1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
8 #include <linux/module.h>
9 #include <linux/debugfs.h>
10 #include <linux/vmalloc.h>
11 #include <linux/crc32.h>
12 #include <linux/firmware.h>
20 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
22 #define ATH10K_DEBUG_CAL_DATA_LEN 12064
24 void ath10k_info(struct ath10k
*ar
, const char *fmt
, ...)
26 struct va_format vaf
= {
33 dev_info(ar
->dev
, "%pV", &vaf
);
34 trace_ath10k_log_info(ar
, &vaf
);
37 EXPORT_SYMBOL(ath10k_info
);
39 void ath10k_debug_print_hwfw_info(struct ath10k
*ar
)
41 const struct firmware
*firmware
;
42 char fw_features
[128] = {};
45 ath10k_core_get_fw_features_str(ar
, fw_features
, sizeof(fw_features
));
47 ath10k_info(ar
, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
50 ar
->bus_param
.chip_id
,
51 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
53 ath10k_info(ar
, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
54 IS_ENABLED(CONFIG_ATH10K_DEBUG
),
55 IS_ENABLED(CONFIG_ATH10K_DEBUGFS
),
56 IS_ENABLED(CONFIG_ATH10K_TRACING
),
57 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
),
58 IS_ENABLED(CONFIG_NL80211_TESTMODE
));
60 firmware
= ar
->normal_mode_fw
.fw_file
.firmware
;
62 crc
= crc32_le(0, firmware
->data
, firmware
->size
);
64 ath10k_info(ar
, "firmware ver %s api %d features %s crc32 %08x\n",
65 ar
->hw
->wiphy
->fw_version
,
71 void ath10k_debug_print_board_info(struct ath10k
*ar
)
74 const struct firmware
*board
;
77 if (ar
->id
.bmi_ids_valid
)
78 scnprintf(boardinfo
, sizeof(boardinfo
), "%d:%d",
79 ar
->id
.bmi_chip_id
, ar
->id
.bmi_board_id
);
81 scnprintf(boardinfo
, sizeof(boardinfo
), "N/A");
83 board
= ar
->normal_mode_fw
.board
;
84 if (!IS_ERR_OR_NULL(board
))
85 crc
= crc32_le(0, board
->data
, board
->size
);
89 ath10k_info(ar
, "board_file api %d bmi_id %s crc32 %08x",
95 void ath10k_debug_print_boot_info(struct ath10k
*ar
)
97 ath10k_info(ar
, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
98 ar
->htt
.target_version_major
,
99 ar
->htt
.target_version_minor
,
100 ar
->normal_mode_fw
.fw_file
.wmi_op_version
,
101 ar
->normal_mode_fw
.fw_file
.htt_op_version
,
102 ath10k_cal_mode_str(ar
->cal_mode
),
103 ar
->max_num_stations
,
104 test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
),
105 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
));
108 void ath10k_print_driver_info(struct ath10k
*ar
)
110 ath10k_debug_print_hwfw_info(ar
);
111 ath10k_debug_print_board_info(ar
);
112 ath10k_debug_print_boot_info(ar
);
114 EXPORT_SYMBOL(ath10k_print_driver_info
);
116 void ath10k_err(struct ath10k
*ar
, const char *fmt
, ...)
118 struct va_format vaf
= {
125 dev_err(ar
->dev
, "%pV", &vaf
);
126 trace_ath10k_log_err(ar
, &vaf
);
129 EXPORT_SYMBOL(ath10k_err
);
131 void ath10k_warn(struct ath10k
*ar
, const char *fmt
, ...)
133 struct va_format vaf
= {
140 dev_warn_ratelimited(ar
->dev
, "%pV", &vaf
);
141 trace_ath10k_log_warn(ar
, &vaf
);
145 EXPORT_SYMBOL(ath10k_warn
);
147 #ifdef CONFIG_ATH10K_DEBUGFS
149 static ssize_t
ath10k_read_wmi_services(struct file
*file
,
150 char __user
*user_buf
,
151 size_t count
, loff_t
*ppos
)
153 struct ath10k
*ar
= file
->private_data
;
155 size_t len
= 0, buf_len
= 8192;
161 buf
= kzalloc(buf_len
, GFP_KERNEL
);
165 mutex_lock(&ar
->conf_mutex
);
167 spin_lock_bh(&ar
->data_lock
);
168 for (i
= 0; i
< WMI_SERVICE_MAX
; i
++) {
169 enabled
= test_bit(i
, ar
->wmi
.svc_map
);
170 name
= wmi_service_name(i
);
174 len
+= scnprintf(buf
+ len
, buf_len
- len
,
175 "%-40s %s (bit %d)\n",
176 "unknown", "enabled", i
);
181 len
+= scnprintf(buf
+ len
, buf_len
- len
,
183 name
, enabled
? "enabled" : "-");
185 spin_unlock_bh(&ar
->data_lock
);
187 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
189 mutex_unlock(&ar
->conf_mutex
);
195 static const struct file_operations fops_wmi_services
= {
196 .read
= ath10k_read_wmi_services
,
198 .owner
= THIS_MODULE
,
199 .llseek
= default_llseek
,
202 static void ath10k_fw_stats_pdevs_free(struct list_head
*head
)
204 struct ath10k_fw_stats_pdev
*i
, *tmp
;
206 list_for_each_entry_safe(i
, tmp
, head
, list
) {
212 static void ath10k_fw_stats_vdevs_free(struct list_head
*head
)
214 struct ath10k_fw_stats_vdev
*i
, *tmp
;
216 list_for_each_entry_safe(i
, tmp
, head
, list
) {
222 static void ath10k_fw_stats_peers_free(struct list_head
*head
)
224 struct ath10k_fw_stats_peer
*i
, *tmp
;
226 list_for_each_entry_safe(i
, tmp
, head
, list
) {
232 static void ath10k_fw_extd_stats_peers_free(struct list_head
*head
)
234 struct ath10k_fw_extd_stats_peer
*i
, *tmp
;
236 list_for_each_entry_safe(i
, tmp
, head
, list
) {
242 static void ath10k_debug_fw_stats_reset(struct ath10k
*ar
)
244 spin_lock_bh(&ar
->data_lock
);
245 ar
->debug
.fw_stats_done
= false;
246 ar
->debug
.fw_stats
.extended
= false;
247 ath10k_fw_stats_pdevs_free(&ar
->debug
.fw_stats
.pdevs
);
248 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
249 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
250 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
251 spin_unlock_bh(&ar
->data_lock
);
254 void ath10k_debug_fw_stats_process(struct ath10k
*ar
, struct sk_buff
*skb
)
256 struct ath10k_fw_stats stats
= {};
257 bool is_start
, is_started
, is_end
;
262 INIT_LIST_HEAD(&stats
.pdevs
);
263 INIT_LIST_HEAD(&stats
.vdevs
);
264 INIT_LIST_HEAD(&stats
.peers
);
265 INIT_LIST_HEAD(&stats
.peers_extd
);
267 spin_lock_bh(&ar
->data_lock
);
268 ret
= ath10k_wmi_pull_fw_stats(ar
, skb
, &stats
);
270 ath10k_warn(ar
, "failed to pull fw stats: %d\n", ret
);
274 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
275 * splits the stats data and delivers it in a ping-pong fashion of
276 * request cmd-update event.
278 * However there is no explicit end-of-data. Instead start-of-data is
279 * used as an implicit one. This works as follows:
280 * a) discard stat update events until one with pdev stats is
281 * delivered - this skips session started at end of (b)
282 * b) consume stat update events until another one with pdev stats is
283 * delivered which is treated as end-of-data and is itself discarded
285 if (ath10k_peer_stats_enabled(ar
))
286 ath10k_sta_update_rx_duration(ar
, &stats
);
288 if (ar
->debug
.fw_stats_done
) {
289 if (!ath10k_peer_stats_enabled(ar
))
290 ath10k_warn(ar
, "received unsolicited stats update event\n");
295 num_peers
= ath10k_wmi_fw_stats_num_peers(&ar
->debug
.fw_stats
.peers
);
296 num_vdevs
= ath10k_wmi_fw_stats_num_vdevs(&ar
->debug
.fw_stats
.vdevs
);
297 is_start
= (list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
298 !list_empty(&stats
.pdevs
));
299 is_end
= (!list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
300 !list_empty(&stats
.pdevs
));
303 list_splice_tail_init(&stats
.pdevs
, &ar
->debug
.fw_stats
.pdevs
);
306 ar
->debug
.fw_stats_done
= true;
309 ar
->debug
.fw_stats
.extended
= true;
311 is_started
= !list_empty(&ar
->debug
.fw_stats
.pdevs
);
313 if (is_started
&& !is_end
) {
314 if (num_peers
>= ATH10K_MAX_NUM_PEER_IDS
) {
315 /* Although this is unlikely impose a sane limit to
316 * prevent firmware from DoS-ing the host.
318 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
319 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
320 ath10k_warn(ar
, "dropping fw peer stats\n");
324 if (num_vdevs
>= BITS_PER_LONG
) {
325 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
326 ath10k_warn(ar
, "dropping fw vdev stats\n");
330 if (!list_empty(&stats
.peers
))
331 list_splice_tail_init(&stats
.peers_extd
,
332 &ar
->debug
.fw_stats
.peers_extd
);
334 list_splice_tail_init(&stats
.peers
, &ar
->debug
.fw_stats
.peers
);
335 list_splice_tail_init(&stats
.vdevs
, &ar
->debug
.fw_stats
.vdevs
);
338 complete(&ar
->debug
.fw_stats_complete
);
341 /* In some cases lists have been spliced and cleared. Free up
342 * resources if that is not the case.
344 ath10k_fw_stats_pdevs_free(&stats
.pdevs
);
345 ath10k_fw_stats_vdevs_free(&stats
.vdevs
);
346 ath10k_fw_stats_peers_free(&stats
.peers
);
347 ath10k_fw_extd_stats_peers_free(&stats
.peers_extd
);
349 spin_unlock_bh(&ar
->data_lock
);
352 int ath10k_debug_fw_stats_request(struct ath10k
*ar
)
354 unsigned long timeout
, time_left
;
357 lockdep_assert_held(&ar
->conf_mutex
);
359 timeout
= jiffies
+ msecs_to_jiffies(1 * HZ
);
361 ath10k_debug_fw_stats_reset(ar
);
364 if (time_after(jiffies
, timeout
))
367 reinit_completion(&ar
->debug
.fw_stats_complete
);
369 ret
= ath10k_wmi_request_stats(ar
, ar
->fw_stats_req_mask
);
371 ath10k_warn(ar
, "could not request stats (%d)\n", ret
);
376 wait_for_completion_timeout(&ar
->debug
.fw_stats_complete
,
381 spin_lock_bh(&ar
->data_lock
);
382 if (ar
->debug
.fw_stats_done
) {
383 spin_unlock_bh(&ar
->data_lock
);
386 spin_unlock_bh(&ar
->data_lock
);
392 static int ath10k_fw_stats_open(struct inode
*inode
, struct file
*file
)
394 struct ath10k
*ar
= inode
->i_private
;
398 mutex_lock(&ar
->conf_mutex
);
400 if (ar
->state
!= ATH10K_STATE_ON
) {
405 buf
= vmalloc(ATH10K_FW_STATS_BUF_SIZE
);
411 ret
= ath10k_debug_fw_stats_request(ar
);
413 ath10k_warn(ar
, "failed to request fw stats: %d\n", ret
);
417 ret
= ath10k_wmi_fw_stats_fill(ar
, &ar
->debug
.fw_stats
, buf
);
419 ath10k_warn(ar
, "failed to fill fw stats: %d\n", ret
);
423 file
->private_data
= buf
;
425 mutex_unlock(&ar
->conf_mutex
);
432 mutex_unlock(&ar
->conf_mutex
);
436 static int ath10k_fw_stats_release(struct inode
*inode
, struct file
*file
)
438 vfree(file
->private_data
);
443 static ssize_t
ath10k_fw_stats_read(struct file
*file
, char __user
*user_buf
,
444 size_t count
, loff_t
*ppos
)
446 const char *buf
= file
->private_data
;
447 size_t len
= strlen(buf
);
449 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
452 static const struct file_operations fops_fw_stats
= {
453 .open
= ath10k_fw_stats_open
,
454 .release
= ath10k_fw_stats_release
,
455 .read
= ath10k_fw_stats_read
,
456 .owner
= THIS_MODULE
,
457 .llseek
= default_llseek
,
460 static ssize_t
ath10k_debug_fw_reset_stats_read(struct file
*file
,
461 char __user
*user_buf
,
462 size_t count
, loff_t
*ppos
)
464 struct ath10k
*ar
= file
->private_data
;
466 size_t len
= 0, buf_len
= 500;
469 buf
= kmalloc(buf_len
, GFP_KERNEL
);
473 spin_lock_bh(&ar
->data_lock
);
475 len
+= scnprintf(buf
+ len
, buf_len
- len
,
476 "fw_crash_counter\t\t%d\n", ar
->stats
.fw_crash_counter
);
477 len
+= scnprintf(buf
+ len
, buf_len
- len
,
478 "fw_warm_reset_counter\t\t%d\n",
479 ar
->stats
.fw_warm_reset_counter
);
480 len
+= scnprintf(buf
+ len
, buf_len
- len
,
481 "fw_cold_reset_counter\t\t%d\n",
482 ar
->stats
.fw_cold_reset_counter
);
484 spin_unlock_bh(&ar
->data_lock
);
486 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
493 static const struct file_operations fops_fw_reset_stats
= {
495 .read
= ath10k_debug_fw_reset_stats_read
,
496 .owner
= THIS_MODULE
,
497 .llseek
= default_llseek
,
500 /* This is a clean assert crash in firmware. */
501 static int ath10k_debug_fw_assert(struct ath10k
*ar
)
503 struct wmi_vdev_install_key_cmd
*cmd
;
506 skb
= ath10k_wmi_alloc_skb(ar
, sizeof(*cmd
) + 16);
510 cmd
= (struct wmi_vdev_install_key_cmd
*)skb
->data
;
511 memset(cmd
, 0, sizeof(*cmd
));
513 /* big enough number so that firmware asserts */
514 cmd
->vdev_id
= __cpu_to_le32(0x7ffe);
516 return ath10k_wmi_cmd_send(ar
, skb
,
517 ar
->wmi
.cmd
->vdev_install_key_cmdid
);
520 static ssize_t
ath10k_read_simulate_fw_crash(struct file
*file
,
521 char __user
*user_buf
,
522 size_t count
, loff_t
*ppos
)
525 "To simulate firmware crash write one of the keywords to this file:\n"
526 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
527 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
528 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
529 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
531 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
534 /* Simulate firmware crash:
535 * 'soft': Call wmi command causing firmware hang. This firmware hang is
536 * recoverable by warm firmware reset.
537 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
538 * vdev id. This is hard firmware crash because it is recoverable only by cold
541 static ssize_t
ath10k_write_simulate_fw_crash(struct file
*file
,
542 const char __user
*user_buf
,
543 size_t count
, loff_t
*ppos
)
545 struct ath10k
*ar
= file
->private_data
;
550 /* filter partial writes and invalid commands */
551 if (*ppos
!= 0 || count
>= sizeof(buf
) || count
== 0)
554 rc
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
558 /* drop the possible '\n' from the end */
559 if (buf
[*ppos
- 1] == '\n')
560 buf
[*ppos
- 1] = '\0';
562 mutex_lock(&ar
->conf_mutex
);
564 if (ar
->state
!= ATH10K_STATE_ON
&&
565 ar
->state
!= ATH10K_STATE_RESTARTED
) {
570 if (!strcmp(buf
, "soft")) {
571 ath10k_info(ar
, "simulating soft firmware crash\n");
572 ret
= ath10k_wmi_force_fw_hang(ar
, WMI_FORCE_FW_HANG_ASSERT
, 0);
573 } else if (!strcmp(buf
, "hard")) {
574 ath10k_info(ar
, "simulating hard firmware crash\n");
575 /* 0x7fff is vdev id, and it is always out of range for all
576 * firmware variants in order to force a firmware crash.
578 ret
= ath10k_wmi_vdev_set_param(ar
, 0x7fff,
579 ar
->wmi
.vdev_param
->rts_threshold
,
581 } else if (!strcmp(buf
, "assert")) {
582 ath10k_info(ar
, "simulating firmware assert crash\n");
583 ret
= ath10k_debug_fw_assert(ar
);
584 } else if (!strcmp(buf
, "hw-restart")) {
585 ath10k_info(ar
, "user requested hw restart\n");
586 ath10k_core_start_recovery(ar
);
594 ath10k_warn(ar
, "failed to simulate firmware crash: %d\n", ret
);
601 mutex_unlock(&ar
->conf_mutex
);
605 static const struct file_operations fops_simulate_fw_crash
= {
606 .read
= ath10k_read_simulate_fw_crash
,
607 .write
= ath10k_write_simulate_fw_crash
,
609 .owner
= THIS_MODULE
,
610 .llseek
= default_llseek
,
613 static ssize_t
ath10k_read_chip_id(struct file
*file
, char __user
*user_buf
,
614 size_t count
, loff_t
*ppos
)
616 struct ath10k
*ar
= file
->private_data
;
620 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->bus_param
.chip_id
);
622 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
625 static const struct file_operations fops_chip_id
= {
626 .read
= ath10k_read_chip_id
,
628 .owner
= THIS_MODULE
,
629 .llseek
= default_llseek
,
632 static ssize_t
ath10k_reg_addr_read(struct file
*file
,
633 char __user
*user_buf
,
634 size_t count
, loff_t
*ppos
)
636 struct ath10k
*ar
= file
->private_data
;
641 mutex_lock(&ar
->conf_mutex
);
642 reg_addr
= ar
->debug
.reg_addr
;
643 mutex_unlock(&ar
->conf_mutex
);
645 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "0x%x\n", reg_addr
);
647 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
650 static ssize_t
ath10k_reg_addr_write(struct file
*file
,
651 const char __user
*user_buf
,
652 size_t count
, loff_t
*ppos
)
654 struct ath10k
*ar
= file
->private_data
;
658 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_addr
);
662 if (!IS_ALIGNED(reg_addr
, 4))
665 mutex_lock(&ar
->conf_mutex
);
666 ar
->debug
.reg_addr
= reg_addr
;
667 mutex_unlock(&ar
->conf_mutex
);
672 static const struct file_operations fops_reg_addr
= {
673 .read
= ath10k_reg_addr_read
,
674 .write
= ath10k_reg_addr_write
,
676 .owner
= THIS_MODULE
,
677 .llseek
= default_llseek
,
680 static ssize_t
ath10k_reg_value_read(struct file
*file
,
681 char __user
*user_buf
,
682 size_t count
, loff_t
*ppos
)
684 struct ath10k
*ar
= file
->private_data
;
687 u32 reg_addr
, reg_val
;
690 mutex_lock(&ar
->conf_mutex
);
692 if (ar
->state
!= ATH10K_STATE_ON
&&
693 ar
->state
!= ATH10K_STATE_UTF
) {
698 reg_addr
= ar
->debug
.reg_addr
;
700 reg_val
= ath10k_hif_read32(ar
, reg_addr
);
701 len
= scnprintf(buf
, sizeof(buf
), "0x%08x:0x%08x\n", reg_addr
, reg_val
);
703 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
706 mutex_unlock(&ar
->conf_mutex
);
711 static ssize_t
ath10k_reg_value_write(struct file
*file
,
712 const char __user
*user_buf
,
713 size_t count
, loff_t
*ppos
)
715 struct ath10k
*ar
= file
->private_data
;
716 u32 reg_addr
, reg_val
;
719 mutex_lock(&ar
->conf_mutex
);
721 if (ar
->state
!= ATH10K_STATE_ON
&&
722 ar
->state
!= ATH10K_STATE_UTF
) {
727 reg_addr
= ar
->debug
.reg_addr
;
729 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_val
);
733 ath10k_hif_write32(ar
, reg_addr
, reg_val
);
738 mutex_unlock(&ar
->conf_mutex
);
743 static const struct file_operations fops_reg_value
= {
744 .read
= ath10k_reg_value_read
,
745 .write
= ath10k_reg_value_write
,
747 .owner
= THIS_MODULE
,
748 .llseek
= default_llseek
,
751 static ssize_t
ath10k_mem_value_read(struct file
*file
,
752 char __user
*user_buf
,
753 size_t count
, loff_t
*ppos
)
755 struct ath10k
*ar
= file
->private_data
;
765 mutex_lock(&ar
->conf_mutex
);
767 buf
= vmalloc(count
);
773 if (ar
->state
!= ATH10K_STATE_ON
&&
774 ar
->state
!= ATH10K_STATE_UTF
) {
779 ret
= ath10k_hif_diag_read(ar
, *ppos
, buf
, count
);
781 ath10k_warn(ar
, "failed to read address 0x%08x via diagnose window from debugfs: %d\n",
786 ret
= copy_to_user(user_buf
, buf
, count
);
798 mutex_unlock(&ar
->conf_mutex
);
803 static ssize_t
ath10k_mem_value_write(struct file
*file
,
804 const char __user
*user_buf
,
805 size_t count
, loff_t
*ppos
)
807 struct ath10k
*ar
= file
->private_data
;
817 mutex_lock(&ar
->conf_mutex
);
819 buf
= vmalloc(count
);
825 if (ar
->state
!= ATH10K_STATE_ON
&&
826 ar
->state
!= ATH10K_STATE_UTF
) {
831 ret
= copy_from_user(buf
, user_buf
, count
);
837 ret
= ath10k_hif_diag_write(ar
, *ppos
, buf
, count
);
839 ath10k_warn(ar
, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
849 mutex_unlock(&ar
->conf_mutex
);
854 static const struct file_operations fops_mem_value
= {
855 .read
= ath10k_mem_value_read
,
856 .write
= ath10k_mem_value_write
,
858 .owner
= THIS_MODULE
,
859 .llseek
= default_llseek
,
862 static int ath10k_debug_htt_stats_req(struct ath10k
*ar
)
867 lockdep_assert_held(&ar
->conf_mutex
);
869 if (ar
->debug
.htt_stats_mask
== 0)
870 /* htt stats are disabled */
873 if (ar
->state
!= ATH10K_STATE_ON
)
876 cookie
= get_jiffies_64();
878 ret
= ath10k_htt_h2t_stats_req(&ar
->htt
, ar
->debug
.htt_stats_mask
,
879 ar
->debug
.reset_htt_stats
, cookie
);
881 ath10k_warn(ar
, "failed to send htt stats request: %d\n", ret
);
885 queue_delayed_work(ar
->workqueue
, &ar
->debug
.htt_stats_dwork
,
886 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL
));
891 static void ath10k_debug_htt_stats_dwork(struct work_struct
*work
)
893 struct ath10k
*ar
= container_of(work
, struct ath10k
,
894 debug
.htt_stats_dwork
.work
);
896 mutex_lock(&ar
->conf_mutex
);
898 ath10k_debug_htt_stats_req(ar
);
900 mutex_unlock(&ar
->conf_mutex
);
903 static ssize_t
ath10k_read_htt_stats_mask(struct file
*file
,
904 char __user
*user_buf
,
905 size_t count
, loff_t
*ppos
)
907 struct ath10k
*ar
= file
->private_data
;
911 len
= scnprintf(buf
, sizeof(buf
), "%lu\n", ar
->debug
.htt_stats_mask
);
913 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
916 static ssize_t
ath10k_write_htt_stats_mask(struct file
*file
,
917 const char __user
*user_buf
,
918 size_t count
, loff_t
*ppos
)
920 struct ath10k
*ar
= file
->private_data
;
924 ret
= kstrtoul_from_user(user_buf
, count
, 0, &mask
);
928 /* max 17 bit masks (for now) */
929 if (mask
> HTT_STATS_BIT_MASK
)
932 mutex_lock(&ar
->conf_mutex
);
934 ar
->debug
.htt_stats_mask
= mask
;
936 ret
= ath10k_debug_htt_stats_req(ar
);
943 mutex_unlock(&ar
->conf_mutex
);
948 static const struct file_operations fops_htt_stats_mask
= {
949 .read
= ath10k_read_htt_stats_mask
,
950 .write
= ath10k_write_htt_stats_mask
,
952 .owner
= THIS_MODULE
,
953 .llseek
= default_llseek
,
956 static ssize_t
ath10k_read_htt_max_amsdu_ampdu(struct file
*file
,
957 char __user
*user_buf
,
958 size_t count
, loff_t
*ppos
)
960 struct ath10k
*ar
= file
->private_data
;
965 mutex_lock(&ar
->conf_mutex
);
967 amsdu
= ar
->htt
.max_num_amsdu
;
968 ampdu
= ar
->htt
.max_num_ampdu
;
969 mutex_unlock(&ar
->conf_mutex
);
971 len
= scnprintf(buf
, sizeof(buf
), "%u %u\n", amsdu
, ampdu
);
973 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
976 static ssize_t
ath10k_write_htt_max_amsdu_ampdu(struct file
*file
,
977 const char __user
*user_buf
,
978 size_t count
, loff_t
*ppos
)
980 struct ath10k
*ar
= file
->private_data
;
983 unsigned int amsdu
, ampdu
;
985 res
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
990 res
= sscanf(buf
, "%u %u", &amsdu
, &du
);
995 mutex_lock(&ar
->conf_mutex
);
997 res
= ath10k_htt_h2t_aggr_cfg_msg(&ar
->htt
, ampdu
, amsdu
);
1002 ar
->htt
.max_num_amsdu
= amsdu
;
1003 ar
->htt
.max_num_ampdu
= ampdu
;
1006 mutex_unlock(&ar
->conf_mutex
);
1010 static const struct file_operations fops_htt_max_amsdu_ampdu
= {
1011 .read
= ath10k_read_htt_max_amsdu_ampdu
,
1012 .write
= ath10k_write_htt_max_amsdu_ampdu
,
1013 .open
= simple_open
,
1014 .owner
= THIS_MODULE
,
1015 .llseek
= default_llseek
,
1018 static ssize_t
ath10k_read_fw_dbglog(struct file
*file
,
1019 char __user
*user_buf
,
1020 size_t count
, loff_t
*ppos
)
1022 struct ath10k
*ar
= file
->private_data
;
1026 len
= scnprintf(buf
, sizeof(buf
), "0x%16llx %u\n",
1027 ar
->debug
.fw_dbglog_mask
, ar
->debug
.fw_dbglog_level
);
1029 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1032 static ssize_t
ath10k_write_fw_dbglog(struct file
*file
,
1033 const char __user
*user_buf
,
1034 size_t count
, loff_t
*ppos
)
1036 struct ath10k
*ar
= file
->private_data
;
1039 unsigned int log_level
;
1042 ret
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
1047 ret
= sscanf(buf
, "%llx %u", &mask
, &log_level
);
1053 /* default if user did not specify */
1054 log_level
= ATH10K_DBGLOG_LEVEL_WARN
;
1056 mutex_lock(&ar
->conf_mutex
);
1058 ar
->debug
.fw_dbglog_mask
= mask
;
1059 ar
->debug
.fw_dbglog_level
= log_level
;
1061 if (ar
->state
== ATH10K_STATE_ON
) {
1062 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1063 ar
->debug
.fw_dbglog_level
);
1065 ath10k_warn(ar
, "dbglog cfg failed from debugfs: %d\n",
1074 mutex_unlock(&ar
->conf_mutex
);
1079 /* TODO: Would be nice to always support ethtool stats, would need to
1080 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1081 * struct available..
1084 /* This generally cooresponds to the debugfs fw_stats file */
1085 static const char ath10k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1095 "d_tx_power", /* in .5 dbM I think */
1096 "d_rx_crc_err", /* fcs_bad */
1097 "d_rx_crc_err_drop", /* frame with FCS error, dropped late in kernel */
1099 "d_tx_mpdus_queued",
1101 "d_tx_msdu_dropped",
1104 "d_tx_ppdu_hw_queued",
1106 "d_tx_fifo_underrun",
1109 "d_tx_excessive_retries",
1111 "d_tx_dropped_sw_retries",
1112 "d_tx_illegal_rate",
1113 "d_tx_continuous_xretries",
1115 "d_tx_mpdu_txop_limit",
1117 "d_rx_mid_ppdu_route_change",
1119 "d_rx_extra_frags_ring0",
1120 "d_rx_extra_frags_ring1",
1121 "d_rx_extra_frags_ring2",
1122 "d_rx_extra_frags_ring3",
1128 "d_rx_phy_err_drops",
1129 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1131 "d_fw_warm_reset_count",
1132 "d_fw_cold_reset_count",
1135 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1137 void ath10k_debug_get_et_strings(struct ieee80211_hw
*hw
,
1138 struct ieee80211_vif
*vif
,
1141 if (sset
== ETH_SS_STATS
)
1142 memcpy(data
, *ath10k_gstrings_stats
,
1143 sizeof(ath10k_gstrings_stats
));
1146 int ath10k_debug_get_et_sset_count(struct ieee80211_hw
*hw
,
1147 struct ieee80211_vif
*vif
, int sset
)
1149 if (sset
== ETH_SS_STATS
)
1150 return ATH10K_SSTATS_LEN
;
1155 void ath10k_debug_get_et_stats(struct ieee80211_hw
*hw
,
1156 struct ieee80211_vif
*vif
,
1157 struct ethtool_stats
*stats
, u64
*data
)
1159 struct ath10k
*ar
= hw
->priv
;
1160 static const struct ath10k_fw_stats_pdev zero_stats
= {};
1161 const struct ath10k_fw_stats_pdev
*pdev_stats
;
1164 mutex_lock(&ar
->conf_mutex
);
1166 if (ar
->state
== ATH10K_STATE_ON
) {
1167 ret
= ath10k_debug_fw_stats_request(ar
);
1169 /* just print a warning and try to use older results */
1171 "failed to get fw stats for ethtool: %d\n",
1176 pdev_stats
= list_first_entry_or_null(&ar
->debug
.fw_stats
.pdevs
,
1177 struct ath10k_fw_stats_pdev
,
1180 /* no results available so just return zeroes */
1181 pdev_stats
= &zero_stats
;
1184 spin_lock_bh(&ar
->data_lock
);
1186 data
[i
++] = pdev_stats
->hw_reaped
; /* ppdu reaped */
1187 data
[i
++] = 0; /* tx bytes */
1188 data
[i
++] = pdev_stats
->htt_mpdus
;
1189 data
[i
++] = 0; /* rx bytes */
1190 data
[i
++] = pdev_stats
->ch_noise_floor
;
1191 data
[i
++] = pdev_stats
->cycle_count
;
1192 data
[i
++] = pdev_stats
->phy_err_count
;
1193 data
[i
++] = pdev_stats
->rts_bad
;
1194 data
[i
++] = pdev_stats
->rts_good
;
1195 data
[i
++] = pdev_stats
->chan_tx_power
;
1196 data
[i
++] = pdev_stats
->fcs_bad
;
1197 data
[i
++] = ar
->stats
.rx_crc_err_drop
;
1198 data
[i
++] = pdev_stats
->no_beacons
;
1199 data
[i
++] = pdev_stats
->mpdu_enqued
;
1200 data
[i
++] = pdev_stats
->msdu_enqued
;
1201 data
[i
++] = pdev_stats
->wmm_drop
;
1202 data
[i
++] = pdev_stats
->local_enqued
;
1203 data
[i
++] = pdev_stats
->local_freed
;
1204 data
[i
++] = pdev_stats
->hw_queued
;
1205 data
[i
++] = pdev_stats
->hw_reaped
;
1206 data
[i
++] = pdev_stats
->underrun
;
1207 data
[i
++] = pdev_stats
->tx_abort
;
1208 data
[i
++] = pdev_stats
->mpdus_requed
;
1209 data
[i
++] = pdev_stats
->tx_ko
;
1210 data
[i
++] = pdev_stats
->data_rc
;
1211 data
[i
++] = pdev_stats
->sw_retry_failure
;
1212 data
[i
++] = pdev_stats
->illgl_rate_phy_err
;
1213 data
[i
++] = pdev_stats
->pdev_cont_xretry
;
1214 data
[i
++] = pdev_stats
->pdev_tx_timeout
;
1215 data
[i
++] = pdev_stats
->txop_ovf
;
1216 data
[i
++] = pdev_stats
->pdev_resets
;
1217 data
[i
++] = pdev_stats
->mid_ppdu_route_change
;
1218 data
[i
++] = pdev_stats
->status_rcvd
;
1219 data
[i
++] = pdev_stats
->r0_frags
;
1220 data
[i
++] = pdev_stats
->r1_frags
;
1221 data
[i
++] = pdev_stats
->r2_frags
;
1222 data
[i
++] = pdev_stats
->r3_frags
;
1223 data
[i
++] = pdev_stats
->htt_msdus
;
1224 data
[i
++] = pdev_stats
->htt_mpdus
;
1225 data
[i
++] = pdev_stats
->loc_msdus
;
1226 data
[i
++] = pdev_stats
->loc_mpdus
;
1227 data
[i
++] = pdev_stats
->phy_errs
;
1228 data
[i
++] = pdev_stats
->phy_err_drop
;
1229 data
[i
++] = pdev_stats
->mpdu_errs
;
1230 data
[i
++] = ar
->stats
.fw_crash_counter
;
1231 data
[i
++] = ar
->stats
.fw_warm_reset_counter
;
1232 data
[i
++] = ar
->stats
.fw_cold_reset_counter
;
1234 spin_unlock_bh(&ar
->data_lock
);
1236 mutex_unlock(&ar
->conf_mutex
);
1238 WARN_ON(i
!= ATH10K_SSTATS_LEN
);
1241 static const struct file_operations fops_fw_dbglog
= {
1242 .read
= ath10k_read_fw_dbglog
,
1243 .write
= ath10k_write_fw_dbglog
,
1244 .open
= simple_open
,
1245 .owner
= THIS_MODULE
,
1246 .llseek
= default_llseek
,
1249 static int ath10k_debug_cal_data_fetch(struct ath10k
*ar
)
1255 lockdep_assert_held(&ar
->conf_mutex
);
1257 if (WARN_ON(ar
->hw_params
.cal_data_len
> ATH10K_DEBUG_CAL_DATA_LEN
))
1260 if (ar
->hw_params
.cal_data_len
== 0)
1263 hi_addr
= host_interest_item_address(HI_ITEM(hi_board_data
));
1265 ret
= ath10k_hif_diag_read(ar
, hi_addr
, &addr
, sizeof(addr
));
1267 ath10k_warn(ar
, "failed to read hi_board_data address: %d\n",
1272 ret
= ath10k_hif_diag_read(ar
, le32_to_cpu(addr
), ar
->debug
.cal_data
,
1273 ar
->hw_params
.cal_data_len
);
1275 ath10k_warn(ar
, "failed to read calibration data: %d\n", ret
);
1282 static int ath10k_debug_cal_data_open(struct inode
*inode
, struct file
*file
)
1284 struct ath10k
*ar
= inode
->i_private
;
1286 mutex_lock(&ar
->conf_mutex
);
1288 if (ar
->state
== ATH10K_STATE_ON
||
1289 ar
->state
== ATH10K_STATE_UTF
) {
1290 ath10k_debug_cal_data_fetch(ar
);
1293 file
->private_data
= ar
;
1294 mutex_unlock(&ar
->conf_mutex
);
1299 static ssize_t
ath10k_debug_cal_data_read(struct file
*file
,
1300 char __user
*user_buf
,
1301 size_t count
, loff_t
*ppos
)
1303 struct ath10k
*ar
= file
->private_data
;
1305 mutex_lock(&ar
->conf_mutex
);
1307 count
= simple_read_from_buffer(user_buf
, count
, ppos
,
1309 ar
->hw_params
.cal_data_len
);
1311 mutex_unlock(&ar
->conf_mutex
);
1316 static ssize_t
ath10k_write_ani_enable(struct file
*file
,
1317 const char __user
*user_buf
,
1318 size_t count
, loff_t
*ppos
)
1320 struct ath10k
*ar
= file
->private_data
;
1324 if (kstrtou8_from_user(user_buf
, count
, 0, &enable
))
1327 mutex_lock(&ar
->conf_mutex
);
1329 if (ar
->ani_enabled
== enable
) {
1334 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->ani_enable
,
1337 ath10k_warn(ar
, "ani_enable failed from debugfs: %d\n", ret
);
1340 ar
->ani_enabled
= enable
;
1345 mutex_unlock(&ar
->conf_mutex
);
1350 static ssize_t
ath10k_read_ani_enable(struct file
*file
, char __user
*user_buf
,
1351 size_t count
, loff_t
*ppos
)
1353 struct ath10k
*ar
= file
->private_data
;
1357 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->ani_enabled
);
1359 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1362 static const struct file_operations fops_ani_enable
= {
1363 .read
= ath10k_read_ani_enable
,
1364 .write
= ath10k_write_ani_enable
,
1365 .open
= simple_open
,
1366 .owner
= THIS_MODULE
,
1367 .llseek
= default_llseek
,
1370 static const struct file_operations fops_cal_data
= {
1371 .open
= ath10k_debug_cal_data_open
,
1372 .read
= ath10k_debug_cal_data_read
,
1373 .owner
= THIS_MODULE
,
1374 .llseek
= default_llseek
,
1377 static ssize_t
ath10k_read_nf_cal_period(struct file
*file
,
1378 char __user
*user_buf
,
1379 size_t count
, loff_t
*ppos
)
1381 struct ath10k
*ar
= file
->private_data
;
1385 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->debug
.nf_cal_period
);
1387 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1390 static ssize_t
ath10k_write_nf_cal_period(struct file
*file
,
1391 const char __user
*user_buf
,
1392 size_t count
, loff_t
*ppos
)
1394 struct ath10k
*ar
= file
->private_data
;
1395 unsigned long period
;
1398 ret
= kstrtoul_from_user(user_buf
, count
, 0, &period
);
1402 if (period
> WMI_PDEV_PARAM_CAL_PERIOD_MAX
)
1405 /* there's no way to switch back to the firmware default */
1409 mutex_lock(&ar
->conf_mutex
);
1411 ar
->debug
.nf_cal_period
= period
;
1413 if (ar
->state
!= ATH10K_STATE_ON
) {
1414 /* firmware is not running, nothing else to do */
1419 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->cal_period
,
1420 ar
->debug
.nf_cal_period
);
1422 ath10k_warn(ar
, "cal period cfg failed from debugfs: %d\n",
1430 mutex_unlock(&ar
->conf_mutex
);
1435 static const struct file_operations fops_nf_cal_period
= {
1436 .read
= ath10k_read_nf_cal_period
,
1437 .write
= ath10k_write_nf_cal_period
,
1438 .open
= simple_open
,
1439 .owner
= THIS_MODULE
,
1440 .llseek
= default_llseek
,
1443 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1445 static int ath10k_debug_tpc_stats_request(struct ath10k
*ar
)
1448 unsigned long time_left
;
1450 lockdep_assert_held(&ar
->conf_mutex
);
1452 reinit_completion(&ar
->debug
.tpc_complete
);
1454 ret
= ath10k_wmi_pdev_get_tpc_config(ar
, WMI_TPC_CONFIG_PARAM
);
1456 ath10k_warn(ar
, "failed to request tpc config: %d\n", ret
);
1460 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
1468 void ath10k_debug_tpc_stats_process(struct ath10k
*ar
,
1469 struct ath10k_tpc_stats
*tpc_stats
)
1471 spin_lock_bh(&ar
->data_lock
);
1473 kfree(ar
->debug
.tpc_stats
);
1474 ar
->debug
.tpc_stats
= tpc_stats
;
1475 complete(&ar
->debug
.tpc_complete
);
1477 spin_unlock_bh(&ar
->data_lock
);
1481 ath10k_debug_tpc_stats_final_process(struct ath10k
*ar
,
1482 struct ath10k_tpc_stats_final
*tpc_stats
)
1484 spin_lock_bh(&ar
->data_lock
);
1486 kfree(ar
->debug
.tpc_stats_final
);
1487 ar
->debug
.tpc_stats_final
= tpc_stats
;
1488 complete(&ar
->debug
.tpc_complete
);
1490 spin_unlock_bh(&ar
->data_lock
);
1493 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats
*tpc_stats
,
1494 unsigned int j
, char *buf
, size_t *len
)
1498 static const char table_str
[][5] = { "CDD",
1501 static const char pream_str
[][6] = { "CCK",
1510 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1511 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1512 "********************************\n");
1513 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1514 "******************* %s POWER TABLE ****************\n",
1516 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1517 "********************************\n");
1518 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1519 "No. Preamble Rate_code ");
1521 for (i
= 0; i
< tpc_stats
->num_tx_chain
; i
++)
1522 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1525 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
, "\n");
1527 for (i
= 0; i
< tpc_stats
->rate_max
; i
++) {
1528 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1529 "%8d %s 0x%2x %s\n", i
,
1530 pream_str
[tpc_stats
->tpc_table
[j
].pream_idx
[i
]],
1531 tpc_stats
->tpc_table
[j
].rate_code
[i
],
1532 tpc_stats
->tpc_table
[j
].tpc_value
[i
]);
1535 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1536 "***********************************\n");
1539 static void ath10k_tpc_stats_fill(struct ath10k
*ar
,
1540 struct ath10k_tpc_stats
*tpc_stats
,
1544 size_t len
, buf_len
;
1547 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1549 spin_lock_bh(&ar
->data_lock
);
1552 ath10k_warn(ar
, "failed to get tpc stats\n");
1556 len
+= scnprintf(buf
+ len
, buf_len
- len
, "\n");
1557 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1558 "*************************************\n");
1559 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1560 "TPC config for channel %4d mode %d\n",
1561 tpc_stats
->chan_freq
,
1562 tpc_stats
->phy_mode
);
1563 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1564 "*************************************\n");
1565 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1566 "CTL = 0x%2x Reg. Domain = %2d\n",
1568 tpc_stats
->reg_domain
);
1569 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1570 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1571 tpc_stats
->twice_antenna_gain
,
1572 tpc_stats
->twice_antenna_reduction
);
1573 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1574 "Power Limit = %2d Reg. Max Power = %2d\n",
1575 tpc_stats
->power_limit
,
1576 tpc_stats
->twice_max_rd_power
/ 2);
1577 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1578 "Num tx chains = %2d Num supported rates = %2d\n",
1579 tpc_stats
->num_tx_chain
,
1580 tpc_stats
->rate_max
);
1582 for (j
= 0; j
< WMI_TPC_FLAG
; j
++) {
1584 case WMI_TPC_TABLE_TYPE_CDD
:
1585 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1586 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1587 "CDD not supported\n");
1591 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1593 case WMI_TPC_TABLE_TYPE_STBC
:
1594 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1595 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1596 "STBC not supported\n");
1600 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1602 case WMI_TPC_TABLE_TYPE_TXBF
:
1603 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1604 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1605 "TXBF not supported\n***************************\n");
1609 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1612 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1619 spin_unlock_bh(&ar
->data_lock
);
1627 static int ath10k_tpc_stats_open(struct inode
*inode
, struct file
*file
)
1629 struct ath10k
*ar
= inode
->i_private
;
1633 mutex_lock(&ar
->conf_mutex
);
1635 if (ar
->state
!= ATH10K_STATE_ON
) {
1640 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
1646 ret
= ath10k_debug_tpc_stats_request(ar
);
1648 ath10k_warn(ar
, "failed to request tpc config stats: %d\n",
1653 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
1654 file
->private_data
= buf
;
1656 mutex_unlock(&ar
->conf_mutex
);
1663 mutex_unlock(&ar
->conf_mutex
);
1667 static int ath10k_tpc_stats_release(struct inode
*inode
, struct file
*file
)
1669 vfree(file
->private_data
);
1674 static ssize_t
ath10k_tpc_stats_read(struct file
*file
, char __user
*user_buf
,
1675 size_t count
, loff_t
*ppos
)
1677 const char *buf
= file
->private_data
;
1678 size_t len
= strlen(buf
);
1680 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1683 static const struct file_operations fops_tpc_stats
= {
1684 .open
= ath10k_tpc_stats_open
,
1685 .release
= ath10k_tpc_stats_release
,
1686 .read
= ath10k_tpc_stats_read
,
1687 .owner
= THIS_MODULE
,
1688 .llseek
= default_llseek
,
1691 int ath10k_debug_start(struct ath10k
*ar
)
1695 lockdep_assert_held(&ar
->conf_mutex
);
1697 ret
= ath10k_debug_htt_stats_req(ar
);
1699 /* continue normally anyway, this isn't serious */
1700 ath10k_warn(ar
, "failed to start htt stats workqueue: %d\n",
1703 if (ar
->debug
.fw_dbglog_mask
) {
1704 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1705 ATH10K_DBGLOG_LEVEL_WARN
);
1708 ath10k_warn(ar
, "failed to enable dbglog during start: %d",
1712 if (ar
->pktlog_filter
) {
1713 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
1718 "failed to enable pktlog filter %x: %d\n",
1719 ar
->pktlog_filter
, ret
);
1721 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1724 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1727 if (ar
->debug
.nf_cal_period
&&
1728 !test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1729 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
1730 ret
= ath10k_wmi_pdev_set_param(ar
,
1731 ar
->wmi
.pdev_param
->cal_period
,
1732 ar
->debug
.nf_cal_period
);
1735 ath10k_warn(ar
, "cal period cfg failed from debug start: %d\n",
1742 void ath10k_debug_stop(struct ath10k
*ar
)
1744 lockdep_assert_held(&ar
->conf_mutex
);
1746 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1747 ar
->normal_mode_fw
.fw_file
.fw_features
))
1748 ath10k_debug_cal_data_fetch(ar
);
1750 /* Must not use _sync to avoid deadlock, we do that in
1751 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1752 * warning from del_timer().
1754 if (ar
->debug
.htt_stats_mask
!= 0)
1755 cancel_delayed_work(&ar
->debug
.htt_stats_dwork
);
1757 ath10k_wmi_pdev_pktlog_disable(ar
);
1760 static ssize_t
ath10k_write_simulate_radar(struct file
*file
,
1761 const char __user
*user_buf
,
1762 size_t count
, loff_t
*ppos
)
1764 struct ath10k
*ar
= file
->private_data
;
1765 struct ath10k_vif
*arvif
;
1767 /* Just check for the first vif alone, as all the vifs will be
1768 * sharing the same channel and if the channel is disabled, all the
1769 * vifs will share the same 'is_started' state.
1771 arvif
= list_first_entry(&ar
->arvifs
, typeof(*arvif
), list
);
1772 if (!arvif
->is_started
)
1775 ieee80211_radar_detected(ar
->hw
);
1780 static const struct file_operations fops_simulate_radar
= {
1781 .write
= ath10k_write_simulate_radar
,
1782 .open
= simple_open
,
1783 .owner
= THIS_MODULE
,
1784 .llseek
= default_llseek
,
1787 #define ATH10K_DFS_STAT(s, p) (\
1788 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1789 ar->debug.dfs_stats.p))
1791 #define ATH10K_DFS_POOL_STAT(s, p) (\
1792 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1793 ar->debug.dfs_pool_stats.p))
1795 static ssize_t
ath10k_read_dfs_stats(struct file
*file
, char __user
*user_buf
,
1796 size_t count
, loff_t
*ppos
)
1798 int retval
= 0, len
= 0;
1799 const int size
= 8000;
1800 struct ath10k
*ar
= file
->private_data
;
1803 buf
= kzalloc(size
, GFP_KERNEL
);
1807 if (!ar
->dfs_detector
) {
1808 len
+= scnprintf(buf
+ len
, size
- len
, "DFS not enabled\n");
1812 ar
->debug
.dfs_pool_stats
=
1813 ar
->dfs_detector
->get_stats(ar
->dfs_detector
);
1815 len
+= scnprintf(buf
+ len
, size
- len
, "Pulse detector statistics:\n");
1817 ATH10K_DFS_STAT("reported phy errors", phy_errors
);
1818 ATH10K_DFS_STAT("pulse events reported", pulses_total
);
1819 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected
);
1820 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded
);
1821 ATH10K_DFS_STAT("Radars detected", radar_detected
);
1823 len
+= scnprintf(buf
+ len
, size
- len
, "Global Pool statistics:\n");
1824 ATH10K_DFS_POOL_STAT("Pool references", pool_reference
);
1825 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated
);
1826 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error
);
1827 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used
);
1828 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated
);
1829 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error
);
1830 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used
);
1836 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1842 static const struct file_operations fops_dfs_stats
= {
1843 .read
= ath10k_read_dfs_stats
,
1844 .open
= simple_open
,
1845 .owner
= THIS_MODULE
,
1846 .llseek
= default_llseek
,
1849 static ssize_t
ath10k_write_pktlog_filter(struct file
*file
,
1850 const char __user
*ubuf
,
1851 size_t count
, loff_t
*ppos
)
1853 struct ath10k
*ar
= file
->private_data
;
1857 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
1860 mutex_lock(&ar
->conf_mutex
);
1862 if (ar
->state
!= ATH10K_STATE_ON
) {
1863 ar
->pktlog_filter
= filter
;
1868 if (filter
== ar
->pktlog_filter
) {
1874 ret
= ath10k_wmi_pdev_pktlog_enable(ar
, filter
);
1876 ath10k_warn(ar
, "failed to enable pktlog filter %x: %d\n",
1877 ar
->pktlog_filter
, ret
);
1881 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1883 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1888 ar
->pktlog_filter
= filter
;
1892 mutex_unlock(&ar
->conf_mutex
);
1896 static ssize_t
ath10k_read_pktlog_filter(struct file
*file
, char __user
*ubuf
,
1897 size_t count
, loff_t
*ppos
)
1900 struct ath10k
*ar
= file
->private_data
;
1903 mutex_lock(&ar
->conf_mutex
);
1904 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
1906 mutex_unlock(&ar
->conf_mutex
);
1908 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1911 static const struct file_operations fops_pktlog_filter
= {
1912 .read
= ath10k_read_pktlog_filter
,
1913 .write
= ath10k_write_pktlog_filter
,
1917 static ssize_t
ath10k_write_quiet_period(struct file
*file
,
1918 const char __user
*ubuf
,
1919 size_t count
, loff_t
*ppos
)
1921 struct ath10k
*ar
= file
->private_data
;
1924 if (kstrtouint_from_user(ubuf
, count
, 0, &period
))
1927 if (period
< ATH10K_QUIET_PERIOD_MIN
) {
1928 ath10k_warn(ar
, "Quiet period %u can not be lesser than 25ms\n",
1932 mutex_lock(&ar
->conf_mutex
);
1933 ar
->thermal
.quiet_period
= period
;
1934 ath10k_thermal_set_throttling(ar
);
1935 mutex_unlock(&ar
->conf_mutex
);
1940 static ssize_t
ath10k_read_quiet_period(struct file
*file
, char __user
*ubuf
,
1941 size_t count
, loff_t
*ppos
)
1944 struct ath10k
*ar
= file
->private_data
;
1947 mutex_lock(&ar
->conf_mutex
);
1948 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
1949 ar
->thermal
.quiet_period
);
1950 mutex_unlock(&ar
->conf_mutex
);
1952 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1955 static const struct file_operations fops_quiet_period
= {
1956 .read
= ath10k_read_quiet_period
,
1957 .write
= ath10k_write_quiet_period
,
1961 static ssize_t
ath10k_write_btcoex(struct file
*file
,
1962 const char __user
*ubuf
,
1963 size_t count
, loff_t
*ppos
)
1965 struct ath10k
*ar
= file
->private_data
;
1972 buf_size
= min(count
, (sizeof(buf
) - 1));
1973 if (copy_from_user(buf
, ubuf
, buf_size
))
1976 buf
[buf_size
] = '\0';
1978 if (strtobool(buf
, &val
) != 0)
1981 if (!ar
->coex_support
)
1984 mutex_lock(&ar
->conf_mutex
);
1986 if (ar
->state
!= ATH10K_STATE_ON
&&
1987 ar
->state
!= ATH10K_STATE_RESTARTED
) {
1992 if (!(test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
) ^ val
)) {
1997 pdev_param
= ar
->wmi
.pdev_param
->enable_btcoex
;
1998 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
1999 ar
->running_fw
->fw_file
.fw_features
)) {
2000 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
, val
);
2002 ath10k_warn(ar
, "failed to enable btcoex: %d\n", ret
);
2007 ath10k_info(ar
, "restarting firmware due to btcoex change");
2008 ath10k_core_start_recovery(ar
);
2012 set_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2014 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2019 mutex_unlock(&ar
->conf_mutex
);
2024 static ssize_t
ath10k_read_btcoex(struct file
*file
, char __user
*ubuf
,
2025 size_t count
, loff_t
*ppos
)
2028 struct ath10k
*ar
= file
->private_data
;
2031 mutex_lock(&ar
->conf_mutex
);
2032 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2033 test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
));
2034 mutex_unlock(&ar
->conf_mutex
);
2036 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2039 static const struct file_operations fops_btcoex
= {
2040 .read
= ath10k_read_btcoex
,
2041 .write
= ath10k_write_btcoex
,
2045 static ssize_t
ath10k_write_enable_extd_tx_stats(struct file
*file
,
2046 const char __user
*ubuf
,
2047 size_t count
, loff_t
*ppos
)
2049 struct ath10k
*ar
= file
->private_data
;
2053 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
2056 mutex_lock(&ar
->conf_mutex
);
2058 if (ar
->state
!= ATH10K_STATE_ON
) {
2059 ar
->debug
.enable_extd_tx_stats
= filter
;
2064 if (filter
== ar
->debug
.enable_extd_tx_stats
) {
2069 ar
->debug
.enable_extd_tx_stats
= filter
;
2073 mutex_unlock(&ar
->conf_mutex
);
2077 static ssize_t
ath10k_read_enable_extd_tx_stats(struct file
*file
,
2079 size_t count
, loff_t
*ppos
)
2083 struct ath10k
*ar
= file
->private_data
;
2086 mutex_lock(&ar
->conf_mutex
);
2087 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
2088 ar
->debug
.enable_extd_tx_stats
);
2089 mutex_unlock(&ar
->conf_mutex
);
2091 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2094 static const struct file_operations fops_enable_extd_tx_stats
= {
2095 .read
= ath10k_read_enable_extd_tx_stats
,
2096 .write
= ath10k_write_enable_extd_tx_stats
,
2100 static ssize_t
ath10k_write_peer_stats(struct file
*file
,
2101 const char __user
*ubuf
,
2102 size_t count
, loff_t
*ppos
)
2104 struct ath10k
*ar
= file
->private_data
;
2110 buf_size
= min(count
, (sizeof(buf
) - 1));
2111 if (copy_from_user(buf
, ubuf
, buf_size
))
2114 buf
[buf_size
] = '\0';
2116 if (strtobool(buf
, &val
) != 0)
2119 mutex_lock(&ar
->conf_mutex
);
2121 if (ar
->state
!= ATH10K_STATE_ON
&&
2122 ar
->state
!= ATH10K_STATE_RESTARTED
) {
2127 if (!(test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
) ^ val
)) {
2133 set_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2135 clear_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2137 ath10k_info(ar
, "restarting firmware due to Peer stats change");
2139 ath10k_core_start_recovery(ar
);
2143 mutex_unlock(&ar
->conf_mutex
);
2147 static ssize_t
ath10k_read_peer_stats(struct file
*file
, char __user
*ubuf
,
2148 size_t count
, loff_t
*ppos
)
2152 struct ath10k
*ar
= file
->private_data
;
2155 mutex_lock(&ar
->conf_mutex
);
2156 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2157 test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
));
2158 mutex_unlock(&ar
->conf_mutex
);
2160 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2163 static const struct file_operations fops_peer_stats
= {
2164 .read
= ath10k_read_peer_stats
,
2165 .write
= ath10k_write_peer_stats
,
2169 static ssize_t
ath10k_debug_fw_checksums_read(struct file
*file
,
2170 char __user
*user_buf
,
2171 size_t count
, loff_t
*ppos
)
2173 struct ath10k
*ar
= file
->private_data
;
2174 size_t len
= 0, buf_len
= 4096;
2178 buf
= kzalloc(buf_len
, GFP_KERNEL
);
2182 mutex_lock(&ar
->conf_mutex
);
2184 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2185 "firmware-N.bin\t\t%08x\n",
2186 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware
->data
,
2187 ar
->normal_mode_fw
.fw_file
.firmware
->size
));
2188 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2189 "athwlan\t\t\t%08x\n",
2190 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware_data
,
2191 ar
->normal_mode_fw
.fw_file
.firmware_len
));
2192 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2194 crc32_le(0, ar
->normal_mode_fw
.fw_file
.otp_data
,
2195 ar
->normal_mode_fw
.fw_file
.otp_len
));
2196 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2197 "codeswap\t\t%08x\n",
2198 crc32_le(0, ar
->normal_mode_fw
.fw_file
.codeswap_data
,
2199 ar
->normal_mode_fw
.fw_file
.codeswap_len
));
2200 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2201 "board-N.bin\t\t%08x\n",
2202 crc32_le(0, ar
->normal_mode_fw
.board
->data
,
2203 ar
->normal_mode_fw
.board
->size
));
2204 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2205 "board\t\t\t%08x\n",
2206 crc32_le(0, ar
->normal_mode_fw
.board_data
,
2207 ar
->normal_mode_fw
.board_len
));
2209 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2211 mutex_unlock(&ar
->conf_mutex
);
2217 static const struct file_operations fops_fw_checksums
= {
2218 .read
= ath10k_debug_fw_checksums_read
,
2219 .open
= simple_open
,
2220 .owner
= THIS_MODULE
,
2221 .llseek
= default_llseek
,
2224 static ssize_t
ath10k_sta_tid_stats_mask_read(struct file
*file
,
2225 char __user
*user_buf
,
2226 size_t count
, loff_t
*ppos
)
2228 struct ath10k
*ar
= file
->private_data
;
2232 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->sta_tid_stats_mask
);
2233 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2236 static ssize_t
ath10k_sta_tid_stats_mask_write(struct file
*file
,
2237 const char __user
*user_buf
,
2238 size_t count
, loff_t
*ppos
)
2240 struct ath10k
*ar
= file
->private_data
;
2245 len
= min(count
, sizeof(buf
) - 1);
2246 if (copy_from_user(buf
, user_buf
, len
))
2250 if (kstrtoint(buf
, 0, &mask
))
2253 ar
->sta_tid_stats_mask
= mask
;
2258 static const struct file_operations fops_sta_tid_stats_mask
= {
2259 .read
= ath10k_sta_tid_stats_mask_read
,
2260 .write
= ath10k_sta_tid_stats_mask_write
,
2261 .open
= simple_open
,
2262 .owner
= THIS_MODULE
,
2263 .llseek
= default_llseek
,
2266 static int ath10k_debug_tpc_stats_final_request(struct ath10k
*ar
)
2269 unsigned long time_left
;
2271 lockdep_assert_held(&ar
->conf_mutex
);
2273 reinit_completion(&ar
->debug
.tpc_complete
);
2275 ret
= ath10k_wmi_pdev_get_tpc_table_cmdid(ar
, WMI_TPC_CONFIG_PARAM
);
2277 ath10k_warn(ar
, "failed to request tpc table cmdid: %d\n", ret
);
2281 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
2289 static int ath10k_tpc_stats_final_open(struct inode
*inode
, struct file
*file
)
2291 struct ath10k
*ar
= inode
->i_private
;
2295 mutex_lock(&ar
->conf_mutex
);
2297 if (ar
->state
!= ATH10K_STATE_ON
) {
2302 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
2308 ret
= ath10k_debug_tpc_stats_final_request(ar
);
2310 ath10k_warn(ar
, "failed to request tpc stats final: %d\n",
2315 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
2316 file
->private_data
= buf
;
2318 mutex_unlock(&ar
->conf_mutex
);
2325 mutex_unlock(&ar
->conf_mutex
);
2329 static int ath10k_tpc_stats_final_release(struct inode
*inode
,
2332 vfree(file
->private_data
);
2337 static ssize_t
ath10k_tpc_stats_final_read(struct file
*file
,
2338 char __user
*user_buf
,
2339 size_t count
, loff_t
*ppos
)
2341 const char *buf
= file
->private_data
;
2342 unsigned int len
= strlen(buf
);
2344 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2347 static const struct file_operations fops_tpc_stats_final
= {
2348 .open
= ath10k_tpc_stats_final_open
,
2349 .release
= ath10k_tpc_stats_final_release
,
2350 .read
= ath10k_tpc_stats_final_read
,
2351 .owner
= THIS_MODULE
,
2352 .llseek
= default_llseek
,
2355 static ssize_t
ath10k_write_warm_hw_reset(struct file
*file
,
2356 const char __user
*user_buf
,
2357 size_t count
, loff_t
*ppos
)
2359 struct ath10k
*ar
= file
->private_data
;
2363 if (kstrtobool_from_user(user_buf
, count
, &val
))
2369 mutex_lock(&ar
->conf_mutex
);
2371 if (ar
->state
!= ATH10K_STATE_ON
) {
2376 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pdev_reset
,
2377 WMI_RST_MODE_WARM_RESET
);
2380 ath10k_warn(ar
, "failed to enable warm hw reset: %d\n", ret
);
2387 mutex_unlock(&ar
->conf_mutex
);
2391 static const struct file_operations fops_warm_hw_reset
= {
2392 .write
= ath10k_write_warm_hw_reset
,
2393 .open
= simple_open
,
2394 .owner
= THIS_MODULE
,
2395 .llseek
= default_llseek
,
2398 static void ath10k_peer_ps_state_disable(void *data
,
2399 struct ieee80211_sta
*sta
)
2401 struct ath10k
*ar
= data
;
2402 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
2404 spin_lock_bh(&ar
->data_lock
);
2405 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
2406 spin_unlock_bh(&ar
->data_lock
);
2409 static ssize_t
ath10k_write_ps_state_enable(struct file
*file
,
2410 const char __user
*user_buf
,
2411 size_t count
, loff_t
*ppos
)
2413 struct ath10k
*ar
= file
->private_data
;
2418 if (kstrtou8_from_user(user_buf
, count
, 0, &ps_state_enable
))
2421 if (ps_state_enable
> 1)
2424 mutex_lock(&ar
->conf_mutex
);
2426 if (ar
->ps_state_enable
== ps_state_enable
) {
2431 param
= ar
->wmi
.pdev_param
->peer_sta_ps_statechg_enable
;
2432 ret
= ath10k_wmi_pdev_set_param(ar
, param
, ps_state_enable
);
2434 ath10k_warn(ar
, "failed to enable ps_state_enable: %d\n",
2438 ar
->ps_state_enable
= ps_state_enable
;
2440 if (!ar
->ps_state_enable
)
2441 ieee80211_iterate_stations_atomic(ar
->hw
,
2442 ath10k_peer_ps_state_disable
,
2448 mutex_unlock(&ar
->conf_mutex
);
2453 static ssize_t
ath10k_read_ps_state_enable(struct file
*file
,
2454 char __user
*user_buf
,
2455 size_t count
, loff_t
*ppos
)
2457 struct ath10k
*ar
= file
->private_data
;
2461 mutex_lock(&ar
->conf_mutex
);
2462 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2463 ar
->ps_state_enable
);
2464 mutex_unlock(&ar
->conf_mutex
);
2466 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2469 static const struct file_operations fops_ps_state_enable
= {
2470 .read
= ath10k_read_ps_state_enable
,
2471 .write
= ath10k_write_ps_state_enable
,
2472 .open
= simple_open
,
2473 .owner
= THIS_MODULE
,
2474 .llseek
= default_llseek
,
2477 static ssize_t
ath10k_write_reset_htt_stats(struct file
*file
,
2478 const char __user
*user_buf
,
2479 size_t count
, loff_t
*ppos
)
2481 struct ath10k
*ar
= file
->private_data
;
2482 unsigned long reset
;
2485 ret
= kstrtoul_from_user(user_buf
, count
, 0, &reset
);
2489 if (reset
== 0 || reset
> 0x1ffff)
2492 mutex_lock(&ar
->conf_mutex
);
2494 ar
->debug
.reset_htt_stats
= reset
;
2496 ret
= ath10k_debug_htt_stats_req(ar
);
2500 ar
->debug
.reset_htt_stats
= 0;
2504 mutex_unlock(&ar
->conf_mutex
);
2508 static const struct file_operations fops_reset_htt_stats
= {
2509 .write
= ath10k_write_reset_htt_stats
,
2510 .owner
= THIS_MODULE
,
2511 .open
= simple_open
,
2512 .llseek
= default_llseek
,
2515 int ath10k_debug_create(struct ath10k
*ar
)
2517 ar
->debug
.cal_data
= vzalloc(ATH10K_DEBUG_CAL_DATA_LEN
);
2518 if (!ar
->debug
.cal_data
)
2521 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.pdevs
);
2522 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.vdevs
);
2523 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers
);
2524 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers_extd
);
2529 void ath10k_debug_destroy(struct ath10k
*ar
)
2531 vfree(ar
->debug
.cal_data
);
2532 ar
->debug
.cal_data
= NULL
;
2534 ath10k_debug_fw_stats_reset(ar
);
2536 kfree(ar
->debug
.tpc_stats
);
2537 kfree(ar
->debug
.tpc_stats_final
);
2540 int ath10k_debug_register(struct ath10k
*ar
)
2542 ar
->debug
.debugfs_phy
= debugfs_create_dir("ath10k",
2543 ar
->hw
->wiphy
->debugfsdir
);
2544 if (IS_ERR_OR_NULL(ar
->debug
.debugfs_phy
)) {
2545 if (IS_ERR(ar
->debug
.debugfs_phy
))
2546 return PTR_ERR(ar
->debug
.debugfs_phy
);
2551 INIT_DELAYED_WORK(&ar
->debug
.htt_stats_dwork
,
2552 ath10k_debug_htt_stats_dwork
);
2554 init_completion(&ar
->debug
.tpc_complete
);
2555 init_completion(&ar
->debug
.fw_stats_complete
);
2557 debugfs_create_file("fw_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2560 debugfs_create_file("fw_reset_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2561 &fops_fw_reset_stats
);
2563 debugfs_create_file("wmi_services", 0400, ar
->debug
.debugfs_phy
, ar
,
2564 &fops_wmi_services
);
2566 debugfs_create_file("simulate_fw_crash", 0600, ar
->debug
.debugfs_phy
, ar
,
2567 &fops_simulate_fw_crash
);
2569 debugfs_create_file("reg_addr", 0600, ar
->debug
.debugfs_phy
, ar
,
2572 debugfs_create_file("reg_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2575 debugfs_create_file("mem_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2578 debugfs_create_file("chip_id", 0400, ar
->debug
.debugfs_phy
, ar
,
2581 debugfs_create_file("htt_stats_mask", 0600, ar
->debug
.debugfs_phy
, ar
,
2582 &fops_htt_stats_mask
);
2584 debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar
->debug
.debugfs_phy
, ar
,
2585 &fops_htt_max_amsdu_ampdu
);
2587 debugfs_create_file("fw_dbglog", 0600, ar
->debug
.debugfs_phy
, ar
,
2590 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
2591 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
2592 debugfs_create_file("cal_data", 0400, ar
->debug
.debugfs_phy
, ar
,
2595 debugfs_create_file("nf_cal_period", 0600, ar
->debug
.debugfs_phy
, ar
,
2596 &fops_nf_cal_period
);
2599 debugfs_create_file("ani_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2602 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
2603 debugfs_create_file("dfs_simulate_radar", 0200, ar
->debug
.debugfs_phy
,
2604 ar
, &fops_simulate_radar
);
2606 debugfs_create_bool("dfs_block_radar_events", 0200,
2607 ar
->debug
.debugfs_phy
,
2608 &ar
->dfs_block_radar_events
);
2610 debugfs_create_file("dfs_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2614 debugfs_create_file("pktlog_filter", 0644, ar
->debug
.debugfs_phy
, ar
,
2615 &fops_pktlog_filter
);
2617 if (test_bit(WMI_SERVICE_THERM_THROT
, ar
->wmi
.svc_map
))
2618 debugfs_create_file("quiet_period", 0644, ar
->debug
.debugfs_phy
, ar
,
2619 &fops_quiet_period
);
2621 debugfs_create_file("tpc_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2624 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
))
2625 debugfs_create_file("btcoex", 0644, ar
->debug
.debugfs_phy
, ar
,
2628 if (test_bit(WMI_SERVICE_PEER_STATS
, ar
->wmi
.svc_map
)) {
2629 debugfs_create_file("peer_stats", 0644, ar
->debug
.debugfs_phy
, ar
,
2632 debugfs_create_file("enable_extd_tx_stats", 0644,
2633 ar
->debug
.debugfs_phy
, ar
,
2634 &fops_enable_extd_tx_stats
);
2637 debugfs_create_file("fw_checksums", 0400, ar
->debug
.debugfs_phy
, ar
,
2638 &fops_fw_checksums
);
2640 if (IS_ENABLED(CONFIG_MAC80211_DEBUGFS
))
2641 debugfs_create_file("sta_tid_stats_mask", 0600,
2642 ar
->debug
.debugfs_phy
,
2643 ar
, &fops_sta_tid_stats_mask
);
2645 if (test_bit(WMI_SERVICE_TPC_STATS_FINAL
, ar
->wmi
.svc_map
))
2646 debugfs_create_file("tpc_stats_final", 0400,
2647 ar
->debug
.debugfs_phy
, ar
,
2648 &fops_tpc_stats_final
);
2650 if (test_bit(WMI_SERVICE_RESET_CHIP
, ar
->wmi
.svc_map
))
2651 debugfs_create_file("warm_hw_reset", 0600,
2652 ar
->debug
.debugfs_phy
, ar
,
2653 &fops_warm_hw_reset
);
2655 debugfs_create_file("ps_state_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2656 &fops_ps_state_enable
);
2658 debugfs_create_file("reset_htt_stats", 0200, ar
->debug
.debugfs_phy
, ar
,
2659 &fops_reset_htt_stats
);
2664 void ath10k_debug_unregister(struct ath10k
*ar
)
2666 cancel_delayed_work_sync(&ar
->debug
.htt_stats_dwork
);
2669 #endif /* CONFIG_ATH10K_DEBUGFS */
2671 #ifdef CONFIG_ATH10K_DEBUG
2672 void __ath10k_dbg(struct ath10k
*ar
, enum ath10k_debug_mask mask
,
2673 const char *fmt
, ...)
2675 struct va_format vaf
;
2678 va_start(args
, fmt
);
2683 if (ath10k_debug_mask
& mask
)
2684 dev_printk(KERN_DEBUG
, ar
->dev
, "%pV", &vaf
);
2686 trace_ath10k_log_dbg(ar
, mask
, &vaf
);
2690 EXPORT_SYMBOL(__ath10k_dbg
);
2692 void ath10k_dbg_dump(struct ath10k
*ar
,
2693 enum ath10k_debug_mask mask
,
2694 const char *msg
, const char *prefix
,
2695 const void *buf
, size_t len
)
2701 if (ath10k_debug_mask
& mask
) {
2703 __ath10k_dbg(ar
, mask
, "%s\n", msg
);
2705 for (ptr
= buf
; (ptr
- buf
) < len
; ptr
+= 16) {
2707 linebuflen
+= scnprintf(linebuf
+ linebuflen
,
2708 sizeof(linebuf
) - linebuflen
,
2710 (prefix
? prefix
: ""),
2711 (unsigned int)(ptr
- buf
));
2712 hex_dump_to_buffer(ptr
, len
- (ptr
- buf
), 16, 1,
2713 linebuf
+ linebuflen
,
2714 sizeof(linebuf
) - linebuflen
, true);
2715 dev_printk(KERN_DEBUG
, ar
->dev
, "%s\n", linebuf
);
2719 /* tracing code doesn't like null strings :/ */
2720 trace_ath10k_log_dbg_dump(ar
, msg
? msg
: "", prefix
? prefix
: "",
2723 EXPORT_SYMBOL(ath10k_dbg_dump
);
2725 #endif /* CONFIG_ATH10K_DEBUG */