2 * Copyright (c) 2004-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <linux/skbuff.h>
22 #include <linux/vmalloc.h>
23 #include <linux/export.h>
28 struct ath6kl_fwlog_slot {
32 /* max ATH6KL_FWLOG_PAYLOAD_SIZE bytes */
36 #define ATH6KL_FWLOG_MAX_ENTRIES 20
38 #define ATH6KL_FWLOG_VALID_MASK 0x1ffff
40 int ath6kl_printk(const char *level, const char *fmt, ...)
51 rtn = printk("%sath6kl: %pV", level, &vaf);
57 EXPORT_SYMBOL(ath6kl_printk);
59 int ath6kl_info(const char *fmt, ...)
61 struct va_format vaf = {
69 ret = ath6kl_printk(KERN_INFO, "%pV", &vaf);
70 trace_ath6kl_log_info(&vaf);
75 EXPORT_SYMBOL(ath6kl_info);
77 int ath6kl_err(const char *fmt, ...)
79 struct va_format vaf = {
87 ret = ath6kl_printk(KERN_ERR, "%pV", &vaf);
88 trace_ath6kl_log_err(&vaf);
93 EXPORT_SYMBOL(ath6kl_err);
95 int ath6kl_warn(const char *fmt, ...)
97 struct va_format vaf = {
105 ret = ath6kl_printk(KERN_WARNING, "%pV", &vaf);
106 trace_ath6kl_log_warn(&vaf);
111 EXPORT_SYMBOL(ath6kl_warn);
113 #ifdef CONFIG_ATH6KL_DEBUG
115 void ath6kl_dbg(enum ATH6K_DEBUG_MASK mask, const char *fmt, ...)
117 struct va_format vaf;
125 if (debug_mask & mask)
126 ath6kl_printk(KERN_DEBUG, "%pV", &vaf);
128 trace_ath6kl_log_dbg(mask, &vaf);
132 EXPORT_SYMBOL(ath6kl_dbg);
134 void ath6kl_dbg_dump(enum ATH6K_DEBUG_MASK mask,
135 const char *msg, const char *prefix,
136 const void *buf, size_t len)
138 if (debug_mask & mask) {
140 ath6kl_dbg(mask, "%s\n", msg);
142 print_hex_dump_bytes(prefix, DUMP_PREFIX_OFFSET, buf, len);
145 /* tracing code doesn't like null strings :/ */
146 trace_ath6kl_log_dbg_dump(msg ? msg : "", prefix ? prefix : "",
149 EXPORT_SYMBOL(ath6kl_dbg_dump);
151 #define REG_OUTPUT_LEN_PER_LINE 25
152 #define REGTYPE_STR_LEN 100
154 struct ath6kl_diag_reg_info {
157 const char *reg_info;
160 static const struct ath6kl_diag_reg_info diag_reg[] = {
161 { 0x20000, 0x200fc, "General DMA and Rx registers" },
162 { 0x28000, 0x28900, "MAC PCU register & keycache" },
163 { 0x20800, 0x20a40, "QCU" },
164 { 0x21000, 0x212f0, "DCU" },
165 { 0x4000, 0x42e4, "RTC" },
166 { 0x540000, 0x540000 + (256 * 1024), "RAM" },
167 { 0x29800, 0x2B210, "Base Band" },
168 { 0x1C000, 0x1C748, "Analog" },
171 void ath6kl_dump_registers(struct ath6kl_device *dev,
172 struct ath6kl_irq_proc_registers *irq_proc_reg,
173 struct ath6kl_irq_enable_reg *irq_enable_reg)
175 ath6kl_dbg(ATH6KL_DBG_IRQ, ("<------- Register Table -------->\n"));
177 if (irq_proc_reg != NULL) {
178 ath6kl_dbg(ATH6KL_DBG_IRQ,
179 "Host Int status: 0x%x\n",
180 irq_proc_reg->host_int_status);
181 ath6kl_dbg(ATH6KL_DBG_IRQ,
182 "CPU Int status: 0x%x\n",
183 irq_proc_reg->cpu_int_status);
184 ath6kl_dbg(ATH6KL_DBG_IRQ,
185 "Error Int status: 0x%x\n",
186 irq_proc_reg->error_int_status);
187 ath6kl_dbg(ATH6KL_DBG_IRQ,
188 "Counter Int status: 0x%x\n",
189 irq_proc_reg->counter_int_status);
190 ath6kl_dbg(ATH6KL_DBG_IRQ,
191 "Mbox Frame: 0x%x\n",
192 irq_proc_reg->mbox_frame);
193 ath6kl_dbg(ATH6KL_DBG_IRQ,
194 "Rx Lookahead Valid: 0x%x\n",
195 irq_proc_reg->rx_lkahd_valid);
196 ath6kl_dbg(ATH6KL_DBG_IRQ,
197 "Rx Lookahead 0: 0x%x\n",
198 irq_proc_reg->rx_lkahd[0]);
199 ath6kl_dbg(ATH6KL_DBG_IRQ,
200 "Rx Lookahead 1: 0x%x\n",
201 irq_proc_reg->rx_lkahd[1]);
203 if (dev->ar->mbox_info.gmbox_addr != 0) {
205 * If the target supports GMBOX hardware, dump some
208 ath6kl_dbg(ATH6KL_DBG_IRQ,
209 "GMBOX Host Int status 2: 0x%x\n",
210 irq_proc_reg->host_int_status2);
211 ath6kl_dbg(ATH6KL_DBG_IRQ,
212 "GMBOX RX Avail: 0x%x\n",
213 irq_proc_reg->gmbox_rx_avail);
214 ath6kl_dbg(ATH6KL_DBG_IRQ,
215 "GMBOX lookahead alias 0: 0x%x\n",
216 irq_proc_reg->rx_gmbox_lkahd_alias[0]);
217 ath6kl_dbg(ATH6KL_DBG_IRQ,
218 "GMBOX lookahead alias 1: 0x%x\n",
219 irq_proc_reg->rx_gmbox_lkahd_alias[1]);
223 if (irq_enable_reg != NULL) {
224 ath6kl_dbg(ATH6KL_DBG_IRQ,
225 "Int status Enable: 0x%x\n",
226 irq_enable_reg->int_status_en);
227 ath6kl_dbg(ATH6KL_DBG_IRQ, "Counter Int status Enable: 0x%x\n",
228 irq_enable_reg->cntr_int_status_en);
230 ath6kl_dbg(ATH6KL_DBG_IRQ, "<------------------------------->\n");
233 static void dump_cred_dist(struct htc_endpoint_credit_dist *ep_dist)
235 ath6kl_dbg(ATH6KL_DBG_CREDIT,
236 "--- endpoint: %d svc_id: 0x%X ---\n",
237 ep_dist->endpoint, ep_dist->svc_id);
238 ath6kl_dbg(ATH6KL_DBG_CREDIT, " dist_flags : 0x%X\n",
239 ep_dist->dist_flags);
240 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_norm : %d\n",
242 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_min : %d\n",
244 ath6kl_dbg(ATH6KL_DBG_CREDIT, " credits : %d\n",
246 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_assngd : %d\n",
247 ep_dist->cred_assngd);
248 ath6kl_dbg(ATH6KL_DBG_CREDIT, " seek_cred : %d\n",
250 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_sz : %d\n",
252 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_per_msg : %d\n",
253 ep_dist->cred_per_msg);
254 ath6kl_dbg(ATH6KL_DBG_CREDIT, " cred_to_dist : %d\n",
255 ep_dist->cred_to_dist);
256 ath6kl_dbg(ATH6KL_DBG_CREDIT, " txq_depth : %d\n",
257 get_queue_depth(&ep_dist->htc_ep->txq));
258 ath6kl_dbg(ATH6KL_DBG_CREDIT,
259 "----------------------------------\n");
262 /* FIXME: move to htc.c */
263 void dump_cred_dist_stats(struct htc_target *target)
265 struct htc_endpoint_credit_dist *ep_list;
267 list_for_each_entry(ep_list, &target->cred_dist_list, list)
268 dump_cred_dist(ep_list);
270 ath6kl_dbg(ATH6KL_DBG_CREDIT,
271 "credit distribution total %d free %d\n",
272 target->credit_info->total_avail_credits,
273 target->credit_info->cur_free_credits);
276 void ath6kl_debug_war(struct ath6kl *ar, enum ath6kl_war war)
279 case ATH6KL_WAR_INVALID_RATE:
280 ar->debug.war_stats.invalid_rate++;
285 static ssize_t read_file_war_stats(struct file *file, char __user *user_buf,
286 size_t count, loff_t *ppos)
288 struct ath6kl *ar = file->private_data;
290 unsigned int len = 0, buf_len = 1500;
293 buf = kzalloc(buf_len, GFP_KERNEL);
297 len += scnprintf(buf + len, buf_len - len, "\n");
298 len += scnprintf(buf + len, buf_len - len, "%25s\n",
300 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
301 "=================");
302 len += scnprintf(buf + len, buf_len - len, "%20s %10u\n",
303 "Invalid rates", ar->debug.war_stats.invalid_rate);
305 if (WARN_ON(len > buf_len))
308 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
314 static const struct file_operations fops_war_stats = {
315 .read = read_file_war_stats,
317 .owner = THIS_MODULE,
318 .llseek = default_llseek,
321 void ath6kl_debug_fwlog_event(struct ath6kl *ar, const void *buf, size_t len)
323 struct ath6kl_fwlog_slot *slot;
327 if (WARN_ON(len > ATH6KL_FWLOG_PAYLOAD_SIZE))
330 slot_len = sizeof(*slot) + ATH6KL_FWLOG_PAYLOAD_SIZE;
332 skb = alloc_skb(slot_len, GFP_KERNEL);
336 slot = (struct ath6kl_fwlog_slot *) skb_put(skb, slot_len);
337 slot->timestamp = cpu_to_le32(jiffies);
338 slot->length = cpu_to_le32(len);
339 memcpy(slot->payload, buf, len);
341 /* Need to pad each record to fixed length ATH6KL_FWLOG_PAYLOAD_SIZE */
342 memset(slot->payload + len, 0, ATH6KL_FWLOG_PAYLOAD_SIZE - len);
344 spin_lock(&ar->debug.fwlog_queue.lock);
346 __skb_queue_tail(&ar->debug.fwlog_queue, skb);
347 complete(&ar->debug.fwlog_completion);
349 /* drop oldest entries */
350 while (skb_queue_len(&ar->debug.fwlog_queue) >
351 ATH6KL_FWLOG_MAX_ENTRIES) {
352 skb = __skb_dequeue(&ar->debug.fwlog_queue);
356 spin_unlock(&ar->debug.fwlog_queue.lock);
361 static int ath6kl_fwlog_open(struct inode *inode, struct file *file)
363 struct ath6kl *ar = inode->i_private;
365 if (ar->debug.fwlog_open)
368 ar->debug.fwlog_open = true;
370 file->private_data = inode->i_private;
374 static int ath6kl_fwlog_release(struct inode *inode, struct file *file)
376 struct ath6kl *ar = inode->i_private;
378 ar->debug.fwlog_open = false;
383 static ssize_t ath6kl_fwlog_read(struct file *file, char __user *user_buf,
384 size_t count, loff_t *ppos)
386 struct ath6kl *ar = file->private_data;
392 buf = vmalloc(count);
396 /* read undelivered logs from firmware */
397 ath6kl_read_fwlogs(ar);
399 spin_lock(&ar->debug.fwlog_queue.lock);
401 while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
402 if (skb->len > count - len) {
403 /* not enough space, put skb back and leave */
404 __skb_queue_head(&ar->debug.fwlog_queue, skb);
409 memcpy(buf + len, skb->data, skb->len);
415 spin_unlock(&ar->debug.fwlog_queue.lock);
417 /* FIXME: what to do if len == 0? */
419 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
426 static const struct file_operations fops_fwlog = {
427 .open = ath6kl_fwlog_open,
428 .release = ath6kl_fwlog_release,
429 .read = ath6kl_fwlog_read,
430 .owner = THIS_MODULE,
431 .llseek = default_llseek,
434 static ssize_t ath6kl_fwlog_block_read(struct file *file,
435 char __user *user_buf,
439 struct ath6kl *ar = file->private_data;
442 size_t len = 0, not_copied;
446 buf = vmalloc(count);
450 spin_lock(&ar->debug.fwlog_queue.lock);
452 if (skb_queue_len(&ar->debug.fwlog_queue) == 0) {
453 /* we must init under queue lock */
454 init_completion(&ar->debug.fwlog_completion);
456 spin_unlock(&ar->debug.fwlog_queue.lock);
458 ret = wait_for_completion_interruptible(
459 &ar->debug.fwlog_completion);
460 if (ret == -ERESTARTSYS) {
465 spin_lock(&ar->debug.fwlog_queue.lock);
468 while ((skb = __skb_dequeue(&ar->debug.fwlog_queue))) {
469 if (skb->len > count - len) {
470 /* not enough space, put skb back and leave */
471 __skb_queue_head(&ar->debug.fwlog_queue, skb);
476 memcpy(buf + len, skb->data, skb->len);
482 spin_unlock(&ar->debug.fwlog_queue.lock);
484 /* FIXME: what to do if len == 0? */
486 not_copied = copy_to_user(user_buf, buf, len);
487 if (not_copied != 0) {
502 static const struct file_operations fops_fwlog_block = {
503 .open = ath6kl_fwlog_open,
504 .release = ath6kl_fwlog_release,
505 .read = ath6kl_fwlog_block_read,
506 .owner = THIS_MODULE,
507 .llseek = default_llseek,
510 static ssize_t ath6kl_fwlog_mask_read(struct file *file, char __user *user_buf,
511 size_t count, loff_t *ppos)
513 struct ath6kl *ar = file->private_data;
517 len = snprintf(buf, sizeof(buf), "0x%x\n", ar->debug.fwlog_mask);
519 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
522 static ssize_t ath6kl_fwlog_mask_write(struct file *file,
523 const char __user *user_buf,
524 size_t count, loff_t *ppos)
526 struct ath6kl *ar = file->private_data;
529 ret = kstrtou32_from_user(user_buf, count, 0, &ar->debug.fwlog_mask);
533 ret = ath6kl_wmi_config_debug_module_cmd(ar->wmi,
534 ATH6KL_FWLOG_VALID_MASK,
535 ar->debug.fwlog_mask);
542 static const struct file_operations fops_fwlog_mask = {
544 .read = ath6kl_fwlog_mask_read,
545 .write = ath6kl_fwlog_mask_write,
546 .owner = THIS_MODULE,
547 .llseek = default_llseek,
550 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
551 size_t count, loff_t *ppos)
553 struct ath6kl *ar = file->private_data;
554 struct ath6kl_vif *vif;
555 struct target_stats *tgt_stats;
557 unsigned int len = 0, buf_len = 1500;
562 vif = ath6kl_vif_first(ar);
566 tgt_stats = &vif->target_stats;
568 buf = kzalloc(buf_len, GFP_KERNEL);
572 if (down_interruptible(&ar->sem)) {
577 set_bit(STATS_UPDATE_PEND, &vif->flags);
579 if (ath6kl_wmi_get_stats_cmd(ar->wmi, 0)) {
585 left = wait_event_interruptible_timeout(ar->event_wq,
586 !test_bit(STATS_UPDATE_PEND,
587 &vif->flags), WMI_TIMEOUT);
596 len += scnprintf(buf + len, buf_len - len, "\n");
597 len += scnprintf(buf + len, buf_len - len, "%25s\n",
599 len += scnprintf(buf + len, buf_len - len, "%25s\n\n",
600 "=================");
601 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
602 "Ucast packets", tgt_stats->tx_ucast_pkt);
603 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
604 "Bcast packets", tgt_stats->tx_bcast_pkt);
605 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
606 "Ucast byte", tgt_stats->tx_ucast_byte);
607 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
608 "Bcast byte", tgt_stats->tx_bcast_byte);
609 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
610 "Rts success cnt", tgt_stats->tx_rts_success_cnt);
611 for (i = 0; i < 4; i++)
612 len += scnprintf(buf + len, buf_len - len,
613 "%18s %d %10llu\n", "PER on ac",
614 i, tgt_stats->tx_pkt_per_ac[i]);
615 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
616 "Error", tgt_stats->tx_err);
617 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
618 "Fail count", tgt_stats->tx_fail_cnt);
619 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
620 "Retry count", tgt_stats->tx_retry_cnt);
621 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
622 "Multi retry cnt", tgt_stats->tx_mult_retry_cnt);
623 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
624 "Rts fail cnt", tgt_stats->tx_rts_fail_cnt);
625 len += scnprintf(buf + len, buf_len - len, "%25s %10llu\n\n",
626 "TKIP counter measure used",
627 tgt_stats->tkip_cnter_measures_invoked);
629 len += scnprintf(buf + len, buf_len - len, "%25s\n",
631 len += scnprintf(buf + len, buf_len - len, "%25s\n",
632 "=================");
634 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
635 "Ucast packets", tgt_stats->rx_ucast_pkt);
636 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
637 "Ucast Rate", tgt_stats->rx_ucast_rate);
638 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
639 "Bcast packets", tgt_stats->rx_bcast_pkt);
640 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
641 "Ucast byte", tgt_stats->rx_ucast_byte);
642 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
643 "Bcast byte", tgt_stats->rx_bcast_byte);
644 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
645 "Fragmented pkt", tgt_stats->rx_frgment_pkt);
646 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
647 "Error", tgt_stats->rx_err);
648 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
649 "CRC Err", tgt_stats->rx_crc_err);
650 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
651 "Key chache miss", tgt_stats->rx_key_cache_miss);
652 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
653 "Decrypt Err", tgt_stats->rx_decrypt_err);
654 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
655 "Duplicate frame", tgt_stats->rx_dupl_frame);
656 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
657 "Tkip Mic failure", tgt_stats->tkip_local_mic_fail);
658 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
659 "TKIP format err", tgt_stats->tkip_fmt_err);
660 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
661 "CCMP format Err", tgt_stats->ccmp_fmt_err);
662 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n\n",
663 "CCMP Replay Err", tgt_stats->ccmp_replays);
665 len += scnprintf(buf + len, buf_len - len, "%25s\n",
666 "Misc Target stats");
667 len += scnprintf(buf + len, buf_len - len, "%25s\n",
668 "=================");
669 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
670 "Beacon Miss count", tgt_stats->cs_bmiss_cnt);
671 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
672 "Num Connects", tgt_stats->cs_connect_cnt);
673 len += scnprintf(buf + len, buf_len - len, "%20s %10llu\n",
674 "Num disconnects", tgt_stats->cs_discon_cnt);
675 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
676 "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
677 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
678 "ARP pkt received", tgt_stats->arp_received);
679 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
680 "ARP pkt matched", tgt_stats->arp_matched);
681 len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
682 "ARP pkt replied", tgt_stats->arp_replied);
687 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
693 static const struct file_operations fops_tgt_stats = {
694 .read = read_file_tgt_stats,
696 .owner = THIS_MODULE,
697 .llseek = default_llseek,
700 #define print_credit_info(fmt_str, ep_list_field) \
701 (len += scnprintf(buf + len, buf_len - len, fmt_str, \
702 ep_list->ep_list_field))
703 #define CREDIT_INFO_DISPLAY_STRING_LEN 200
704 #define CREDIT_INFO_LEN 128
706 static ssize_t read_file_credit_dist_stats(struct file *file,
707 char __user *user_buf,
708 size_t count, loff_t *ppos)
710 struct ath6kl *ar = file->private_data;
711 struct htc_target *target = ar->htc_target;
712 struct htc_endpoint_credit_dist *ep_list;
714 unsigned int buf_len, len = 0;
717 buf_len = CREDIT_INFO_DISPLAY_STRING_LEN +
718 get_queue_depth(&target->cred_dist_list) * CREDIT_INFO_LEN;
719 buf = kzalloc(buf_len, GFP_KERNEL);
723 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
724 "Total Avail Credits: ",
725 target->credit_info->total_avail_credits);
726 len += scnprintf(buf + len, buf_len - len, "%25s%5d\n",
728 target->credit_info->cur_free_credits);
730 len += scnprintf(buf + len, buf_len - len,
731 " Epid Flags Cred_norm Cred_min Credits Cred_assngd"
732 " Seek_cred Cred_sz Cred_per_msg Cred_to_dist"
735 list_for_each_entry(ep_list, &target->cred_dist_list, list) {
736 print_credit_info(" %2d", endpoint);
737 print_credit_info("%10x", dist_flags);
738 print_credit_info("%8d", cred_norm);
739 print_credit_info("%9d", cred_min);
740 print_credit_info("%9d", credits);
741 print_credit_info("%10d", cred_assngd);
742 print_credit_info("%13d", seek_cred);
743 print_credit_info("%12d", cred_sz);
744 print_credit_info("%9d", cred_per_msg);
745 print_credit_info("%14d", cred_to_dist);
746 len += scnprintf(buf + len, buf_len - len, "%12d\n",
747 get_queue_depth(&ep_list->htc_ep->txq));
753 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
758 static const struct file_operations fops_credit_dist_stats = {
759 .read = read_file_credit_dist_stats,
761 .owner = THIS_MODULE,
762 .llseek = default_llseek,
765 static unsigned int print_endpoint_stat(struct htc_target *target, char *buf,
766 unsigned int buf_len, unsigned int len,
767 int offset, const char *name)
770 struct htc_endpoint_stats *ep_st;
773 len += scnprintf(buf + len, buf_len - len, "%s:", name);
774 for (i = 0; i < ENDPOINT_MAX; i++) {
775 ep_st = &target->endpoint[i].ep_st;
776 counter = ((u32 *) ep_st) + (offset / 4);
777 len += scnprintf(buf + len, buf_len - len, " %u", *counter);
779 len += scnprintf(buf + len, buf_len - len, "\n");
784 static ssize_t ath6kl_endpoint_stats_read(struct file *file,
785 char __user *user_buf,
786 size_t count, loff_t *ppos)
788 struct ath6kl *ar = file->private_data;
789 struct htc_target *target = ar->htc_target;
791 unsigned int buf_len, len = 0;
794 buf_len = sizeof(struct htc_endpoint_stats) / sizeof(u32) *
795 (25 + ENDPOINT_MAX * 11);
796 buf = kmalloc(buf_len, GFP_KERNEL);
800 #define EPSTAT(name) \
802 len = print_endpoint_stat(target, buf, buf_len, len, \
803 offsetof(struct htc_endpoint_stats, \
808 EPSTAT(cred_low_indicate);
810 EPSTAT(tx_pkt_bundled);
814 EPSTAT(cred_rpt_from_rx);
815 EPSTAT(cred_rpt_from_other);
816 EPSTAT(cred_rpt_ep0);
817 EPSTAT(cred_from_rx);
818 EPSTAT(cred_from_other);
819 EPSTAT(cred_from_ep0);
825 EPSTAT(rx_bundle_lkahd);
826 EPSTAT(rx_bundle_from_hdr);
827 EPSTAT(rx_alloc_thresh_hit);
828 EPSTAT(rxalloc_thresh_byte);
834 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
839 static ssize_t ath6kl_endpoint_stats_write(struct file *file,
840 const char __user *user_buf,
841 size_t count, loff_t *ppos)
843 struct ath6kl *ar = file->private_data;
844 struct htc_target *target = ar->htc_target;
847 struct htc_endpoint_stats *ep_st;
849 ret = kstrtou32_from_user(user_buf, count, 0, &val);
853 for (i = 0; i < ENDPOINT_MAX; i++) {
854 ep_st = &target->endpoint[i].ep_st;
855 memset(ep_st, 0, sizeof(*ep_st));
862 static const struct file_operations fops_endpoint_stats = {
864 .read = ath6kl_endpoint_stats_read,
865 .write = ath6kl_endpoint_stats_write,
866 .owner = THIS_MODULE,
867 .llseek = default_llseek,
870 static unsigned long ath6kl_get_num_reg(void)
873 unsigned long n_reg = 0;
875 for (i = 0; i < ARRAY_SIZE(diag_reg); i++)
877 (diag_reg[i].reg_end - diag_reg[i].reg_start) / 4 + 1;
882 static bool ath6kl_dbg_is_diag_reg_valid(u32 reg_addr)
886 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
887 if (reg_addr >= diag_reg[i].reg_start &&
888 reg_addr <= diag_reg[i].reg_end)
895 static ssize_t ath6kl_regread_read(struct file *file, char __user *user_buf,
896 size_t count, loff_t *ppos)
898 struct ath6kl *ar = file->private_data;
900 unsigned int len = 0;
902 if (ar->debug.dbgfs_diag_reg)
903 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n",
904 ar->debug.dbgfs_diag_reg);
906 len += scnprintf(buf + len, sizeof(buf) - len,
907 "All diag registers\n");
909 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
912 static ssize_t ath6kl_regread_write(struct file *file,
913 const char __user *user_buf,
914 size_t count, loff_t *ppos)
916 struct ath6kl *ar = file->private_data;
917 unsigned long reg_addr;
919 if (kstrtoul_from_user(user_buf, count, 0, ®_addr))
922 if ((reg_addr % 4) != 0)
925 if (reg_addr && !ath6kl_dbg_is_diag_reg_valid(reg_addr))
928 ar->debug.dbgfs_diag_reg = reg_addr;
933 static const struct file_operations fops_diag_reg_read = {
934 .read = ath6kl_regread_read,
935 .write = ath6kl_regread_write,
937 .owner = THIS_MODULE,
938 .llseek = default_llseek,
941 static int ath6kl_regdump_open(struct inode *inode, struct file *file)
943 struct ath6kl *ar = inode->i_private;
945 unsigned long int reg_len;
946 unsigned int len = 0, n_reg;
951 /* Dump all the registers if no register is specified */
952 if (!ar->debug.dbgfs_diag_reg)
953 n_reg = ath6kl_get_num_reg();
957 reg_len = n_reg * REG_OUTPUT_LEN_PER_LINE;
959 reg_len += REGTYPE_STR_LEN;
961 buf = vmalloc(reg_len);
966 addr = ar->debug.dbgfs_diag_reg;
968 status = ath6kl_diag_read32(ar,
969 TARG_VTOP(ar->target_type, addr),
974 len += scnprintf(buf + len, reg_len - len,
975 "0x%06x 0x%08x\n", addr, le32_to_cpu(reg_val));
979 for (i = 0; i < ARRAY_SIZE(diag_reg); i++) {
980 len += scnprintf(buf + len, reg_len - len,
981 "%s\n", diag_reg[i].reg_info);
982 for (addr = diag_reg[i].reg_start;
983 addr <= diag_reg[i].reg_end; addr += 4) {
984 status = ath6kl_diag_read32(ar,
985 TARG_VTOP(ar->target_type, addr),
990 len += scnprintf(buf + len, reg_len - len,
992 addr, le32_to_cpu(reg_val));
997 file->private_data = buf;
1001 ath6kl_warn("Unable to read memory:%u\n", addr);
1006 static ssize_t ath6kl_regdump_read(struct file *file, char __user *user_buf,
1007 size_t count, loff_t *ppos)
1009 u8 *buf = file->private_data;
1010 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
1013 static int ath6kl_regdump_release(struct inode *inode, struct file *file)
1015 vfree(file->private_data);
1019 static const struct file_operations fops_reg_dump = {
1020 .open = ath6kl_regdump_open,
1021 .read = ath6kl_regdump_read,
1022 .release = ath6kl_regdump_release,
1023 .owner = THIS_MODULE,
1024 .llseek = default_llseek,
1027 static ssize_t ath6kl_lrssi_roam_write(struct file *file,
1028 const char __user *user_buf,
1029 size_t count, loff_t *ppos)
1031 struct ath6kl *ar = file->private_data;
1032 unsigned long lrssi_roam_threshold;
1034 if (kstrtoul_from_user(user_buf, count, 0, &lrssi_roam_threshold))
1037 ar->lrssi_roam_threshold = lrssi_roam_threshold;
1039 ath6kl_wmi_set_roam_lrssi_cmd(ar->wmi, ar->lrssi_roam_threshold);
1044 static ssize_t ath6kl_lrssi_roam_read(struct file *file,
1045 char __user *user_buf,
1046 size_t count, loff_t *ppos)
1048 struct ath6kl *ar = file->private_data;
1052 len = snprintf(buf, sizeof(buf), "%u\n", ar->lrssi_roam_threshold);
1054 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1057 static const struct file_operations fops_lrssi_roam_threshold = {
1058 .read = ath6kl_lrssi_roam_read,
1059 .write = ath6kl_lrssi_roam_write,
1060 .open = simple_open,
1061 .owner = THIS_MODULE,
1062 .llseek = default_llseek,
1065 static ssize_t ath6kl_regwrite_read(struct file *file,
1066 char __user *user_buf,
1067 size_t count, loff_t *ppos)
1069 struct ath6kl *ar = file->private_data;
1071 unsigned int len = 0;
1073 len = scnprintf(buf, sizeof(buf), "Addr: 0x%x Val: 0x%x\n",
1074 ar->debug.diag_reg_addr_wr, ar->debug.diag_reg_val_wr);
1076 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1079 static ssize_t ath6kl_regwrite_write(struct file *file,
1080 const char __user *user_buf,
1081 size_t count, loff_t *ppos)
1083 struct ath6kl *ar = file->private_data;
1086 unsigned int len = 0;
1087 u32 reg_addr, reg_val;
1089 len = min(count, sizeof(buf) - 1);
1090 if (copy_from_user(buf, user_buf, len))
1096 token = strsep(&sptr, "=");
1100 if (kstrtou32(token, 0, ®_addr))
1103 if (!ath6kl_dbg_is_diag_reg_valid(reg_addr))
1106 if (kstrtou32(sptr, 0, ®_val))
1109 ar->debug.diag_reg_addr_wr = reg_addr;
1110 ar->debug.diag_reg_val_wr = reg_val;
1112 if (ath6kl_diag_write32(ar, ar->debug.diag_reg_addr_wr,
1113 cpu_to_le32(ar->debug.diag_reg_val_wr)))
1119 static const struct file_operations fops_diag_reg_write = {
1120 .read = ath6kl_regwrite_read,
1121 .write = ath6kl_regwrite_write,
1122 .open = simple_open,
1123 .owner = THIS_MODULE,
1124 .llseek = default_llseek,
1127 int ath6kl_debug_roam_tbl_event(struct ath6kl *ar, const void *buf,
1130 const struct wmi_target_roam_tbl *tbl;
1133 if (len < sizeof(*tbl))
1136 tbl = (const struct wmi_target_roam_tbl *) buf;
1137 num_entries = le16_to_cpu(tbl->num_entries);
1138 if (sizeof(*tbl) + num_entries * sizeof(struct wmi_bss_roam_info) >
1142 if (ar->debug.roam_tbl == NULL ||
1143 ar->debug.roam_tbl_len < (unsigned int) len) {
1144 kfree(ar->debug.roam_tbl);
1145 ar->debug.roam_tbl = kmalloc(len, GFP_ATOMIC);
1146 if (ar->debug.roam_tbl == NULL)
1150 memcpy(ar->debug.roam_tbl, buf, len);
1151 ar->debug.roam_tbl_len = len;
1153 if (test_bit(ROAM_TBL_PEND, &ar->flag)) {
1154 clear_bit(ROAM_TBL_PEND, &ar->flag);
1155 wake_up(&ar->event_wq);
1161 static ssize_t ath6kl_roam_table_read(struct file *file, char __user *user_buf,
1162 size_t count, loff_t *ppos)
1164 struct ath6kl *ar = file->private_data;
1167 struct wmi_target_roam_tbl *tbl;
1170 unsigned int len, buf_len;
1173 if (down_interruptible(&ar->sem))
1176 set_bit(ROAM_TBL_PEND, &ar->flag);
1178 ret = ath6kl_wmi_get_roam_tbl_cmd(ar->wmi);
1184 left = wait_event_interruptible_timeout(
1185 ar->event_wq, !test_bit(ROAM_TBL_PEND, &ar->flag), WMI_TIMEOUT);
1191 if (ar->debug.roam_tbl == NULL)
1194 tbl = (struct wmi_target_roam_tbl *) ar->debug.roam_tbl;
1195 num_entries = le16_to_cpu(tbl->num_entries);
1197 buf_len = 100 + num_entries * 100;
1198 buf = kzalloc(buf_len, GFP_KERNEL);
1202 len += scnprintf(buf + len, buf_len - len,
1204 "# roam_util bssid rssi rssidt last_rssi util bias\n",
1205 le16_to_cpu(tbl->roam_mode));
1207 for (i = 0; i < num_entries; i++) {
1208 struct wmi_bss_roam_info *info = &tbl->info[i];
1209 len += scnprintf(buf + len, buf_len - len,
1210 "%d %pM %d %d %d %d %d\n",
1211 a_sle32_to_cpu(info->roam_util), info->bssid,
1212 info->rssi, info->rssidt, info->last_rssi,
1213 info->util, info->bias);
1219 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
1225 static const struct file_operations fops_roam_table = {
1226 .read = ath6kl_roam_table_read,
1227 .open = simple_open,
1228 .owner = THIS_MODULE,
1229 .llseek = default_llseek,
1232 static ssize_t ath6kl_force_roam_write(struct file *file,
1233 const char __user *user_buf,
1234 size_t count, loff_t *ppos)
1236 struct ath6kl *ar = file->private_data;
1242 len = min(count, sizeof(buf) - 1);
1243 if (copy_from_user(buf, user_buf, len))
1247 if (!mac_pton(buf, bssid))
1250 ret = ath6kl_wmi_force_roam_cmd(ar->wmi, bssid);
1257 static const struct file_operations fops_force_roam = {
1258 .write = ath6kl_force_roam_write,
1259 .open = simple_open,
1260 .owner = THIS_MODULE,
1261 .llseek = default_llseek,
1264 static ssize_t ath6kl_roam_mode_write(struct file *file,
1265 const char __user *user_buf,
1266 size_t count, loff_t *ppos)
1268 struct ath6kl *ar = file->private_data;
1272 enum wmi_roam_mode mode;
1274 len = min(count, sizeof(buf) - 1);
1275 if (copy_from_user(buf, user_buf, len))
1278 if (len > 0 && buf[len - 1] == '\n')
1279 buf[len - 1] = '\0';
1281 if (strcasecmp(buf, "default") == 0)
1282 mode = WMI_DEFAULT_ROAM_MODE;
1283 else if (strcasecmp(buf, "bssbias") == 0)
1284 mode = WMI_HOST_BIAS_ROAM_MODE;
1285 else if (strcasecmp(buf, "lock") == 0)
1286 mode = WMI_LOCK_BSS_MODE;
1290 ret = ath6kl_wmi_set_roam_mode_cmd(ar->wmi, mode);
1297 static const struct file_operations fops_roam_mode = {
1298 .write = ath6kl_roam_mode_write,
1299 .open = simple_open,
1300 .owner = THIS_MODULE,
1301 .llseek = default_llseek,
1304 void ath6kl_debug_set_keepalive(struct ath6kl *ar, u8 keepalive)
1306 ar->debug.keepalive = keepalive;
1309 static ssize_t ath6kl_keepalive_read(struct file *file, char __user *user_buf,
1310 size_t count, loff_t *ppos)
1312 struct ath6kl *ar = file->private_data;
1316 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.keepalive);
1318 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1321 static ssize_t ath6kl_keepalive_write(struct file *file,
1322 const char __user *user_buf,
1323 size_t count, loff_t *ppos)
1325 struct ath6kl *ar = file->private_data;
1329 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1333 ret = ath6kl_wmi_set_keepalive_cmd(ar->wmi, 0, val);
1340 static const struct file_operations fops_keepalive = {
1341 .open = simple_open,
1342 .read = ath6kl_keepalive_read,
1343 .write = ath6kl_keepalive_write,
1344 .owner = THIS_MODULE,
1345 .llseek = default_llseek,
1348 void ath6kl_debug_set_disconnect_timeout(struct ath6kl *ar, u8 timeout)
1350 ar->debug.disc_timeout = timeout;
1353 static ssize_t ath6kl_disconnect_timeout_read(struct file *file,
1354 char __user *user_buf,
1355 size_t count, loff_t *ppos)
1357 struct ath6kl *ar = file->private_data;
1361 len = snprintf(buf, sizeof(buf), "%u\n", ar->debug.disc_timeout);
1363 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1366 static ssize_t ath6kl_disconnect_timeout_write(struct file *file,
1367 const char __user *user_buf,
1368 size_t count, loff_t *ppos)
1370 struct ath6kl *ar = file->private_data;
1374 ret = kstrtou8_from_user(user_buf, count, 0, &val);
1378 ret = ath6kl_wmi_disctimeout_cmd(ar->wmi, 0, val);
1385 static const struct file_operations fops_disconnect_timeout = {
1386 .open = simple_open,
1387 .read = ath6kl_disconnect_timeout_read,
1388 .write = ath6kl_disconnect_timeout_write,
1389 .owner = THIS_MODULE,
1390 .llseek = default_llseek,
1393 static ssize_t ath6kl_create_qos_write(struct file *file,
1394 const char __user *user_buf,
1395 size_t count, loff_t *ppos)
1397 struct ath6kl *ar = file->private_data;
1398 struct ath6kl_vif *vif;
1402 struct wmi_create_pstream_cmd pstream;
1406 vif = ath6kl_vif_first(ar);
1410 len = min(count, sizeof(buf) - 1);
1411 if (copy_from_user(buf, user_buf, len))
1416 token = strsep(&sptr, " ");
1419 if (kstrtou8(token, 0, &pstream.user_pri))
1422 token = strsep(&sptr, " ");
1425 if (kstrtou8(token, 0, &pstream.traffic_direc))
1428 token = strsep(&sptr, " ");
1431 if (kstrtou8(token, 0, &pstream.traffic_class))
1434 token = strsep(&sptr, " ");
1437 if (kstrtou8(token, 0, &pstream.traffic_type))
1440 token = strsep(&sptr, " ");
1443 if (kstrtou8(token, 0, &pstream.voice_psc_cap))
1446 token = strsep(&sptr, " ");
1449 if (kstrtou32(token, 0, &val32))
1451 pstream.min_service_int = cpu_to_le32(val32);
1453 token = strsep(&sptr, " ");
1456 if (kstrtou32(token, 0, &val32))
1458 pstream.max_service_int = cpu_to_le32(val32);
1460 token = strsep(&sptr, " ");
1463 if (kstrtou32(token, 0, &val32))
1465 pstream.inactivity_int = cpu_to_le32(val32);
1467 token = strsep(&sptr, " ");
1470 if (kstrtou32(token, 0, &val32))
1472 pstream.suspension_int = cpu_to_le32(val32);
1474 token = strsep(&sptr, " ");
1477 if (kstrtou32(token, 0, &val32))
1479 pstream.service_start_time = cpu_to_le32(val32);
1481 token = strsep(&sptr, " ");
1484 if (kstrtou8(token, 0, &pstream.tsid))
1487 token = strsep(&sptr, " ");
1490 if (kstrtou16(token, 0, &val16))
1492 pstream.nominal_msdu = cpu_to_le16(val16);
1494 token = strsep(&sptr, " ");
1497 if (kstrtou16(token, 0, &val16))
1499 pstream.max_msdu = cpu_to_le16(val16);
1501 token = strsep(&sptr, " ");
1504 if (kstrtou32(token, 0, &val32))
1506 pstream.min_data_rate = cpu_to_le32(val32);
1508 token = strsep(&sptr, " ");
1511 if (kstrtou32(token, 0, &val32))
1513 pstream.mean_data_rate = cpu_to_le32(val32);
1515 token = strsep(&sptr, " ");
1518 if (kstrtou32(token, 0, &val32))
1520 pstream.peak_data_rate = cpu_to_le32(val32);
1522 token = strsep(&sptr, " ");
1525 if (kstrtou32(token, 0, &val32))
1527 pstream.max_burst_size = cpu_to_le32(val32);
1529 token = strsep(&sptr, " ");
1532 if (kstrtou32(token, 0, &val32))
1534 pstream.delay_bound = cpu_to_le32(val32);
1536 token = strsep(&sptr, " ");
1539 if (kstrtou32(token, 0, &val32))
1541 pstream.min_phy_rate = cpu_to_le32(val32);
1543 token = strsep(&sptr, " ");
1546 if (kstrtou32(token, 0, &val32))
1548 pstream.sba = cpu_to_le32(val32);
1550 token = strsep(&sptr, " ");
1553 if (kstrtou32(token, 0, &val32))
1555 pstream.medium_time = cpu_to_le32(val32);
1557 pstream.nominal_phy = le32_to_cpu(pstream.min_phy_rate) / 1000000;
1559 ath6kl_wmi_create_pstream_cmd(ar->wmi, vif->fw_vif_idx, &pstream);
1564 static const struct file_operations fops_create_qos = {
1565 .write = ath6kl_create_qos_write,
1566 .open = simple_open,
1567 .owner = THIS_MODULE,
1568 .llseek = default_llseek,
1571 static ssize_t ath6kl_delete_qos_write(struct file *file,
1572 const char __user *user_buf,
1573 size_t count, loff_t *ppos)
1575 struct ath6kl *ar = file->private_data;
1576 struct ath6kl_vif *vif;
1583 vif = ath6kl_vif_first(ar);
1587 len = min(count, sizeof(buf) - 1);
1588 if (copy_from_user(buf, user_buf, len))
1593 token = strsep(&sptr, " ");
1596 if (kstrtou8(token, 0, &traffic_class))
1599 token = strsep(&sptr, " ");
1602 if (kstrtou8(token, 0, &tsid))
1605 ath6kl_wmi_delete_pstream_cmd(ar->wmi, vif->fw_vif_idx,
1606 traffic_class, tsid);
1611 static const struct file_operations fops_delete_qos = {
1612 .write = ath6kl_delete_qos_write,
1613 .open = simple_open,
1614 .owner = THIS_MODULE,
1615 .llseek = default_llseek,
1618 static ssize_t ath6kl_bgscan_int_write(struct file *file,
1619 const char __user *user_buf,
1620 size_t count, loff_t *ppos)
1622 struct ath6kl *ar = file->private_data;
1623 struct ath6kl_vif *vif;
1628 vif = ath6kl_vif_first(ar);
1632 len = min(count, sizeof(buf) - 1);
1633 if (copy_from_user(buf, user_buf, len))
1637 if (kstrtou16(buf, 0, &bgscan_int))
1640 if (bgscan_int == 0)
1641 bgscan_int = 0xffff;
1643 vif->bg_scan_period = bgscan_int;
1645 ath6kl_wmi_scanparams_cmd(ar->wmi, 0, 0, 0, bgscan_int, 0, 0, 0, 3,
1651 static const struct file_operations fops_bgscan_int = {
1652 .write = ath6kl_bgscan_int_write,
1653 .open = simple_open,
1654 .owner = THIS_MODULE,
1655 .llseek = default_llseek,
1658 static ssize_t ath6kl_listen_int_write(struct file *file,
1659 const char __user *user_buf,
1660 size_t count, loff_t *ppos)
1662 struct ath6kl *ar = file->private_data;
1663 struct ath6kl_vif *vif;
1664 u16 listen_interval;
1668 vif = ath6kl_vif_first(ar);
1672 len = min(count, sizeof(buf) - 1);
1673 if (copy_from_user(buf, user_buf, len))
1677 if (kstrtou16(buf, 0, &listen_interval))
1680 if ((listen_interval < 15) || (listen_interval > 3000))
1683 vif->listen_intvl_t = listen_interval;
1684 ath6kl_wmi_listeninterval_cmd(ar->wmi, vif->fw_vif_idx,
1685 vif->listen_intvl_t, 0);
1690 static ssize_t ath6kl_listen_int_read(struct file *file,
1691 char __user *user_buf,
1692 size_t count, loff_t *ppos)
1694 struct ath6kl *ar = file->private_data;
1695 struct ath6kl_vif *vif;
1699 vif = ath6kl_vif_first(ar);
1703 len = scnprintf(buf, sizeof(buf), "%u\n", vif->listen_intvl_t);
1705 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1708 static const struct file_operations fops_listen_int = {
1709 .read = ath6kl_listen_int_read,
1710 .write = ath6kl_listen_int_write,
1711 .open = simple_open,
1712 .owner = THIS_MODULE,
1713 .llseek = default_llseek,
1716 static ssize_t ath6kl_power_params_write(struct file *file,
1717 const char __user *user_buf,
1718 size_t count, loff_t *ppos)
1720 struct ath6kl *ar = file->private_data;
1722 unsigned int len = 0;
1724 u16 idle_period, ps_poll_num, dtim,
1727 len = min(count, sizeof(buf) - 1);
1728 if (copy_from_user(buf, user_buf, len))
1733 token = strsep(&sptr, " ");
1736 if (kstrtou16(token, 0, &idle_period))
1739 token = strsep(&sptr, " ");
1742 if (kstrtou16(token, 0, &ps_poll_num))
1745 token = strsep(&sptr, " ");
1748 if (kstrtou16(token, 0, &dtim))
1751 token = strsep(&sptr, " ");
1754 if (kstrtou16(token, 0, &tx_wakeup))
1757 token = strsep(&sptr, " ");
1760 if (kstrtou16(token, 0, &num_tx))
1763 ath6kl_wmi_pmparams_cmd(ar->wmi, 0, idle_period, ps_poll_num,
1764 dtim, tx_wakeup, num_tx, 0);
1769 static const struct file_operations fops_power_params = {
1770 .write = ath6kl_power_params_write,
1771 .open = simple_open,
1772 .owner = THIS_MODULE,
1773 .llseek = default_llseek,
1776 void ath6kl_debug_init(struct ath6kl *ar)
1778 skb_queue_head_init(&ar->debug.fwlog_queue);
1779 init_completion(&ar->debug.fwlog_completion);
1782 * Actually we are lying here but don't know how to read the mask
1783 * value from the firmware.
1785 ar->debug.fwlog_mask = 0;
1789 * Initialisation needs to happen in two stages as fwlog events can come
1790 * before cfg80211 is initialised, and debugfs depends on cfg80211
1793 int ath6kl_debug_init_fs(struct ath6kl *ar)
1795 ar->debugfs_phy = debugfs_create_dir("ath6kl",
1796 ar->wiphy->debugfsdir);
1797 if (!ar->debugfs_phy)
1800 debugfs_create_file("tgt_stats", S_IRUSR, ar->debugfs_phy, ar,
1803 if (ar->hif_type == ATH6KL_HIF_TYPE_SDIO)
1804 debugfs_create_file("credit_dist_stats", S_IRUSR,
1805 ar->debugfs_phy, ar,
1806 &fops_credit_dist_stats);
1808 debugfs_create_file("endpoint_stats", S_IRUSR | S_IWUSR,
1809 ar->debugfs_phy, ar, &fops_endpoint_stats);
1811 debugfs_create_file("fwlog", S_IRUSR, ar->debugfs_phy, ar,
1814 debugfs_create_file("fwlog_block", S_IRUSR, ar->debugfs_phy, ar,
1817 debugfs_create_file("fwlog_mask", S_IRUSR | S_IWUSR, ar->debugfs_phy,
1818 ar, &fops_fwlog_mask);
1820 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1821 &fops_diag_reg_read);
1823 debugfs_create_file("reg_dump", S_IRUSR, ar->debugfs_phy, ar,
1826 debugfs_create_file("lrssi_roam_threshold", S_IRUSR | S_IWUSR,
1827 ar->debugfs_phy, ar, &fops_lrssi_roam_threshold);
1829 debugfs_create_file("reg_write", S_IRUSR | S_IWUSR,
1830 ar->debugfs_phy, ar, &fops_diag_reg_write);
1832 debugfs_create_file("war_stats", S_IRUSR, ar->debugfs_phy, ar,
1835 debugfs_create_file("roam_table", S_IRUSR, ar->debugfs_phy, ar,
1838 debugfs_create_file("force_roam", S_IWUSR, ar->debugfs_phy, ar,
1841 debugfs_create_file("roam_mode", S_IWUSR, ar->debugfs_phy, ar,
1844 debugfs_create_file("keepalive", S_IRUSR | S_IWUSR, ar->debugfs_phy, ar,
1847 debugfs_create_file("disconnect_timeout", S_IRUSR | S_IWUSR,
1848 ar->debugfs_phy, ar, &fops_disconnect_timeout);
1850 debugfs_create_file("create_qos", S_IWUSR, ar->debugfs_phy, ar,
1853 debugfs_create_file("delete_qos", S_IWUSR, ar->debugfs_phy, ar,
1856 debugfs_create_file("bgscan_interval", S_IWUSR,
1857 ar->debugfs_phy, ar, &fops_bgscan_int);
1859 debugfs_create_file("listen_interval", S_IRUSR | S_IWUSR,
1860 ar->debugfs_phy, ar, &fops_listen_int);
1862 debugfs_create_file("power_params", S_IWUSR, ar->debugfs_phy, ar,
1863 &fops_power_params);
1868 void ath6kl_debug_cleanup(struct ath6kl *ar)
1870 skb_queue_purge(&ar->debug.fwlog_queue);
1871 complete(&ar->debug.fwlog_completion);
1872 kfree(ar->debug.roam_tbl);