2 * Copyright (c) 2004-2011 Atheros Communications Inc.
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.
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.
19 #include <linux/circ_buf.h>
25 struct ath6kl_fwlog_slot {
29 /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
33 #define ATH6KL_FWLOG_SIZE 32768
34 #define ATH6KL_FWLOG_SLOT_SIZE (sizeof(struct ath6kl_fwlog_slot) + \
35 ATH6KL_FWLOG_PAYLOAD_SIZE)
36 #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
38 int ath6kl_printk(const char *level, const char *fmt, ...)
49 rtn = printk("%sath6kl: %pV", level, &vaf);
56 #ifdef CONFIG_ATH6KL_DEBUG
58 #define REG_OUTPUT_LEN_PER_LINE 25
59 #define REGTYPE_STR_LEN 100
61 struct ath6kl_diag_reg_info {
67 static 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" },
78 void 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)
83 ath6kl_dbg(ATH6KL_DBG_ANY, ("<------- Register Table -------->\n"));
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,
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]);
111 if (dev->ar->mbox_info.gmbox_addr != 0) {
113 * If the target supports GMBOX hardware, dump some
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]);
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);
139 ath6kl_dbg(ATH6KL_DBG_ANY, "<------------------------------->\n");
142 static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
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",
151 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_min : %d\n",
153 ath6kl_dbg(ATH6KL_DBG_ANY, " credits : %d\n",
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",
159 ath6kl_dbg(ATH6KL_DBG_ANY, " cred_sz : %d\n",
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");
172 void dump_cred_dist_stats(struct htc_target *target)
174 struct htc_endpoint_credit_dist *ep_list;
176 if (!AR_DBG_LVL_CHECK(ATH6KL_DBG_TRC))
179 list_for_each_entry(ep_list, &target->cred_dist_list, list)
180 dump_cred_dist(ep_list);
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);
189 static int ath6kl_debugfs_open(struct inode *inode, struct file *file)
191 file->private_data = inode->i_private;
195 void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
198 case ATH6KL_WAR_INVALID_RATE:
199 ar->debug.war_stats.invalid_rate++;
204 static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
205 size_t count, loff_t *ppos)
207 struct ath6kl *ar = file->private_data;
209 unsigned int len = 0, buf_len = 1500;
212 buf = kzalloc(buf_len, GFP_KERNEL);
216 len += scnprintf(buf + len, buf_len - len, "\n");
217 len += scnprintf(buf + len, buf_len - len, "%25s\n",
219 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
220 "=================");
221 len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
222 "Invalid rates", ar->debug.war_stats.invalid_rate);
224 if (WARN_ON(len > buf_len))
227 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
233 static const struct file_operations fops_war_stats = {
234 .read = read_file_war_stats,
235 .open = ath6kl_debugfs_open,
236 .owner = THIS_MODULE,
237 .llseek = default_llseek,
240 static void ath6kl_debug_fwlog_add(struct ath6kl *ar, const void *buf,
243 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
247 /* entries must all be equal size */
248 if (WARN_ON(buf_len != ATH6KL_FWLOG_SLOT_SIZE))
251 space = CIRC_SPACE(fwlog->head, fwlog->tail, ATH6KL_FWLOG_SIZE);
253 /* discard oldest slot */
254 fwlog->tail = (fwlog->tail + ATH6KL_FWLOG_SLOT_SIZE) &
255 (ATH6KL_FWLOG_SIZE - 1);
257 for (i = 0; i < buf_len; i += space) {
258 space = CIRC_SPACE_TO_END(fwlog->head, fwlog->tail,
261 if ((size_t) space > buf_len - i)
264 memcpy(&fwlog->buf[fwlog->head], buf, space);
265 fwlog->head = (fwlog->head + space) & (ATH6KL_FWLOG_SIZE - 1);
270 void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
272 struct ath6kl_fwlog_slot *slot = ar->debug.fwlog_tmp;
275 if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
278 spin_lock_bh(&ar->debug.fwlog_lock);
280 slot->timestamp = cpu_to_le32(jiffies);
281 slot->length = cpu_to_le32(len);
282 memcpy(slot->payload, buf, len);
284 slot_len = sizeof(*slot) + len;
286 if (slot_len < ATH6KL_FWLOG_SLOT_SIZE)
287 memset(slot->payload + len, 0,
288 ATH6KL_FWLOG_SLOT_SIZE - slot_len);
290 ath6kl_debug_fwlog_add(ar, slot, ATH6KL_FWLOG_SLOT_SIZE);
292 spin_unlock_bh(&ar->debug.fwlog_lock);
295 static bool ath6kl_debug_fwlog_empty(struct ath6kl *ar)
297 return CIRC_CNT(ar->debug.fwlog_buf.head,
298 ar->debug.fwlog_buf.tail,
299 ATH6KL_FWLOG_SLOT_SIZE) == 0;
302 static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
303 size_t count, loff_t *ppos)
305 struct ath6kl *ar = file->private_data;
306 struct circ_buf *fwlog = &ar->debug.fwlog_buf;
307 size_t len = 0, buf_len = count;
312 buf = vmalloc(buf_len);
316 /* read undelivered logs from firmware */
317 ath6kl_read_fwlogs(ar);
319 spin_lock_bh(&ar->debug.fwlog_lock);
321 while (len < buf_len && !ath6kl_debug_fwlog_empty(ar)) {
322 ccnt = CIRC_CNT_TO_END(fwlog->head, fwlog->tail,
325 if ((size_t) ccnt > buf_len - len)
326 ccnt = buf_len - len;
328 memcpy(buf + len, &fwlog->buf[fwlog->tail], ccnt);
331 fwlog->tail = (fwlog->tail + ccnt) &
332 (ATH6KL_FWLOG_SIZE - 1);
335 spin_unlock_bh(&ar->debug.fwlog_lock);
337 if (WARN_ON(len > buf_len))
340 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
347 static const struct file_operations fops_fwlog = {
348 .open = ath6kl_debugfs_open,
349 .read = ath6kl_fwlog_read,
350 .owner = THIS_MODULE,
351 .llseek = default_llseek,
354 static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
355 size_t count, loff_t *ppos)
357 struct ath6kl *ar = file->private_data;
361 len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
363 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
366 static ssize_t ath6kl_fwlog_mask_write(struct file *file,
367 const char __user *user_buf,
368 size_t count, loff_t *ppos)
370 struct ath6kl *ar = file->private_data;
373 ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
377 ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
378 ATH6KL_FWLOG_VALID_MASK,
379 ar->debug.fwlog_mask);
386 static const struct file_operations fops_fwlog_mask = {
387 .open = ath6kl_debugfs_open,
388 .read = ath6kl_fwlog_mask_read,
389 .write = ath6kl_fwlog_mask_write,
390 .owner = THIS_MODULE,
391 .llseek = default_llseek,
394 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
395 size_t count, loff_t *ppos)
397 struct ath6kl *ar = file->private_data;
398 struct target_stats *tgt_stats = &ar->target_stats;
400 unsigned int len = 0, buf_len = 1500;
405 buf = kzalloc(buf_len, GFP_KERNEL);
409 if (down_interruptible(&ar->sem)) {
414 set_bit(STATS_UPDATE_PEND, &ar->flag);
416 if (ath6kl_wmi_get_stats_cmd(ar->wmi)) {
422 left = wait_event_interruptible_timeout(ar->event_wq,
423 !test_bit(STATS_UPDATE_PEND,
424 &ar->flag), WMI_TIMEOUT);
433 len += scnprintf(buf + len, buf_len - len, "\n");
434 len += scnprintf(buf + len, buf_len - len, "%25s\n",
436 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
437 "=================");
438 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
439 "Ucast packets", tgt_stats->tx_ucast_pkt);
440 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
441 "Bcast packets", tgt_stats->tx_bcast_pkt);
442 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
443 "Ucast byte", tgt_stats->tx_ucast_byte);
444 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
445 "Bcast byte", tgt_stats->tx_bcast_byte);
446 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
447 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
448 for (i = 0; i < 4; i++)
449 len += scnprintf(buf + len, buf_len - len,
450 "%18s %d %10llu\n", "PER on ac",
451 i, tgt_stats->tx_pkt_per_ac[i]);
452 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
453 "Error", tgt_stats->tx_err);
454 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
455 "Fail count", tgt_stats->tx_fail_cnt);
456 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
457 "Retry count", tgt_stats->tx_retry_cnt);
458 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
459 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
460 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
461 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
462 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
463 "TKIP counter measure used",
464 tgt_stats->tkip_cnter_measures_invoked);
466 len += scnprintf(buf + len, buf_len - len, "%25s\n",
468 len += scnprintf(buf + len, buf_len - len, "%25s\n",
469 "=================");
471 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
472 "Ucast packets", tgt_stats->rx_ucast_pkt);
473 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
474 "Ucast Rate", tgt_stats->rx_ucast_rate);
475 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
476 "Bcast packets", tgt_stats->rx_bcast_pkt);
477 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
478 "Ucast byte", tgt_stats->rx_ucast_byte);
479 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
480 "Bcast byte", tgt_stats->rx_bcast_byte);
481 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
482 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
483 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
484 "Error", tgt_stats->rx_err);
485 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
486 "CRC Err", tgt_stats->rx_crc_err);
487 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
488 "Key chache miss", tgt_stats->rx_key_cache_miss);
489 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
490 "Decrypt Err", tgt_stats->rx_decrypt_err);
491 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
492 "Duplicate frame", tgt_stats->rx_dupl_frame);
493 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
494 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
495 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
496 "TKIP format err", tgt_stats->tkip_fmt_err);
497 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
498 "CCMP format Err", tgt_stats->ccmp_fmt_err);
499 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
500 "CCMP Replay Err", tgt_stats->ccmp_replays);
502 len += scnprintf(buf + len, buf_len - len, "%25s\n",
503 "Misc Target stats");
504 len += scnprintf(buf + len, buf_len - len, "%25s\n",
505 "=================");
506 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
507 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
508 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
509 "Num Connects", tgt_stats->cs_connect_cnt);
510 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
511 "Num disconnects", tgt_stats->cs_discon_cnt);
512 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
513 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
518 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
524 static const struct file_operations fops_tgt_stats = {
525 .read = read_file_tgt_stats,
526 .open = ath6kl_debugfs_open,
527 .owner = THIS_MODULE,
528 .llseek = default_llseek,
531 #define print_credit_info(fmt_str, ep_list_field) \
532 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
533 ep_list->ep_list_field))
534 #define CREDIT_INFO_DISPLAY_STRING_LEN 200
535 #define CREDIT_INFO_LEN 128
537 static ssize_t read_file_credit_dist_stats(struct file *file,
538 char __user *user_buf,
539 size_t count, loff_t *ppos)
541 struct ath6kl *ar = file->private_data;
542 struct htc_target *target = ar->htc_target;
543 struct htc_endpoint_credit_dist *ep_list;
545 unsigned int buf_len, len = 0;
548 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
549 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
550 buf = kzalloc(buf_len, GFP_KERNEL);
554 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
555 "Total Avail Credits: ",
556 target->cred_dist_cntxt->total_avail_credits);
557 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
559 target->cred_dist_cntxt->cur_free_credits);
561 len += scnprintf(buf + len, buf_len - len,
562 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
563 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
566 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
567 print_credit_info(" %2d", endpoint);
568 print_credit_info("%10x", dist_flags);
569 print_credit_info("%8d", cred_norm);
570 print_credit_info("%9d", cred_min);
571 print_credit_info("%9d", credits);
572 print_credit_info("%10d", cred_assngd);
573 print_credit_info("%13d", seek_cred);
574 print_credit_info("%12d", cred_sz);
575 print_credit_info("%9d", cred_per_msg);
576 print_credit_info("%14d", cred_to_dist);
577 len += scnprintf(buf + len, buf_len - len, "%12d\n",
578 get_queue_depth(&((struct htc_endpoint *)
579 ep_list->htc_rsvd)->txq));
585 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
590 static const struct file_operations fops_credit_dist_stats = {
591 .read = read_file_credit_dist_stats,
592 .open = ath6kl_debugfs_open,
593 .owner = THIS_MODULE,
594 .llseek = default_llseek,
597 static unsigned long ath6kl_get_num_reg(void)
600 unsigned long n_reg = 0;
602 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
604 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
609 static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
613 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
614 if (reg_addr >= diag_reg[i].reg_start &&
615 reg_addr <= diag_reg[i].reg_end)
622 static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
623 size_t count, loff_t *ppos)
625 struct ath6kl *ar = file->private_data;
627 unsigned int len = 0;
629 if (ar->debug.dbgfs_diag_reg)
630 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
631 ar->debug.dbgfs_diag_reg);
633 len += scnprintf(buf + len, sizeof(buf) - len,
634 "All diag registers\n");
636 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
639 static ssize_t ath6kl_regread_write(struct file *file,
640 const char __user *user_buf,
641 size_t count, loff_t *ppos)
643 struct ath6kl *ar = file->private_data;
646 unsigned long reg_addr;
648 len = min(count, sizeof(buf) - 1);
649 if (copy_from_user(buf, user_buf, len))
654 if (strict_strtoul(buf, 0, ®_addr))
657 if ((reg_addr % 4) != 0)
660 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
663 ar->debug.dbgfs_diag_reg = reg_addr;
668 static const struct file_operations fops_diag_reg_read = {
669 .read = ath6kl_regread_read,
670 .write = ath6kl_regread_write,
671 .open = ath6kl_debugfs_open,
672 .owner = THIS_MODULE,
673 .llseek = default_llseek,
676 static int ath6kl_regdump_open(struct inode *inode, struct file *file)
678 struct ath6kl *ar = inode->i_private;
680 unsigned long int reg_len;
681 unsigned int len = 0, n_reg;
686 /* Dump all the registers if no register is specified */
687 if (!ar->debug.dbgfs_diag_reg)
688 n_reg = ath6kl_get_num_reg();
692 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
694 reg_len += REGTYPE_STR_LEN;
696 buf = vmalloc(reg_len);
701 addr = ar->debug.dbgfs_diag_reg;
703 status = ath6kl_diag_read32(ar,
704 TARG_VTOP(ar->target_type, addr),
709 len += scnprintf(buf + len, reg_len - len,
710 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
714 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
715 len += scnprintf(buf + len, reg_len - len,
716 "%s\n", diag_reg[i].reg_info);
717 for (addr = diag_reg[i].reg_start;
718 addr <= diag_reg[i].reg_end; addr += 4) {
719 status = ath6kl_diag_read32(ar,
720 TARG_VTOP(ar->target_type, addr),
725 len += scnprintf(buf + len, reg_len - len,
727 addr, le32_to_cpu(reg_val));
732 file->private_data = buf;
736 ath6kl_warn("Unable to read memory:%u\n", addr);
741 static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
742 size_t count, loff_t *ppos)
744 u8 *buf = file->private_data;
745 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
748 static int ath6kl_regdump_release(struct inode *inode, struct file *file)
750 vfree(file->private_data);
754 static const struct file_operations fops_reg_dump = {
755 .open = ath6kl_regdump_open,
756 .read = ath6kl_regdump_read,
757 .release = ath6kl_regdump_release,
758 .owner = THIS_MODULE,
759 .llseek = default_llseek,
762 static ssize_t ath6kl_lrssi_roam_write(struct file *file,
763 const char __user *user_buf,
764 size_t count, loff_t *ppos)
766 struct ath6kl *ar = file->private_data;
767 unsigned long lrssi_roam_threshold;
771 len = min(count, sizeof(buf) - 1);
772 if (copy_from_user(buf, user_buf, len))
776 if (strict_strtoul(buf, 0, &lrssi_roam_threshold))
779 ar->lrssi_roam_threshold = lrssi_roam_threshold;
781 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
786 static ssize_t ath6kl_lrssi_roam_read(struct file *file,
787 char __user *user_buf,
788 size_t count, loff_t *ppos)
790 struct ath6kl *ar = file->private_data;
794 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
796 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
799 static const struct file_operations fops_lrssi_roam_threshold = {
800 .read = ath6kl_lrssi_roam_read,
801 .write = ath6kl_lrssi_roam_write,
802 .open = ath6kl_debugfs_open,
803 .owner = THIS_MODULE,
804 .llseek = default_llseek,
807 static ssize_t ath6kl_regwrite_read(struct file *file,
808 char __user *user_buf,
809 size_t count, loff_t *ppos)
811 struct ath6kl *ar = file->private_data;
813 unsigned int len = 0;
815 len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
816 ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
818 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
821 static ssize_t ath6kl_regwrite_write(struct file *file,
822 const char __user *user_buf,
823 size_t count, loff_t *ppos)
825 struct ath6kl *ar = file->private_data;
828 unsigned int len = 0;
829 u32 reg_addr, reg_val;
831 len = min(count, sizeof(buf) - 1);
832 if (copy_from_user(buf, user_buf, len))
838 token = strsep(&sptr, "=");
842 if (kstrtou32(token, 0, ®_addr))
845 if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
848 if (kstrtou32(sptr, 0, ®_val))
851 ar->debug.diag_reg_addr_wr = reg_addr;
852 ar->debug.diag_reg_val_wr = reg_val;
854 if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
855 cpu_to_le32(ar->debug.diag_reg_val_wr)))
861 static const struct file_operations fops_diag_reg_write = {
862 .read = ath6kl_regwrite_read,
863 .write = ath6kl_regwrite_write,
864 .open = ath6kl_debugfs_open,
865 .owner = THIS_MODULE,
866 .llseek = default_llseek,
869 int ath6kl_debug_init(struct ath6kl *ar)
871 ar->debug.fwlog_buf.buf = vmalloc(ATH6KL_FWLOG_SIZE);
872 if (ar->debug.fwlog_buf.buf == NULL)
875 ar->debug.fwlog_tmp = kmalloc(ATH6KL_FWLOG_SLOT_SIZE, GFP_KERNEL);
876 if (ar->debug.fwlog_tmp == NULL) {
877 vfree(ar->debug.fwlog_buf.buf);
881 spin_lock_init(&ar->debug.fwlog_lock);
884 * Actually we are lying here but don't know how to read the mask
885 * value from the firmware.
887 ar->debug.fwlog_mask = 0;
889 ar->debugfs_phy = debugfs_create_dir("ath6kl",
890 ar->wdev->wiphy->debugfsdir);
891 if (!ar->debugfs_phy) {
892 vfree(ar->debug.fwlog_buf.buf);
893 kfree(ar->debug.fwlog_tmp);
897 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
900 debugfs_create_file("credit_dist_stats", S_IRUSR, ar->debugfs_phy, ar,
901 &fops_credit_dist_stats);
903 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
906 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
907 ar, &fops_fwlog_mask);
909 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
910 &fops_diag_reg_read);
912 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
915 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
916 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
918 debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
919 ar->debugfs_phy, ar, &fops_diag_reg_write);
921 debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
927 void ath6kl_debug_cleanup(struct ath6kl *ar)
929 vfree(ar->debug.fwlog_buf.buf);
930 kfree(ar->debug.fwlog_tmp);