blob: 8bc475376372eb8b943ae1e2d06fcc7593431448 [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 Valobdf53962011-09-02 10:32:04 +030021
Kalle Valobdcd8172011-07-18 00:22:30 +030022#include "debug.h"
Kalle Valobdf53962011-09-02 10:32:04 +030023#include "target.h"
24
25struct ath6kl_fwlog_slot {
26 __le32 timestamp;
27 __le32 length;
28
29 /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
30 u8 payload[0];
31};
32
33#define ATH6KL_FWLOG_SIZE 32768
34#define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \
35 ATH6KL_FWLOG_PAYLOAD_SIZE)
Kalle Valo939f1cc2011-09-02 10:32:04 +030036#define ATH6KL_FWLOG_VALID_MASK 0x1ffff
Kalle Valobdcd8172011-07-18 00:22:30 +030037
38int ath6kl_printk(const char *level, const char *fmt, ...)
39{
40 struct va_format vaf;
41 va_list args;
42 int rtn;
43
44 va_start(args, fmt);
45
46 vaf.fmt = fmt;
47 vaf.va = &args;
48
49 rtn = printk("%sath6kl: %pV", level, &vaf);
50
51 va_end(args);
52
53 return rtn;
54}
55
56#ifdef CONFIG_ATH6KL_DEBUG
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +030057
58#define REG_OUTPUT_LEN_PER_LINE 25
59#define REGTYPE_STR_LEN 100
60
61struct ath6kl_diag_reg_info {
62 u32 reg_start;
63 u32 reg_end;
64 const char *reg_info;
65};
66
67static const struct ath6kl_diag_reg_info diag_reg[] = {
68 { 0x20000, 0x200fc, "General DMA and Rx registers" },
69 { 0x28000, 0x28900, "MAC PCU register & keycache" },
70 { 0x20800, 0x20a40, "QCU" },
71 { 0x21000, 0x212f0, "DCU" },
72 { 0x4000, 0x42e4, "RTC" },
73 { 0x540000, 0x540000 + (256 * 1024), "RAM" },
74 { 0x29800, 0x2B210, "Base Band" },
75 { 0x1C000, 0x1C748, "Analog" },
76};
77
Kalle Valobdcd8172011-07-18 00:22:30 +030078void ath6kl_dump_registers(struct ath6kl_device *dev,
79 struct ath6kl_irq_proc_registers *irq_proc_reg,
80 struct ath6kl_irq_enable_reg *irq_enable_reg)
81{
82
83 ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
84
85 if (irq_proc_reg != NULL) {
86 ath6kl_dbg(ATH6KL_DBG_ANY,
87 "Host Int status: 0x%x\n",
88 irq_proc_reg->host_int_status);
89 ath6kl_dbg(ATH6KL_DBG_ANY,
90 "CPU Int status: 0x%x\n",
91 irq_proc_reg->cpu_int_status);
92 ath6kl_dbg(ATH6KL_DBG_ANY,
93 "Error Int status: 0x%x\n",
94 irq_proc_reg->error_int_status);
95 ath6kl_dbg(ATH6KL_DBG_ANY,
96 "Counter Int status: 0x%x\n",
97 irq_proc_reg->counter_int_status);
98 ath6kl_dbg(ATH6KL_DBG_ANY,
99 "Mbox Frame: 0x%x\n",
100 irq_proc_reg->mbox_frame);
101 ath6kl_dbg(ATH6KL_DBG_ANY,
102 "Rx Lookahead Valid: 0x%x\n",
103 irq_proc_reg->rx_lkahd_valid);
104 ath6kl_dbg(ATH6KL_DBG_ANY,
105 "Rx Lookahead 0: 0x%x\n",
106 irq_proc_reg->rx_lkahd[0]);
107 ath6kl_dbg(ATH6KL_DBG_ANY,
108 "Rx Lookahead 1: 0x%x\n",
109 irq_proc_reg->rx_lkahd[1]);
110
111 if (dev->ar->mbox_info.gmbox_addr != 0) {
112 /*
113 * If the target supports GMBOX hardware, dump some
114 * additional state.
115 */
116 ath6kl_dbg(ATH6KL_DBG_ANY,
117 "GMBOX Host Int status 2: 0x%x\n",
118 irq_proc_reg->host_int_status2);
119 ath6kl_dbg(ATH6KL_DBG_ANY,
120 "GMBOX RX Avail: 0x%x\n",
121 irq_proc_reg->gmbox_rx_avail);
122 ath6kl_dbg(ATH6KL_DBG_ANY,
123 "GMBOX lookahead alias 0: 0x%x\n",
124 irq_proc_reg->rx_gmbox_lkahd_alias[0]);
125 ath6kl_dbg(ATH6KL_DBG_ANY,
126 "GMBOX lookahead alias 1: 0x%x\n",
127 irq_proc_reg->rx_gmbox_lkahd_alias[1]);
128 }
129
130 }
131
132 if (irq_enable_reg != NULL) {
133 ath6kl_dbg(ATH6KL_DBG_ANY,
134 "Int status Enable: 0x%x\n",
135 irq_enable_reg->int_status_en);
136 ath6kl_dbg(ATH6KL_DBG_ANY, "Counter Int status Enable: 0x%x\n",
137 irq_enable_reg->cntr_int_status_en);
138 }
139 ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
140}
141
142static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
143{
144 ath6kl_dbg(ATH6KL_DBG_ANY,
145 "--- endpoint: %d svc_id: 0x%X ---\n",
146 ep_dist->endpoint, ep_dist->svc_id);
147 ath6kl_dbg(ATH6KL_DBG_ANY, " dist_flags : 0x%X\n",
148 ep_dist->dist_flags);
149 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_norm : %d\n",
150 ep_dist->cred_norm);
151 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n",
152 ep_dist->cred_min);
153 ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n",
154 ep_dist->credits);
155 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_assngd : %d\n",
156 ep_dist->cred_assngd);
157 ath6kl_dbg(ATH6KL_DBG_ANY, " seek_cred : %d\n",
158 ep_dist->seek_cred);
159 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n",
160 ep_dist->cred_sz);
161 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_per_msg : %d\n",
162 ep_dist->cred_per_msg);
163 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_to_dist : %d\n",
164 ep_dist->cred_to_dist);
165 ath6kl_dbg(ATH6KL_DBG_ANY, " txq_depth : %d\n",
166 get_queue_depth(&((struct htc_endpoint *)
167 ep_dist->htc_rsvd)->txq));
168 ath6kl_dbg(ATH6KL_DBG_ANY,
169 "----------------------------------\n");
170}
171
172void dump_cred_dist_stats(struct htc_target *target)
173{
174 struct htc_endpoint_credit_dist *ep_list;
175
176 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
177 return;
178
179 list_for_each_entry(ep_list, &target->cred_dist_list, list)
180 dump_cred_dist(ep_list);
181
182 ath6kl_dbg(ATH6KL_DBG_HTC_SEND, "ctxt:%p dist:%p\n",
183 target->cred_dist_cntxt, NULL);
184 ath6kl_dbg(ATH6KL_DBG_TRC, "credit distribution, total : %d, free : %d\n",
185 target->cred_dist_cntxt->total_avail_credits,
186 target->cred_dist_cntxt->cur_free_credits);
187}
188
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530189static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
190{
191 file->private_data = inode->i_private;
192 return 0;
193}
194
Kalle Valobdf53962011-09-02 10:32:04 +0300195static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
196 size_t buf_len)
197{
198 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
199 size_t space;
200 int i;
201
202 /* entries must all be equal size */
203 if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
204 return;
205
206 space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
207 if (space < buf_len)
208 /* discard oldest slot */
209 fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
210 (ATH6KL_FWLOG_SIZE - 1);
211
212 for (i = 0; i < buf_len; i += space) {
213 space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
214 ATH6KL_FWLOG_SIZE);
215
216 if ((size_t) space > buf_len - i)
217 space = buf_len - i;
218
219 memcpy(&fwlog->buf[fwlog->head], buf, space);
220 fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
221 }
222
223}
224
225void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
226{
227 struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
228 size_t slot_len;
229
230 if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
231 return;
232
233 spin_lock_bh(&ar->debug.fwlog_lock);
234
235 slot->timestamp = cpu_to_le32(jiffies);
236 slot->length = cpu_to_le32(len);
237 memcpy(slot->payload, buf, len);
238
239 slot_len = sizeof(*slot) + len;
240
241 if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
242 memset(slot->payload + len, 0,
243 ATH6KL_FWLOG_SLOT_SIZE - slot_len);
244
245 ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
246
247 spin_unlock_bh(&ar->debug.fwlog_lock);
248}
249
250static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
251{
252 return CIRC_CNT(ar->debug.fwlog_buf.head,
253 ar->debug.fwlog_buf.tail,
254 ATH6KL_FWLOG_SLOT_SIZE) == 0;
255}
256
257static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
258 size_t count, loff_t *ppos)
259{
260 struct ath6kl *ar = file->private_data;
261 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
262 size_t len = 0, buf_len = count;
263 ssize_t ret_cnt;
264 char *buf;
265 int ccnt;
266
267 buf = vmalloc(buf_len);
268 if (!buf)
269 return -ENOMEM;
270
Kalle Valobc07ddb2011-09-02 10:32:05 +0300271 /* read undelivered logs from firmware */
272 ath6kl_read_fwlogs(ar);
273
Kalle Valobdf53962011-09-02 10:32:04 +0300274 spin_lock_bh(&ar->debug.fwlog_lock);
275
276 while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
277 ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
278 ATH6KL_FWLOG_SIZE);
279
280 if ((size_t) ccnt > buf_len - len)
281 ccnt = buf_len - len;
282
283 memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
284 len += ccnt;
285
286 fwlog->tail = (fwlog->tail + ccnt) &
287 (ATH6KL_FWLOG_SIZE - 1);
288 }
289
290 spin_unlock_bh(&ar->debug.fwlog_lock);
291
292 if (WARN_ON(len > buf_len))
293 len = buf_len;
294
295 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
296
297 vfree(buf);
298
299 return ret_cnt;
300}
301
302static const struct file_operations fops_fwlog = {
303 .open = ath6kl_debugfs_open,
304 .read = ath6kl_fwlog_read,
305 .owner = THIS_MODULE,
306 .llseek = default_llseek,
307};
308
Kalle Valo939f1cc2011-09-02 10:32:04 +0300309static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
310 size_t count, loff_t *ppos)
311{
312 struct ath6kl *ar = file->private_data;
313 char buf[16];
314 int len;
315
316 len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
317
318 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
319}
320
321static ssize_t ath6kl_fwlog_mask_write(struct file *file,
322 const char __user *user_buf,
323 size_t count, loff_t *ppos)
324{
325 struct ath6kl *ar = file->private_data;
326 int ret;
327
328 ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
329 if (ret)
330 return ret;
331
332 ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
333 ATH6KL_FWLOG_VALID_MASK,
334 ar->debug.fwlog_mask);
335 if (ret)
336 return ret;
337
338 return count;
339}
340
341static const struct file_operations fops_fwlog_mask = {
342 .open = ath6kl_debugfs_open,
343 .read = ath6kl_fwlog_mask_read,
344 .write = ath6kl_fwlog_mask_write,
345 .owner = THIS_MODULE,
346 .llseek = default_llseek,
347};
348
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530349static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
350 size_t count, loff_t *ppos)
351{
352 struct ath6kl *ar = file->private_data;
353 struct target_stats *tgt_stats = &ar->target_stats;
354 char *buf;
355 unsigned int len = 0, buf_len = 1500;
356 int i;
357 long left;
358 ssize_t ret_cnt;
359
360 buf = kzalloc(buf_len, GFP_KERNEL);
361 if (!buf)
362 return -ENOMEM;
363
364 if (down_interruptible(&ar->sem)) {
365 kfree(buf);
366 return -EBUSY;
367 }
368
369 set_bit(STATS_UPDATE_PEND, &ar->flag);
370
371 if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
372 up(&ar->sem);
373 kfree(buf);
374 return -EIO;
375 }
376
377 left = wait_event_interruptible_timeout(ar->event_wq,
378 !test_bit(STATS_UPDATE_PEND,
379 &ar->flag), WMI_TIMEOUT);
380
381 up(&ar->sem);
382
383 if (left <= 0) {
384 kfree(buf);
385 return -ETIMEDOUT;
386 }
387
388 len += scnprintf(buf + len, buf_len - len, "\n");
389 len += scnprintf(buf + len, buf_len - len, "%25s\n",
390 "Target Tx stats");
391 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
392 "=================");
393 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
394 "Ucast packets", tgt_stats->tx_ucast_pkt);
395 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
396 "Bcast packets", tgt_stats->tx_bcast_pkt);
397 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
398 "Ucast byte", tgt_stats->tx_ucast_byte);
399 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
400 "Bcast byte", tgt_stats->tx_bcast_byte);
401 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
402 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
403 for (i = 0; i < 4; i++)
404 len += scnprintf(buf + len, buf_len - len,
405 "%18s %d %10llu\n", "PER on ac",
406 i, tgt_stats->tx_pkt_per_ac[i]);
407 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
408 "Error", tgt_stats->tx_err);
409 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
410 "Fail count", tgt_stats->tx_fail_cnt);
411 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
412 "Retry count", tgt_stats->tx_retry_cnt);
413 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
414 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
415 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
416 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
417 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
418 "TKIP counter measure used",
419 tgt_stats->tkip_cnter_measures_invoked);
420
421 len += scnprintf(buf + len, buf_len - len, "%25s\n",
422 "Target Rx stats");
423 len += scnprintf(buf + len, buf_len - len, "%25s\n",
424 "=================");
425
426 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
427 "Ucast packets", tgt_stats->rx_ucast_pkt);
428 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
429 "Ucast Rate", tgt_stats->rx_ucast_rate);
430 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
431 "Bcast packets", tgt_stats->rx_bcast_pkt);
432 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
433 "Ucast byte", tgt_stats->rx_ucast_byte);
434 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
435 "Bcast byte", tgt_stats->rx_bcast_byte);
436 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
437 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
438 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
439 "Error", tgt_stats->rx_err);
440 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
441 "CRC Err", tgt_stats->rx_crc_err);
442 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
443 "Key chache miss", tgt_stats->rx_key_cache_miss);
444 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
445 "Decrypt Err", tgt_stats->rx_decrypt_err);
446 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
447 "Duplicate frame", tgt_stats->rx_dupl_frame);
448 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
449 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
450 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
451 "TKIP format err", tgt_stats->tkip_fmt_err);
452 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
453 "CCMP format Err", tgt_stats->ccmp_fmt_err);
454 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
455 "CCMP Replay Err", tgt_stats->ccmp_replays);
456
457 len += scnprintf(buf + len, buf_len - len, "%25s\n",
458 "Misc Target stats");
459 len += scnprintf(buf + len, buf_len - len, "%25s\n",
460 "=================");
461 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
462 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
463 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
464 "Num Connects", tgt_stats->cs_connect_cnt);
465 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
466 "Num disconnects", tgt_stats->cs_discon_cnt);
467 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
468 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
469
470 if (len > buf_len)
471 len = buf_len;
472
473 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
474
475 kfree(buf);
476 return ret_cnt;
477}
478
479static const struct file_operations fops_tgt_stats = {
480 .read = read_file_tgt_stats,
481 .open = ath6kl_debugfs_open,
482 .owner = THIS_MODULE,
483 .llseek = default_llseek,
484};
485
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530486#define print_credit_info(fmt_str, ep_list_field) \
487 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
488 ep_list->ep_list_field))
489#define CREDIT_INFO_DISPLAY_STRING_LEN 200
490#define CREDIT_INFO_LEN 128
491
492static ssize_t read_file_credit_dist_stats(struct file *file,
493 char __user *user_buf,
494 size_t count, loff_t *ppos)
495{
496 struct ath6kl *ar = file->private_data;
497 struct htc_target *target = ar->htc_target;
498 struct htc_endpoint_credit_dist *ep_list;
499 char *buf;
500 unsigned int buf_len, len = 0;
501 ssize_t ret_cnt;
502
503 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
504 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
505 buf = kzalloc(buf_len, GFP_KERNEL);
506 if (!buf)
507 return -ENOMEM;
508
509 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
510 "Total Avail Credits: ",
511 target->cred_dist_cntxt->total_avail_credits);
512 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
513 "Free credits :",
514 target->cred_dist_cntxt->cur_free_credits);
515
516 len += scnprintf(buf + len, buf_len - len,
517 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
518 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
519 " qdepth\n");
520
521 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
522 print_credit_info(" %2d", endpoint);
523 print_credit_info("%10x", dist_flags);
524 print_credit_info("%8d", cred_norm);
525 print_credit_info("%9d", cred_min);
526 print_credit_info("%9d", credits);
527 print_credit_info("%10d", cred_assngd);
528 print_credit_info("%13d", seek_cred);
529 print_credit_info("%12d", cred_sz);
530 print_credit_info("%9d", cred_per_msg);
531 print_credit_info("%14d", cred_to_dist);
532 len += scnprintf(buf + len, buf_len - len, "%12d\n",
533 get_queue_depth(&((struct htc_endpoint *)
534 ep_list->htc_rsvd)->txq));
535 }
536
537 if (len > buf_len)
538 len = buf_len;
539
540 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
541 kfree(buf);
542 return ret_cnt;
543}
544
545static const struct file_operations fops_credit_dist_stats = {
546 .read = read_file_credit_dist_stats,
547 .open = ath6kl_debugfs_open,
548 .owner = THIS_MODULE,
549 .llseek = default_llseek,
550};
551
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +0300552static unsigned long ath6kl_get_num_reg(void)
553{
554 int i;
555 unsigned long n_reg = 0;
556
557 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
558 n_reg = n_reg +
559 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
560
561 return n_reg;
562}
563
564static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
565{
566 int i;
567
568 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
569 if (reg_addr >= diag_reg[i].reg_start &&
570 reg_addr <= diag_reg[i].reg_end)
571 return true;
572 }
573
574 return false;
575}
576
577static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
578 size_t count, loff_t *ppos)
579{
580 struct ath6kl *ar = file->private_data;
581 u8 buf[50];
582 unsigned int len = 0;
583
584 if (ar->debug.dbgfs_diag_reg)
585 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
586 ar->debug.dbgfs_diag_reg);
587 else
588 len += scnprintf(buf + len, sizeof(buf) - len,
589 "All diag registers\n");
590
591 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
592}
593
594static ssize_t ath6kl_regread_write(struct file *file,
595 const char __user *user_buf,
596 size_t count, loff_t *ppos)
597{
598 struct ath6kl *ar = file->private_data;
599 u8 buf[50];
600 unsigned int len;
601 unsigned long reg_addr;
602
603 len = min(count, sizeof(buf) - 1);
604 if (copy_from_user(buf, user_buf, len))
605 return -EFAULT;
606
607 buf[len] = '\0';
608
609 if (strict_strtoul(buf, 0, &reg_addr))
610 return -EINVAL;
611
612 if ((reg_addr % 4) != 0)
613 return -EINVAL;
614
615 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
616 return -EINVAL;
617
618 ar->debug.dbgfs_diag_reg = reg_addr;
619
620 return count;
621}
622
623static const struct file_operations fops_diag_reg_read = {
624 .read = ath6kl_regread_read,
625 .write = ath6kl_regread_write,
626 .open = ath6kl_debugfs_open,
627 .owner = THIS_MODULE,
628 .llseek = default_llseek,
629};
630
631static int ath6kl_regdump_open(struct inode *inode, struct file *file)
632{
633 struct ath6kl *ar = inode->i_private;
634 u8 *buf;
635 unsigned long int reg_len;
636 unsigned int len = 0, n_reg;
637 u32 addr;
638 __le32 reg_val;
639 int i, status;
640
641 /* Dump all the registers if no register is specified */
642 if (!ar->debug.dbgfs_diag_reg)
643 n_reg = ath6kl_get_num_reg();
644 else
645 n_reg = 1;
646
647 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
648 if (n_reg > 1)
649 reg_len += REGTYPE_STR_LEN;
650
651 buf = vmalloc(reg_len);
652 if (!buf)
653 return -ENOMEM;
654
655 if (n_reg == 1) {
656 addr = ar->debug.dbgfs_diag_reg;
657
658 status = ath6kl_diag_read32(ar,
659 TARG_VTOP(ar->target_type, addr),
660 (u32 *)&reg_val);
661 if (status)
662 goto fail_reg_read;
663
664 len += scnprintf(buf + len, reg_len - len,
665 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
666 goto done;
667 }
668
669 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
670 len += scnprintf(buf + len, reg_len - len,
671 "%s\n", diag_reg[i].reg_info);
672 for (addr = diag_reg[i].reg_start;
673 addr <= diag_reg[i].reg_end; addr += 4) {
674 status = ath6kl_diag_read32(ar,
675 TARG_VTOP(ar->target_type, addr),
676 (u32 *)&reg_val);
677 if (status)
678 goto fail_reg_read;
679
680 len += scnprintf(buf + len, reg_len - len,
681 "0x%06x 0x%08x\n",
682 addr, le32_to_cpu(reg_val));
683 }
684 }
685
686done:
687 file->private_data = buf;
688 return 0;
689
690fail_reg_read:
691 ath6kl_warn("Unable to read memory:%u\n", addr);
692 vfree(buf);
693 return -EIO;
694}
695
696static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
697 size_t count, loff_t *ppos)
698{
699 u8 *buf = file->private_data;
700 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
701}
702
703static int ath6kl_regdump_release(struct inode *inode, struct file *file)
704{
705 vfree(file->private_data);
706 return 0;
707}
708
709static const struct file_operations fops_reg_dump = {
710 .open = ath6kl_regdump_open,
711 .read = ath6kl_regdump_read,
712 .release = ath6kl_regdump_release,
713 .owner = THIS_MODULE,
714 .llseek = default_llseek,
715};
716
Vivek Natarajane5090442011-08-31 15:02:19 +0530717static ssize_t ath6kl_lrssi_roam_write(struct file *file,
718 const char __user *user_buf,
719 size_t count, loff_t *ppos)
720{
721 struct ath6kl *ar = file->private_data;
722 unsigned long lrssi_roam_threshold;
723 char buf[32];
724 ssize_t len;
725
726 len = min(count, sizeof(buf) - 1);
727 if (copy_from_user(buf, user_buf, len))
728 return -EFAULT;
729
730 buf[len] = '\0';
731 if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
732 return -EINVAL;
733
734 ar->lrssi_roam_threshold = lrssi_roam_threshold;
735
736 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
737
738 return count;
739}
740
741static ssize_t ath6kl_lrssi_roam_read(struct file *file,
742 char __user *user_buf,
743 size_t count, loff_t *ppos)
744{
745 struct ath6kl *ar = file->private_data;
746 char buf[32];
747 unsigned int len;
748
749 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
750
751 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
752}
753
754static const struct file_operations fops_lrssi_roam_threshold = {
755 .read = ath6kl_lrssi_roam_read,
756 .write = ath6kl_lrssi_roam_write,
757 .open = ath6kl_debugfs_open,
758 .owner = THIS_MODULE,
759 .llseek = default_llseek,
760};
761
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530762int ath6kl_debug_init(struct ath6kl *ar)
763{
Kalle Valobdf53962011-09-02 10:32:04 +0300764 ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
765 if (ar->debug.fwlog_buf.buf == NULL)
766 return -ENOMEM;
767
768 ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
769 if (ar->debug.fwlog_tmp == NULL) {
770 vfree(ar->debug.fwlog_buf.buf);
771 return -ENOMEM;
772 }
773
774 spin_lock_init(&ar->debug.fwlog_lock);
775
Kalle Valo939f1cc2011-09-02 10:32:04 +0300776 /*
777 * Actually we are lying here but don't know how to read the mask
778 * value from the firmware.
779 */
780 ar->debug.fwlog_mask = 0;
781
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530782 ar->debugfs_phy = debugfs_create_dir("ath6kl",
783 ar->wdev->wiphy->debugfsdir);
Kalle Valobdf53962011-09-02 10:32:04 +0300784 if (!ar->debugfs_phy) {
785 vfree(ar->debug.fwlog_buf.buf);
786 kfree(ar->debug.fwlog_tmp);
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530787 return -ENOMEM;
Kalle Valobdf53962011-09-02 10:32:04 +0300788 }
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530789
Vasanthakumar Thiagarajan03f68a92011-08-26 13:06:32 +0530790 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
791 &fops_tgt_stats);
792
Vasanthakumar Thiagarajan78fc4852011-08-26 13:06:33 +0530793 debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
794 &fops_credit_dist_stats);
795
Kalle Valobdf53962011-09-02 10:32:04 +0300796 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
797 &fops_fwlog);
798
Kalle Valo939f1cc2011-09-02 10:32:04 +0300799 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
800 ar, &fops_fwlog_mask);
801
Vasanthakumar Thiagarajan91d57de2011-09-02 10:40:06 +0300802 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
803 &fops_diag_reg_read);
804
805 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
806 &fops_reg_dump);
807
Vivek Natarajane5090442011-08-31 15:02:19 +0530808 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
809 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
Vasanthakumar Thiagarajand999ba32011-08-26 13:06:31 +0530810 return 0;
811}
Kalle Valobdf53962011-09-02 10:32:04 +0300812
813void ath6kl_debug_cleanup(struct ath6kl *ar)
814{
815 vfree(ar->debug.fwlog_buf.buf);
816 kfree(ar->debug.fwlog_tmp);
817}
818
Kalle Valobdcd8172011-07-18 00:22:30 +0300819#endif