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.
6 * Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
9 #include <linux/module.h>
10 #include <linux/debugfs.h>
11 #include <linux/vmalloc.h>
12 #include <linux/crc32.h>
13 #include <linux/firmware.h>
14 #include <linux/kstrtox.h>
22 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
24 #define ATH10K_DEBUG_CAL_DATA_LEN 12064
26 void ath10k_info(struct ath10k
*ar
, const char *fmt
, ...)
28 struct va_format vaf
= {
35 dev_info(ar
->dev
, "%pV", &vaf
);
36 trace_ath10k_log_info(ar
, &vaf
);
39 EXPORT_SYMBOL(ath10k_info
);
41 void ath10k_debug_print_hwfw_info(struct ath10k
*ar
)
43 const struct firmware
*firmware
;
44 char fw_features
[128] = {};
47 ath10k_core_get_fw_features_str(ar
, fw_features
, sizeof(fw_features
));
49 ath10k_info(ar
, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
52 ar
->bus_param
.chip_id
,
53 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
55 ath10k_info(ar
, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
56 IS_ENABLED(CONFIG_ATH10K_DEBUG
),
57 IS_ENABLED(CONFIG_ATH10K_DEBUGFS
),
58 IS_ENABLED(CONFIG_ATH10K_TRACING
),
59 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
),
60 IS_ENABLED(CONFIG_NL80211_TESTMODE
));
62 firmware
= ar
->normal_mode_fw
.fw_file
.firmware
;
64 crc
= crc32_le(0, firmware
->data
, firmware
->size
);
66 ath10k_info(ar
, "firmware ver %s api %d features %s crc32 %08x\n",
67 ar
->hw
->wiphy
->fw_version
,
73 void ath10k_debug_print_board_info(struct ath10k
*ar
)
76 const struct firmware
*board
;
79 if (ar
->id
.bmi_ids_valid
)
80 scnprintf(boardinfo
, sizeof(boardinfo
), "%d:%d",
81 ar
->id
.bmi_chip_id
, ar
->id
.bmi_board_id
);
83 scnprintf(boardinfo
, sizeof(boardinfo
), "N/A");
85 board
= ar
->normal_mode_fw
.board
;
86 if (!IS_ERR_OR_NULL(board
))
87 crc
= crc32_le(0, board
->data
, board
->size
);
91 ath10k_info(ar
, "board_file api %d bmi_id %s crc32 %08x",
97 void ath10k_debug_print_boot_info(struct ath10k
*ar
)
99 ath10k_info(ar
, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
100 ar
->htt
.target_version_major
,
101 ar
->htt
.target_version_minor
,
102 ar
->normal_mode_fw
.fw_file
.wmi_op_version
,
103 ar
->normal_mode_fw
.fw_file
.htt_op_version
,
104 ath10k_cal_mode_str(ar
->cal_mode
),
105 ar
->max_num_stations
,
106 test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
),
107 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
));
110 void ath10k_print_driver_info(struct ath10k
*ar
)
112 ath10k_debug_print_hwfw_info(ar
);
113 ath10k_debug_print_board_info(ar
);
114 ath10k_debug_print_boot_info(ar
);
116 EXPORT_SYMBOL(ath10k_print_driver_info
);
118 void ath10k_err(struct ath10k
*ar
, const char *fmt
, ...)
120 struct va_format vaf
= {
127 dev_err(ar
->dev
, "%pV", &vaf
);
128 trace_ath10k_log_err(ar
, &vaf
);
131 EXPORT_SYMBOL(ath10k_err
);
133 void ath10k_warn(struct ath10k
*ar
, const char *fmt
, ...)
135 struct va_format vaf
= {
142 dev_warn_ratelimited(ar
->dev
, "%pV", &vaf
);
143 trace_ath10k_log_warn(ar
, &vaf
);
147 EXPORT_SYMBOL(ath10k_warn
);
149 #ifdef CONFIG_ATH10K_DEBUGFS
151 static ssize_t
ath10k_read_wmi_services(struct file
*file
,
152 char __user
*user_buf
,
153 size_t count
, loff_t
*ppos
)
155 struct ath10k
*ar
= file
->private_data
;
157 size_t len
= 0, buf_len
= 8192;
163 buf
= kzalloc(buf_len
, GFP_KERNEL
);
167 mutex_lock(&ar
->conf_mutex
);
169 spin_lock_bh(&ar
->data_lock
);
170 for (i
= 0; i
< WMI_SERVICE_MAX
; i
++) {
171 enabled
= test_bit(i
, ar
->wmi
.svc_map
);
172 name
= wmi_service_name(i
);
176 len
+= scnprintf(buf
+ len
, buf_len
- len
,
177 "%-40s %s (bit %d)\n",
178 "unknown", "enabled", i
);
183 len
+= scnprintf(buf
+ len
, buf_len
- len
,
185 name
, enabled
? "enabled" : "-");
187 spin_unlock_bh(&ar
->data_lock
);
189 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
191 mutex_unlock(&ar
->conf_mutex
);
197 static const struct file_operations fops_wmi_services
= {
198 .read
= ath10k_read_wmi_services
,
200 .owner
= THIS_MODULE
,
201 .llseek
= default_llseek
,
204 static void ath10k_fw_stats_pdevs_free(struct list_head
*head
)
206 struct ath10k_fw_stats_pdev
*i
, *tmp
;
208 list_for_each_entry_safe(i
, tmp
, head
, list
) {
214 static void ath10k_fw_stats_vdevs_free(struct list_head
*head
)
216 struct ath10k_fw_stats_vdev
*i
, *tmp
;
218 list_for_each_entry_safe(i
, tmp
, head
, list
) {
224 static void ath10k_fw_stats_peers_free(struct list_head
*head
)
226 struct ath10k_fw_stats_peer
*i
, *tmp
;
228 list_for_each_entry_safe(i
, tmp
, head
, list
) {
234 static void ath10k_fw_extd_stats_peers_free(struct list_head
*head
)
236 struct ath10k_fw_extd_stats_peer
*i
, *tmp
;
238 list_for_each_entry_safe(i
, tmp
, head
, list
) {
244 static void ath10k_debug_fw_stats_reset(struct ath10k
*ar
)
246 spin_lock_bh(&ar
->data_lock
);
247 ar
->debug
.fw_stats_done
= false;
248 ar
->debug
.fw_stats
.extended
= false;
249 ath10k_fw_stats_pdevs_free(&ar
->debug
.fw_stats
.pdevs
);
250 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
251 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
252 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
253 spin_unlock_bh(&ar
->data_lock
);
256 void ath10k_debug_fw_stats_process(struct ath10k
*ar
, struct sk_buff
*skb
)
258 struct ath10k_fw_stats stats
= {};
259 bool is_start
, is_started
, is_end
;
264 INIT_LIST_HEAD(&stats
.pdevs
);
265 INIT_LIST_HEAD(&stats
.vdevs
);
266 INIT_LIST_HEAD(&stats
.peers
);
267 INIT_LIST_HEAD(&stats
.peers_extd
);
269 spin_lock_bh(&ar
->data_lock
);
270 ret
= ath10k_wmi_pull_fw_stats(ar
, skb
, &stats
);
272 ath10k_warn(ar
, "failed to pull fw stats: %d\n", ret
);
276 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
277 * splits the stats data and delivers it in a ping-pong fashion of
278 * request cmd-update event.
280 * However there is no explicit end-of-data. Instead start-of-data is
281 * used as an implicit one. This works as follows:
282 * a) discard stat update events until one with pdev stats is
283 * delivered - this skips session started at end of (b)
284 * b) consume stat update events until another one with pdev stats is
285 * delivered which is treated as end-of-data and is itself discarded
287 if (ath10k_peer_stats_enabled(ar
))
288 ath10k_sta_update_rx_duration(ar
, &stats
);
290 if (ar
->debug
.fw_stats_done
) {
291 if (!ath10k_peer_stats_enabled(ar
))
292 ath10k_warn(ar
, "received unsolicited stats update event\n");
297 num_peers
= list_count_nodes(&ar
->debug
.fw_stats
.peers
);
298 num_vdevs
= list_count_nodes(&ar
->debug
.fw_stats
.vdevs
);
299 is_start
= (list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
300 !list_empty(&stats
.pdevs
));
301 is_end
= (!list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
302 !list_empty(&stats
.pdevs
));
305 list_splice_tail_init(&stats
.pdevs
, &ar
->debug
.fw_stats
.pdevs
);
308 ar
->debug
.fw_stats_done
= true;
311 ar
->debug
.fw_stats
.extended
= true;
313 is_started
= !list_empty(&ar
->debug
.fw_stats
.pdevs
);
315 if (is_started
&& !is_end
) {
316 if (num_peers
>= ATH10K_MAX_NUM_PEER_IDS
) {
317 /* Although this is unlikely impose a sane limit to
318 * prevent firmware from DoS-ing the host.
320 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
321 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
322 ath10k_warn(ar
, "dropping fw peer stats\n");
326 if (num_vdevs
>= BITS_PER_LONG
) {
327 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
328 ath10k_warn(ar
, "dropping fw vdev stats\n");
332 if (!list_empty(&stats
.peers
))
333 list_splice_tail_init(&stats
.peers_extd
,
334 &ar
->debug
.fw_stats
.peers_extd
);
336 list_splice_tail_init(&stats
.peers
, &ar
->debug
.fw_stats
.peers
);
337 list_splice_tail_init(&stats
.vdevs
, &ar
->debug
.fw_stats
.vdevs
);
340 complete(&ar
->debug
.fw_stats_complete
);
343 /* In some cases lists have been spliced and cleared. Free up
344 * resources if that is not the case.
346 ath10k_fw_stats_pdevs_free(&stats
.pdevs
);
347 ath10k_fw_stats_vdevs_free(&stats
.vdevs
);
348 ath10k_fw_stats_peers_free(&stats
.peers
);
349 ath10k_fw_extd_stats_peers_free(&stats
.peers_extd
);
351 spin_unlock_bh(&ar
->data_lock
);
354 int ath10k_debug_fw_stats_request(struct ath10k
*ar
)
356 unsigned long timeout
, time_left
;
359 lockdep_assert_held(&ar
->conf_mutex
);
361 timeout
= jiffies
+ msecs_to_jiffies(1 * HZ
);
363 ath10k_debug_fw_stats_reset(ar
);
366 if (time_after(jiffies
, timeout
))
369 reinit_completion(&ar
->debug
.fw_stats_complete
);
371 ret
= ath10k_wmi_request_stats(ar
, ar
->fw_stats_req_mask
);
373 ath10k_warn(ar
, "could not request stats (%d)\n", ret
);
378 wait_for_completion_timeout(&ar
->debug
.fw_stats_complete
,
383 spin_lock_bh(&ar
->data_lock
);
384 if (ar
->debug
.fw_stats_done
) {
385 spin_unlock_bh(&ar
->data_lock
);
388 spin_unlock_bh(&ar
->data_lock
);
394 static int ath10k_fw_stats_open(struct inode
*inode
, struct file
*file
)
396 struct ath10k
*ar
= inode
->i_private
;
400 mutex_lock(&ar
->conf_mutex
);
402 if (ar
->state
!= ATH10K_STATE_ON
) {
407 buf
= vmalloc(ATH10K_FW_STATS_BUF_SIZE
);
413 ret
= ath10k_debug_fw_stats_request(ar
);
415 ath10k_warn(ar
, "failed to request fw stats: %d\n", ret
);
419 ret
= ath10k_wmi_fw_stats_fill(ar
, &ar
->debug
.fw_stats
, buf
);
421 ath10k_warn(ar
, "failed to fill fw stats: %d\n", ret
);
425 file
->private_data
= buf
;
427 mutex_unlock(&ar
->conf_mutex
);
434 mutex_unlock(&ar
->conf_mutex
);
438 static int ath10k_fw_stats_release(struct inode
*inode
, struct file
*file
)
440 vfree(file
->private_data
);
445 static ssize_t
ath10k_fw_stats_read(struct file
*file
, char __user
*user_buf
,
446 size_t count
, loff_t
*ppos
)
448 const char *buf
= file
->private_data
;
449 size_t len
= strlen(buf
);
451 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
454 static const struct file_operations fops_fw_stats
= {
455 .open
= ath10k_fw_stats_open
,
456 .release
= ath10k_fw_stats_release
,
457 .read
= ath10k_fw_stats_read
,
458 .owner
= THIS_MODULE
,
459 .llseek
= default_llseek
,
462 static ssize_t
ath10k_debug_fw_reset_stats_read(struct file
*file
,
463 char __user
*user_buf
,
464 size_t count
, loff_t
*ppos
)
466 struct ath10k
*ar
= file
->private_data
;
468 size_t len
= 0, buf_len
= 500;
471 buf
= kmalloc(buf_len
, GFP_KERNEL
);
475 spin_lock_bh(&ar
->data_lock
);
477 len
+= scnprintf(buf
+ len
, buf_len
- len
,
478 "fw_crash_counter\t\t%d\n", ar
->stats
.fw_crash_counter
);
479 len
+= scnprintf(buf
+ len
, buf_len
- len
,
480 "fw_warm_reset_counter\t\t%d\n",
481 ar
->stats
.fw_warm_reset_counter
);
482 len
+= scnprintf(buf
+ len
, buf_len
- len
,
483 "fw_cold_reset_counter\t\t%d\n",
484 ar
->stats
.fw_cold_reset_counter
);
486 spin_unlock_bh(&ar
->data_lock
);
488 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
495 static const struct file_operations fops_fw_reset_stats
= {
497 .read
= ath10k_debug_fw_reset_stats_read
,
498 .owner
= THIS_MODULE
,
499 .llseek
= default_llseek
,
502 /* This is a clean assert crash in firmware. */
503 static int ath10k_debug_fw_assert(struct ath10k
*ar
)
505 struct wmi_vdev_install_key_cmd
*cmd
;
508 skb
= ath10k_wmi_alloc_skb(ar
, sizeof(*cmd
) + 16);
512 cmd
= (struct wmi_vdev_install_key_cmd
*)skb
->data
;
513 memset(cmd
, 0, sizeof(*cmd
));
515 /* big enough number so that firmware asserts */
516 cmd
->vdev_id
= __cpu_to_le32(0x7ffe);
518 return ath10k_wmi_cmd_send(ar
, skb
,
519 ar
->wmi
.cmd
->vdev_install_key_cmdid
);
522 static ssize_t
ath10k_read_simulate_fw_crash(struct file
*file
,
523 char __user
*user_buf
,
524 size_t count
, loff_t
*ppos
)
527 "To simulate firmware crash write one of the keywords to this file:\n"
528 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
529 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
530 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
531 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
533 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
536 /* Simulate firmware crash:
537 * 'soft': Call wmi command causing firmware hang. This firmware hang is
538 * recoverable by warm firmware reset.
539 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
540 * vdev id. This is hard firmware crash because it is recoverable only by cold
543 static ssize_t
ath10k_write_simulate_fw_crash(struct file
*file
,
544 const char __user
*user_buf
,
545 size_t count
, loff_t
*ppos
)
547 struct ath10k
*ar
= file
->private_data
;
552 /* filter partial writes and invalid commands */
553 if (*ppos
!= 0 || count
>= sizeof(buf
) || count
== 0)
556 rc
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
560 /* drop the possible '\n' from the end */
561 if (buf
[*ppos
- 1] == '\n')
562 buf
[*ppos
- 1] = '\0';
564 mutex_lock(&ar
->conf_mutex
);
566 if (ar
->state
!= ATH10K_STATE_ON
&&
567 ar
->state
!= ATH10K_STATE_RESTARTED
) {
572 if (!strcmp(buf
, "soft")) {
573 ath10k_info(ar
, "simulating soft firmware crash\n");
574 ret
= ath10k_wmi_force_fw_hang(ar
, WMI_FORCE_FW_HANG_ASSERT
, 0);
575 } else if (!strcmp(buf
, "hard")) {
576 ath10k_info(ar
, "simulating hard firmware crash\n");
577 /* 0x7fff is vdev id, and it is always out of range for all
578 * firmware variants in order to force a firmware crash.
580 ret
= ath10k_wmi_vdev_set_param(ar
, 0x7fff,
581 ar
->wmi
.vdev_param
->rts_threshold
,
583 } else if (!strcmp(buf
, "assert")) {
584 ath10k_info(ar
, "simulating firmware assert crash\n");
585 ret
= ath10k_debug_fw_assert(ar
);
586 } else if (!strcmp(buf
, "hw-restart")) {
587 ath10k_info(ar
, "user requested hw restart\n");
588 ath10k_core_start_recovery(ar
);
596 ath10k_warn(ar
, "failed to simulate firmware crash: %d\n", ret
);
603 mutex_unlock(&ar
->conf_mutex
);
607 static const struct file_operations fops_simulate_fw_crash
= {
608 .read
= ath10k_read_simulate_fw_crash
,
609 .write
= ath10k_write_simulate_fw_crash
,
611 .owner
= THIS_MODULE
,
612 .llseek
= default_llseek
,
615 static ssize_t
ath10k_read_chip_id(struct file
*file
, char __user
*user_buf
,
616 size_t count
, loff_t
*ppos
)
618 struct ath10k
*ar
= file
->private_data
;
622 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->bus_param
.chip_id
);
624 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
627 static const struct file_operations fops_chip_id
= {
628 .read
= ath10k_read_chip_id
,
630 .owner
= THIS_MODULE
,
631 .llseek
= default_llseek
,
634 static ssize_t
ath10k_reg_addr_read(struct file
*file
,
635 char __user
*user_buf
,
636 size_t count
, loff_t
*ppos
)
638 struct ath10k
*ar
= file
->private_data
;
643 mutex_lock(&ar
->conf_mutex
);
644 reg_addr
= ar
->debug
.reg_addr
;
645 mutex_unlock(&ar
->conf_mutex
);
647 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "0x%x\n", reg_addr
);
649 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
652 static ssize_t
ath10k_reg_addr_write(struct file
*file
,
653 const char __user
*user_buf
,
654 size_t count
, loff_t
*ppos
)
656 struct ath10k
*ar
= file
->private_data
;
660 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_addr
);
664 if (!IS_ALIGNED(reg_addr
, 4))
667 mutex_lock(&ar
->conf_mutex
);
668 ar
->debug
.reg_addr
= reg_addr
;
669 mutex_unlock(&ar
->conf_mutex
);
674 static const struct file_operations fops_reg_addr
= {
675 .read
= ath10k_reg_addr_read
,
676 .write
= ath10k_reg_addr_write
,
678 .owner
= THIS_MODULE
,
679 .llseek
= default_llseek
,
682 static ssize_t
ath10k_reg_value_read(struct file
*file
,
683 char __user
*user_buf
,
684 size_t count
, loff_t
*ppos
)
686 struct ath10k
*ar
= file
->private_data
;
689 u32 reg_addr
, reg_val
;
692 mutex_lock(&ar
->conf_mutex
);
694 if (ar
->state
!= ATH10K_STATE_ON
&&
695 ar
->state
!= ATH10K_STATE_UTF
) {
700 reg_addr
= ar
->debug
.reg_addr
;
702 reg_val
= ath10k_hif_read32(ar
, reg_addr
);
703 len
= scnprintf(buf
, sizeof(buf
), "0x%08x:0x%08x\n", reg_addr
, reg_val
);
705 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
708 mutex_unlock(&ar
->conf_mutex
);
713 static ssize_t
ath10k_reg_value_write(struct file
*file
,
714 const char __user
*user_buf
,
715 size_t count
, loff_t
*ppos
)
717 struct ath10k
*ar
= file
->private_data
;
718 u32 reg_addr
, reg_val
;
721 mutex_lock(&ar
->conf_mutex
);
723 if (ar
->state
!= ATH10K_STATE_ON
&&
724 ar
->state
!= ATH10K_STATE_UTF
) {
729 reg_addr
= ar
->debug
.reg_addr
;
731 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_val
);
735 ath10k_hif_write32(ar
, reg_addr
, reg_val
);
740 mutex_unlock(&ar
->conf_mutex
);
745 static const struct file_operations fops_reg_value
= {
746 .read
= ath10k_reg_value_read
,
747 .write
= ath10k_reg_value_write
,
749 .owner
= THIS_MODULE
,
750 .llseek
= default_llseek
,
753 static ssize_t
ath10k_mem_value_read(struct file
*file
,
754 char __user
*user_buf
,
755 size_t count
, loff_t
*ppos
)
757 struct ath10k
*ar
= file
->private_data
;
767 mutex_lock(&ar
->conf_mutex
);
769 buf
= vmalloc(count
);
775 if (ar
->state
!= ATH10K_STATE_ON
&&
776 ar
->state
!= ATH10K_STATE_UTF
) {
781 ret
= ath10k_hif_diag_read(ar
, *ppos
, buf
, count
);
783 ath10k_warn(ar
, "failed to read address 0x%08x via diagnose window from debugfs: %d\n",
788 ret
= copy_to_user(user_buf
, buf
, count
);
800 mutex_unlock(&ar
->conf_mutex
);
805 static ssize_t
ath10k_mem_value_write(struct file
*file
,
806 const char __user
*user_buf
,
807 size_t count
, loff_t
*ppos
)
809 struct ath10k
*ar
= file
->private_data
;
819 mutex_lock(&ar
->conf_mutex
);
821 buf
= vmalloc(count
);
827 if (ar
->state
!= ATH10K_STATE_ON
&&
828 ar
->state
!= ATH10K_STATE_UTF
) {
833 ret
= copy_from_user(buf
, user_buf
, count
);
839 ret
= ath10k_hif_diag_write(ar
, *ppos
, buf
, count
);
841 ath10k_warn(ar
, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
851 mutex_unlock(&ar
->conf_mutex
);
856 static const struct file_operations fops_mem_value
= {
857 .read
= ath10k_mem_value_read
,
858 .write
= ath10k_mem_value_write
,
860 .owner
= THIS_MODULE
,
861 .llseek
= default_llseek
,
864 static int ath10k_debug_htt_stats_req(struct ath10k
*ar
)
869 lockdep_assert_held(&ar
->conf_mutex
);
871 if (ar
->debug
.htt_stats_mask
== 0)
872 /* htt stats are disabled */
875 if (ar
->state
!= ATH10K_STATE_ON
)
878 cookie
= get_jiffies_64();
880 ret
= ath10k_htt_h2t_stats_req(&ar
->htt
, ar
->debug
.htt_stats_mask
,
881 ar
->debug
.reset_htt_stats
, cookie
);
883 ath10k_warn(ar
, "failed to send htt stats request: %d\n", ret
);
887 queue_delayed_work(ar
->workqueue
, &ar
->debug
.htt_stats_dwork
,
888 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL
));
893 static void ath10k_debug_htt_stats_dwork(struct work_struct
*work
)
895 struct ath10k
*ar
= container_of(work
, struct ath10k
,
896 debug
.htt_stats_dwork
.work
);
898 mutex_lock(&ar
->conf_mutex
);
900 ath10k_debug_htt_stats_req(ar
);
902 mutex_unlock(&ar
->conf_mutex
);
905 static ssize_t
ath10k_read_htt_stats_mask(struct file
*file
,
906 char __user
*user_buf
,
907 size_t count
, loff_t
*ppos
)
909 struct ath10k
*ar
= file
->private_data
;
913 len
= scnprintf(buf
, sizeof(buf
), "%lu\n", ar
->debug
.htt_stats_mask
);
915 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
918 static ssize_t
ath10k_write_htt_stats_mask(struct file
*file
,
919 const char __user
*user_buf
,
920 size_t count
, loff_t
*ppos
)
922 struct ath10k
*ar
= file
->private_data
;
926 ret
= kstrtoul_from_user(user_buf
, count
, 0, &mask
);
930 /* max 17 bit masks (for now) */
931 if (mask
> HTT_STATS_BIT_MASK
)
934 mutex_lock(&ar
->conf_mutex
);
936 ar
->debug
.htt_stats_mask
= mask
;
938 ret
= ath10k_debug_htt_stats_req(ar
);
945 mutex_unlock(&ar
->conf_mutex
);
950 static const struct file_operations fops_htt_stats_mask
= {
951 .read
= ath10k_read_htt_stats_mask
,
952 .write
= ath10k_write_htt_stats_mask
,
954 .owner
= THIS_MODULE
,
955 .llseek
= default_llseek
,
958 static ssize_t
ath10k_read_htt_max_amsdu_ampdu(struct file
*file
,
959 char __user
*user_buf
,
960 size_t count
, loff_t
*ppos
)
962 struct ath10k
*ar
= file
->private_data
;
967 mutex_lock(&ar
->conf_mutex
);
969 amsdu
= ar
->htt
.max_num_amsdu
;
970 ampdu
= ar
->htt
.max_num_ampdu
;
971 mutex_unlock(&ar
->conf_mutex
);
973 len
= scnprintf(buf
, sizeof(buf
), "%u %u\n", amsdu
, ampdu
);
975 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
978 static ssize_t
ath10k_write_htt_max_amsdu_ampdu(struct file
*file
,
979 const char __user
*user_buf
,
980 size_t count
, loff_t
*ppos
)
982 struct ath10k
*ar
= file
->private_data
;
985 unsigned int amsdu
, ampdu
;
987 res
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
992 res
= sscanf(buf
, "%u %u", &amsdu
, &du
);
997 mutex_lock(&ar
->conf_mutex
);
999 res
= ath10k_htt_h2t_aggr_cfg_msg(&ar
->htt
, ampdu
, amsdu
);
1004 ar
->htt
.max_num_amsdu
= amsdu
;
1005 ar
->htt
.max_num_ampdu
= ampdu
;
1008 mutex_unlock(&ar
->conf_mutex
);
1012 static const struct file_operations fops_htt_max_amsdu_ampdu
= {
1013 .read
= ath10k_read_htt_max_amsdu_ampdu
,
1014 .write
= ath10k_write_htt_max_amsdu_ampdu
,
1015 .open
= simple_open
,
1016 .owner
= THIS_MODULE
,
1017 .llseek
= default_llseek
,
1020 static ssize_t
ath10k_read_fw_dbglog(struct file
*file
,
1021 char __user
*user_buf
,
1022 size_t count
, loff_t
*ppos
)
1024 struct ath10k
*ar
= file
->private_data
;
1028 len
= scnprintf(buf
, sizeof(buf
), "0x%16llx %u\n",
1029 ar
->debug
.fw_dbglog_mask
, ar
->debug
.fw_dbglog_level
);
1031 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1034 static ssize_t
ath10k_write_fw_dbglog(struct file
*file
,
1035 const char __user
*user_buf
,
1036 size_t count
, loff_t
*ppos
)
1038 struct ath10k
*ar
= file
->private_data
;
1041 unsigned int log_level
;
1044 ret
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
1049 ret
= sscanf(buf
, "%llx %u", &mask
, &log_level
);
1055 /* default if user did not specify */
1056 log_level
= ATH10K_DBGLOG_LEVEL_WARN
;
1058 mutex_lock(&ar
->conf_mutex
);
1060 ar
->debug
.fw_dbglog_mask
= mask
;
1061 ar
->debug
.fw_dbglog_level
= log_level
;
1063 if (ar
->state
== ATH10K_STATE_ON
) {
1064 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1065 ar
->debug
.fw_dbglog_level
);
1067 ath10k_warn(ar
, "dbglog cfg failed from debugfs: %d\n",
1076 mutex_unlock(&ar
->conf_mutex
);
1081 /* TODO: Would be nice to always support ethtool stats, would need to
1082 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1083 * struct available..
1086 /* This generally corresponds to the debugfs fw_stats file */
1087 static const char ath10k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1097 "d_tx_power", /* in .5 dbM I think */
1098 "d_rx_crc_err", /* fcs_bad */
1099 "d_rx_crc_err_drop", /* frame with FCS error, dropped late in kernel */
1101 "d_tx_mpdus_queued",
1103 "d_tx_msdu_dropped",
1106 "d_tx_ppdu_hw_queued",
1108 "d_tx_fifo_underrun",
1110 "d_tx_mpdu_requeued",
1111 "d_tx_excessive_retries",
1113 "d_tx_dropped_sw_retries",
1114 "d_tx_illegal_rate",
1115 "d_tx_continuous_xretries",
1117 "d_tx_mpdu_txop_limit",
1119 "d_rx_mid_ppdu_route_change",
1121 "d_rx_extra_frags_ring0",
1122 "d_rx_extra_frags_ring1",
1123 "d_rx_extra_frags_ring2",
1124 "d_rx_extra_frags_ring3",
1130 "d_rx_phy_err_drops",
1131 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1133 "d_fw_warm_reset_count",
1134 "d_fw_cold_reset_count",
1137 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1139 void ath10k_debug_get_et_strings(struct ieee80211_hw
*hw
,
1140 struct ieee80211_vif
*vif
,
1143 if (sset
== ETH_SS_STATS
)
1144 memcpy(data
, ath10k_gstrings_stats
,
1145 sizeof(ath10k_gstrings_stats
));
1148 int ath10k_debug_get_et_sset_count(struct ieee80211_hw
*hw
,
1149 struct ieee80211_vif
*vif
, int sset
)
1151 if (sset
== ETH_SS_STATS
)
1152 return ATH10K_SSTATS_LEN
;
1157 void ath10k_debug_get_et_stats(struct ieee80211_hw
*hw
,
1158 struct ieee80211_vif
*vif
,
1159 struct ethtool_stats
*stats
, u64
*data
)
1161 struct ath10k
*ar
= hw
->priv
;
1162 static const struct ath10k_fw_stats_pdev zero_stats
= {};
1163 const struct ath10k_fw_stats_pdev
*pdev_stats
;
1166 mutex_lock(&ar
->conf_mutex
);
1168 if (ar
->state
== ATH10K_STATE_ON
) {
1169 ret
= ath10k_debug_fw_stats_request(ar
);
1171 /* just print a warning and try to use older results */
1173 "failed to get fw stats for ethtool: %d\n",
1178 pdev_stats
= list_first_entry_or_null(&ar
->debug
.fw_stats
.pdevs
,
1179 struct ath10k_fw_stats_pdev
,
1182 /* no results available so just return zeroes */
1183 pdev_stats
= &zero_stats
;
1186 spin_lock_bh(&ar
->data_lock
);
1188 data
[i
++] = pdev_stats
->hw_reaped
; /* ppdu reaped */
1189 data
[i
++] = 0; /* tx bytes */
1190 data
[i
++] = pdev_stats
->htt_mpdus
;
1191 data
[i
++] = 0; /* rx bytes */
1192 data
[i
++] = pdev_stats
->ch_noise_floor
;
1193 data
[i
++] = pdev_stats
->cycle_count
;
1194 data
[i
++] = pdev_stats
->phy_err_count
;
1195 data
[i
++] = pdev_stats
->rts_bad
;
1196 data
[i
++] = pdev_stats
->rts_good
;
1197 data
[i
++] = pdev_stats
->chan_tx_power
;
1198 data
[i
++] = pdev_stats
->fcs_bad
;
1199 data
[i
++] = ar
->stats
.rx_crc_err_drop
;
1200 data
[i
++] = pdev_stats
->no_beacons
;
1201 data
[i
++] = pdev_stats
->mpdu_enqued
;
1202 data
[i
++] = pdev_stats
->msdu_enqued
;
1203 data
[i
++] = pdev_stats
->wmm_drop
;
1204 data
[i
++] = pdev_stats
->local_enqued
;
1205 data
[i
++] = pdev_stats
->local_freed
;
1206 data
[i
++] = pdev_stats
->hw_queued
;
1207 data
[i
++] = pdev_stats
->hw_reaped
;
1208 data
[i
++] = pdev_stats
->underrun
;
1209 data
[i
++] = pdev_stats
->tx_abort
;
1210 data
[i
++] = pdev_stats
->mpdus_requeued
;
1211 data
[i
++] = pdev_stats
->tx_ko
;
1212 data
[i
++] = pdev_stats
->data_rc
;
1213 data
[i
++] = pdev_stats
->sw_retry_failure
;
1214 data
[i
++] = pdev_stats
->illgl_rate_phy_err
;
1215 data
[i
++] = pdev_stats
->pdev_cont_xretry
;
1216 data
[i
++] = pdev_stats
->pdev_tx_timeout
;
1217 data
[i
++] = pdev_stats
->txop_ovf
;
1218 data
[i
++] = pdev_stats
->pdev_resets
;
1219 data
[i
++] = pdev_stats
->mid_ppdu_route_change
;
1220 data
[i
++] = pdev_stats
->status_rcvd
;
1221 data
[i
++] = pdev_stats
->r0_frags
;
1222 data
[i
++] = pdev_stats
->r1_frags
;
1223 data
[i
++] = pdev_stats
->r2_frags
;
1224 data
[i
++] = pdev_stats
->r3_frags
;
1225 data
[i
++] = pdev_stats
->htt_msdus
;
1226 data
[i
++] = pdev_stats
->htt_mpdus
;
1227 data
[i
++] = pdev_stats
->loc_msdus
;
1228 data
[i
++] = pdev_stats
->loc_mpdus
;
1229 data
[i
++] = pdev_stats
->phy_errs
;
1230 data
[i
++] = pdev_stats
->phy_err_drop
;
1231 data
[i
++] = pdev_stats
->mpdu_errs
;
1232 data
[i
++] = ar
->stats
.fw_crash_counter
;
1233 data
[i
++] = ar
->stats
.fw_warm_reset_counter
;
1234 data
[i
++] = ar
->stats
.fw_cold_reset_counter
;
1236 spin_unlock_bh(&ar
->data_lock
);
1238 mutex_unlock(&ar
->conf_mutex
);
1240 WARN_ON(i
!= ATH10K_SSTATS_LEN
);
1243 static const struct file_operations fops_fw_dbglog
= {
1244 .read
= ath10k_read_fw_dbglog
,
1245 .write
= ath10k_write_fw_dbglog
,
1246 .open
= simple_open
,
1247 .owner
= THIS_MODULE
,
1248 .llseek
= default_llseek
,
1251 static int ath10k_debug_cal_data_fetch(struct ath10k
*ar
)
1257 lockdep_assert_held(&ar
->conf_mutex
);
1259 if (WARN_ON(ar
->hw_params
.cal_data_len
> ATH10K_DEBUG_CAL_DATA_LEN
))
1262 if (ar
->hw_params
.cal_data_len
== 0)
1265 hi_addr
= host_interest_item_address(HI_ITEM(hi_board_data
));
1267 ret
= ath10k_hif_diag_read(ar
, hi_addr
, &addr
, sizeof(addr
));
1269 ath10k_warn(ar
, "failed to read hi_board_data address: %d\n",
1274 ret
= ath10k_hif_diag_read(ar
, le32_to_cpu(addr
), ar
->debug
.cal_data
,
1275 ar
->hw_params
.cal_data_len
);
1277 ath10k_warn(ar
, "failed to read calibration data: %d\n", ret
);
1284 static int ath10k_debug_cal_data_open(struct inode
*inode
, struct file
*file
)
1286 struct ath10k
*ar
= inode
->i_private
;
1288 mutex_lock(&ar
->conf_mutex
);
1290 if (ar
->state
== ATH10K_STATE_ON
||
1291 ar
->state
== ATH10K_STATE_UTF
) {
1292 ath10k_debug_cal_data_fetch(ar
);
1295 file
->private_data
= ar
;
1296 mutex_unlock(&ar
->conf_mutex
);
1301 static ssize_t
ath10k_debug_cal_data_read(struct file
*file
,
1302 char __user
*user_buf
,
1303 size_t count
, loff_t
*ppos
)
1305 struct ath10k
*ar
= file
->private_data
;
1307 mutex_lock(&ar
->conf_mutex
);
1309 count
= simple_read_from_buffer(user_buf
, count
, ppos
,
1311 ar
->hw_params
.cal_data_len
);
1313 mutex_unlock(&ar
->conf_mutex
);
1318 static ssize_t
ath10k_write_ani_enable(struct file
*file
,
1319 const char __user
*user_buf
,
1320 size_t count
, loff_t
*ppos
)
1322 struct ath10k
*ar
= file
->private_data
;
1326 if (kstrtou8_from_user(user_buf
, count
, 0, &enable
))
1329 mutex_lock(&ar
->conf_mutex
);
1331 if (ar
->ani_enabled
== enable
) {
1336 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->ani_enable
,
1339 ath10k_warn(ar
, "ani_enable failed from debugfs: %d\n", ret
);
1342 ar
->ani_enabled
= enable
;
1347 mutex_unlock(&ar
->conf_mutex
);
1352 static ssize_t
ath10k_read_ani_enable(struct file
*file
, char __user
*user_buf
,
1353 size_t count
, loff_t
*ppos
)
1355 struct ath10k
*ar
= file
->private_data
;
1359 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->ani_enabled
);
1361 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1364 static const struct file_operations fops_ani_enable
= {
1365 .read
= ath10k_read_ani_enable
,
1366 .write
= ath10k_write_ani_enable
,
1367 .open
= simple_open
,
1368 .owner
= THIS_MODULE
,
1369 .llseek
= default_llseek
,
1372 static const struct file_operations fops_cal_data
= {
1373 .open
= ath10k_debug_cal_data_open
,
1374 .read
= ath10k_debug_cal_data_read
,
1375 .owner
= THIS_MODULE
,
1376 .llseek
= default_llseek
,
1379 static ssize_t
ath10k_read_nf_cal_period(struct file
*file
,
1380 char __user
*user_buf
,
1381 size_t count
, loff_t
*ppos
)
1383 struct ath10k
*ar
= file
->private_data
;
1387 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->debug
.nf_cal_period
);
1389 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1392 static ssize_t
ath10k_write_nf_cal_period(struct file
*file
,
1393 const char __user
*user_buf
,
1394 size_t count
, loff_t
*ppos
)
1396 struct ath10k
*ar
= file
->private_data
;
1397 unsigned long period
;
1400 ret
= kstrtoul_from_user(user_buf
, count
, 0, &period
);
1404 if (period
> WMI_PDEV_PARAM_CAL_PERIOD_MAX
)
1407 /* there's no way to switch back to the firmware default */
1411 mutex_lock(&ar
->conf_mutex
);
1413 ar
->debug
.nf_cal_period
= period
;
1415 if (ar
->state
!= ATH10K_STATE_ON
) {
1416 /* firmware is not running, nothing else to do */
1421 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->cal_period
,
1422 ar
->debug
.nf_cal_period
);
1424 ath10k_warn(ar
, "cal period cfg failed from debugfs: %d\n",
1432 mutex_unlock(&ar
->conf_mutex
);
1437 static const struct file_operations fops_nf_cal_period
= {
1438 .read
= ath10k_read_nf_cal_period
,
1439 .write
= ath10k_write_nf_cal_period
,
1440 .open
= simple_open
,
1441 .owner
= THIS_MODULE
,
1442 .llseek
= default_llseek
,
1445 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1447 static int ath10k_debug_tpc_stats_request(struct ath10k
*ar
)
1450 unsigned long time_left
;
1452 lockdep_assert_held(&ar
->conf_mutex
);
1454 reinit_completion(&ar
->debug
.tpc_complete
);
1456 ret
= ath10k_wmi_pdev_get_tpc_config(ar
, WMI_TPC_CONFIG_PARAM
);
1458 ath10k_warn(ar
, "failed to request tpc config: %d\n", ret
);
1462 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
1470 void ath10k_debug_tpc_stats_process(struct ath10k
*ar
,
1471 struct ath10k_tpc_stats
*tpc_stats
)
1473 spin_lock_bh(&ar
->data_lock
);
1475 kfree(ar
->debug
.tpc_stats
);
1476 ar
->debug
.tpc_stats
= tpc_stats
;
1477 complete(&ar
->debug
.tpc_complete
);
1479 spin_unlock_bh(&ar
->data_lock
);
1483 ath10k_debug_tpc_stats_final_process(struct ath10k
*ar
,
1484 struct ath10k_tpc_stats_final
*tpc_stats
)
1486 spin_lock_bh(&ar
->data_lock
);
1488 kfree(ar
->debug
.tpc_stats_final
);
1489 ar
->debug
.tpc_stats_final
= tpc_stats
;
1490 complete(&ar
->debug
.tpc_complete
);
1492 spin_unlock_bh(&ar
->data_lock
);
1495 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats
*tpc_stats
,
1496 unsigned int j
, char *buf
, size_t *len
)
1500 static const char table_str
[][5] = { "CDD",
1503 static const char pream_str
[][6] = { "CCK",
1512 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1513 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1514 "********************************\n");
1515 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1516 "******************* %s POWER TABLE ****************\n",
1518 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1519 "********************************\n");
1520 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1521 "No. Preamble Rate_code ");
1523 for (i
= 0; i
< tpc_stats
->num_tx_chain
; i
++)
1524 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1527 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
, "\n");
1529 for (i
= 0; i
< tpc_stats
->rate_max
; i
++) {
1530 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1531 "%8d %s 0x%2x %s\n", i
,
1532 pream_str
[tpc_stats
->tpc_table
[j
].pream_idx
[i
]],
1533 tpc_stats
->tpc_table
[j
].rate_code
[i
],
1534 tpc_stats
->tpc_table
[j
].tpc_value
[i
]);
1537 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1538 "***********************************\n");
1541 static void ath10k_tpc_stats_fill(struct ath10k
*ar
,
1542 struct ath10k_tpc_stats
*tpc_stats
,
1546 size_t len
, buf_len
;
1549 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1551 spin_lock_bh(&ar
->data_lock
);
1554 ath10k_warn(ar
, "failed to get tpc stats\n");
1558 len
+= scnprintf(buf
+ len
, buf_len
- len
, "\n");
1559 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1560 "*************************************\n");
1561 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1562 "TPC config for channel %4d mode %d\n",
1563 tpc_stats
->chan_freq
,
1564 tpc_stats
->phy_mode
);
1565 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1566 "*************************************\n");
1567 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1568 "CTL = 0x%2x Reg. Domain = %2d\n",
1570 tpc_stats
->reg_domain
);
1571 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1572 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1573 tpc_stats
->twice_antenna_gain
,
1574 tpc_stats
->twice_antenna_reduction
);
1575 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1576 "Power Limit = %2d Reg. Max Power = %2d\n",
1577 tpc_stats
->power_limit
,
1578 tpc_stats
->twice_max_rd_power
/ 2);
1579 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1580 "Num tx chains = %2d Num supported rates = %2d\n",
1581 tpc_stats
->num_tx_chain
,
1582 tpc_stats
->rate_max
);
1584 for (j
= 0; j
< WMI_TPC_FLAG
; j
++) {
1586 case WMI_TPC_TABLE_TYPE_CDD
:
1587 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1588 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1589 "CDD not supported\n");
1593 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1595 case WMI_TPC_TABLE_TYPE_STBC
:
1596 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1597 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1598 "STBC not supported\n");
1602 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1604 case WMI_TPC_TABLE_TYPE_TXBF
:
1605 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1606 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1607 "TXBF not supported\n***************************\n");
1611 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1614 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1621 spin_unlock_bh(&ar
->data_lock
);
1629 static int ath10k_tpc_stats_open(struct inode
*inode
, struct file
*file
)
1631 struct ath10k
*ar
= inode
->i_private
;
1635 mutex_lock(&ar
->conf_mutex
);
1637 if (ar
->state
!= ATH10K_STATE_ON
) {
1642 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
1648 ret
= ath10k_debug_tpc_stats_request(ar
);
1650 ath10k_warn(ar
, "failed to request tpc config stats: %d\n",
1655 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
1656 file
->private_data
= buf
;
1658 mutex_unlock(&ar
->conf_mutex
);
1665 mutex_unlock(&ar
->conf_mutex
);
1669 static int ath10k_tpc_stats_release(struct inode
*inode
, struct file
*file
)
1671 vfree(file
->private_data
);
1676 static ssize_t
ath10k_tpc_stats_read(struct file
*file
, char __user
*user_buf
,
1677 size_t count
, loff_t
*ppos
)
1679 const char *buf
= file
->private_data
;
1680 size_t len
= strlen(buf
);
1682 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1685 static const struct file_operations fops_tpc_stats
= {
1686 .open
= ath10k_tpc_stats_open
,
1687 .release
= ath10k_tpc_stats_release
,
1688 .read
= ath10k_tpc_stats_read
,
1689 .owner
= THIS_MODULE
,
1690 .llseek
= default_llseek
,
1693 int ath10k_debug_start(struct ath10k
*ar
)
1697 lockdep_assert_held(&ar
->conf_mutex
);
1699 ret
= ath10k_debug_htt_stats_req(ar
);
1701 /* continue normally anyway, this isn't serious */
1702 ath10k_warn(ar
, "failed to start htt stats workqueue: %d\n",
1705 if (ar
->debug
.fw_dbglog_mask
) {
1706 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1707 ATH10K_DBGLOG_LEVEL_WARN
);
1710 ath10k_warn(ar
, "failed to enable dbglog during start: %d",
1714 if (ar
->pktlog_filter
) {
1715 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
1720 "failed to enable pktlog filter %x: %d\n",
1721 ar
->pktlog_filter
, ret
);
1723 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1726 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1729 if (ar
->debug
.nf_cal_period
&&
1730 !test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1731 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
1732 ret
= ath10k_wmi_pdev_set_param(ar
,
1733 ar
->wmi
.pdev_param
->cal_period
,
1734 ar
->debug
.nf_cal_period
);
1737 ath10k_warn(ar
, "cal period cfg failed from debug start: %d\n",
1744 void ath10k_debug_stop(struct ath10k
*ar
)
1746 lockdep_assert_held(&ar
->conf_mutex
);
1748 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1749 ar
->normal_mode_fw
.fw_file
.fw_features
))
1750 ath10k_debug_cal_data_fetch(ar
);
1752 /* Must not use _sync to avoid deadlock, we do that in
1753 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1754 * warning from del_timer().
1756 if (ar
->debug
.htt_stats_mask
!= 0)
1757 cancel_delayed_work(&ar
->debug
.htt_stats_dwork
);
1759 ath10k_wmi_pdev_pktlog_disable(ar
);
1762 static ssize_t
ath10k_write_simulate_radar(struct file
*file
,
1763 const char __user
*user_buf
,
1764 size_t count
, loff_t
*ppos
)
1766 struct ath10k
*ar
= file
->private_data
;
1767 struct ath10k_vif
*arvif
;
1769 /* Just check for the first vif alone, as all the vifs will be
1770 * sharing the same channel and if the channel is disabled, all the
1771 * vifs will share the same 'is_started' state.
1773 arvif
= list_first_entry(&ar
->arvifs
, typeof(*arvif
), list
);
1774 if (!arvif
->is_started
)
1777 ieee80211_radar_detected(ar
->hw
, NULL
);
1782 static const struct file_operations fops_simulate_radar
= {
1783 .write
= ath10k_write_simulate_radar
,
1784 .open
= simple_open
,
1785 .owner
= THIS_MODULE
,
1786 .llseek
= default_llseek
,
1789 #define ATH10K_DFS_STAT(s, p) (\
1790 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1791 ar->debug.dfs_stats.p))
1793 #define ATH10K_DFS_POOL_STAT(s, p) (\
1794 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1795 ar->debug.dfs_pool_stats.p))
1797 static ssize_t
ath10k_read_dfs_stats(struct file
*file
, char __user
*user_buf
,
1798 size_t count
, loff_t
*ppos
)
1800 int retval
= 0, len
= 0;
1801 const int size
= 8000;
1802 struct ath10k
*ar
= file
->private_data
;
1805 buf
= kzalloc(size
, GFP_KERNEL
);
1809 if (!ar
->dfs_detector
) {
1810 len
+= scnprintf(buf
+ len
, size
- len
, "DFS not enabled\n");
1814 ar
->debug
.dfs_pool_stats
=
1815 ar
->dfs_detector
->get_stats(ar
->dfs_detector
);
1817 len
+= scnprintf(buf
+ len
, size
- len
, "Pulse detector statistics:\n");
1819 ATH10K_DFS_STAT("reported phy errors", phy_errors
);
1820 ATH10K_DFS_STAT("pulse events reported", pulses_total
);
1821 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected
);
1822 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded
);
1823 ATH10K_DFS_STAT("Radars detected", radar_detected
);
1825 len
+= scnprintf(buf
+ len
, size
- len
, "Global Pool statistics:\n");
1826 ATH10K_DFS_POOL_STAT("Pool references", pool_reference
);
1827 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated
);
1828 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error
);
1829 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used
);
1830 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated
);
1831 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error
);
1832 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used
);
1838 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1844 static const struct file_operations fops_dfs_stats
= {
1845 .read
= ath10k_read_dfs_stats
,
1846 .open
= simple_open
,
1847 .owner
= THIS_MODULE
,
1848 .llseek
= default_llseek
,
1851 static ssize_t
ath10k_write_pktlog_filter(struct file
*file
,
1852 const char __user
*ubuf
,
1853 size_t count
, loff_t
*ppos
)
1855 struct ath10k
*ar
= file
->private_data
;
1859 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
1862 mutex_lock(&ar
->conf_mutex
);
1864 if (ar
->state
!= ATH10K_STATE_ON
) {
1865 ar
->pktlog_filter
= filter
;
1870 if (filter
== ar
->pktlog_filter
) {
1876 ret
= ath10k_wmi_pdev_pktlog_enable(ar
, filter
);
1878 ath10k_warn(ar
, "failed to enable pktlog filter %x: %d\n",
1879 ar
->pktlog_filter
, ret
);
1883 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1885 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1890 ar
->pktlog_filter
= filter
;
1894 mutex_unlock(&ar
->conf_mutex
);
1898 static ssize_t
ath10k_read_pktlog_filter(struct file
*file
, char __user
*ubuf
,
1899 size_t count
, loff_t
*ppos
)
1902 struct ath10k
*ar
= file
->private_data
;
1905 mutex_lock(&ar
->conf_mutex
);
1906 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
1908 mutex_unlock(&ar
->conf_mutex
);
1910 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1913 static const struct file_operations fops_pktlog_filter
= {
1914 .read
= ath10k_read_pktlog_filter
,
1915 .write
= ath10k_write_pktlog_filter
,
1919 static ssize_t
ath10k_write_quiet_period(struct file
*file
,
1920 const char __user
*ubuf
,
1921 size_t count
, loff_t
*ppos
)
1923 struct ath10k
*ar
= file
->private_data
;
1926 if (kstrtouint_from_user(ubuf
, count
, 0, &period
))
1929 if (period
< ATH10K_QUIET_PERIOD_MIN
) {
1930 ath10k_warn(ar
, "Quiet period %u can not be lesser than 25ms\n",
1934 mutex_lock(&ar
->conf_mutex
);
1935 ar
->thermal
.quiet_period
= period
;
1936 ath10k_thermal_set_throttling(ar
);
1937 mutex_unlock(&ar
->conf_mutex
);
1942 static ssize_t
ath10k_read_quiet_period(struct file
*file
, char __user
*ubuf
,
1943 size_t count
, loff_t
*ppos
)
1946 struct ath10k
*ar
= file
->private_data
;
1949 mutex_lock(&ar
->conf_mutex
);
1950 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
1951 ar
->thermal
.quiet_period
);
1952 mutex_unlock(&ar
->conf_mutex
);
1954 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1957 static const struct file_operations fops_quiet_period
= {
1958 .read
= ath10k_read_quiet_period
,
1959 .write
= ath10k_write_quiet_period
,
1963 static ssize_t
ath10k_write_btcoex(struct file
*file
,
1964 const char __user
*ubuf
,
1965 size_t count
, loff_t
*ppos
)
1967 struct ath10k
*ar
= file
->private_data
;
1972 ret
= kstrtobool_from_user(ubuf
, count
, &val
);
1976 if (!ar
->coex_support
)
1979 mutex_lock(&ar
->conf_mutex
);
1981 if (ar
->state
!= ATH10K_STATE_ON
&&
1982 ar
->state
!= ATH10K_STATE_RESTARTED
) {
1987 if (!(test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
) ^ val
)) {
1992 pdev_param
= ar
->wmi
.pdev_param
->enable_btcoex
;
1993 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
1994 ar
->running_fw
->fw_file
.fw_features
)) {
1995 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
, val
);
1997 ath10k_warn(ar
, "failed to enable btcoex: %zd\n", ret
);
2002 ath10k_info(ar
, "restarting firmware due to btcoex change");
2003 ath10k_core_start_recovery(ar
);
2007 set_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2009 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2014 mutex_unlock(&ar
->conf_mutex
);
2019 static ssize_t
ath10k_read_btcoex(struct file
*file
, char __user
*ubuf
,
2020 size_t count
, loff_t
*ppos
)
2023 struct ath10k
*ar
= file
->private_data
;
2026 mutex_lock(&ar
->conf_mutex
);
2027 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2028 test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
));
2029 mutex_unlock(&ar
->conf_mutex
);
2031 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2034 static const struct file_operations fops_btcoex
= {
2035 .read
= ath10k_read_btcoex
,
2036 .write
= ath10k_write_btcoex
,
2040 static ssize_t
ath10k_write_enable_extd_tx_stats(struct file
*file
,
2041 const char __user
*ubuf
,
2042 size_t count
, loff_t
*ppos
)
2044 struct ath10k
*ar
= file
->private_data
;
2048 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
2051 mutex_lock(&ar
->conf_mutex
);
2053 if (ar
->state
!= ATH10K_STATE_ON
) {
2054 ar
->debug
.enable_extd_tx_stats
= filter
;
2059 if (filter
== ar
->debug
.enable_extd_tx_stats
) {
2064 ar
->debug
.enable_extd_tx_stats
= filter
;
2068 mutex_unlock(&ar
->conf_mutex
);
2072 static ssize_t
ath10k_read_enable_extd_tx_stats(struct file
*file
,
2074 size_t count
, loff_t
*ppos
)
2078 struct ath10k
*ar
= file
->private_data
;
2081 mutex_lock(&ar
->conf_mutex
);
2082 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
2083 ar
->debug
.enable_extd_tx_stats
);
2084 mutex_unlock(&ar
->conf_mutex
);
2086 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2089 static const struct file_operations fops_enable_extd_tx_stats
= {
2090 .read
= ath10k_read_enable_extd_tx_stats
,
2091 .write
= ath10k_write_enable_extd_tx_stats
,
2095 static ssize_t
ath10k_write_peer_stats(struct file
*file
,
2096 const char __user
*ubuf
,
2097 size_t count
, loff_t
*ppos
)
2099 struct ath10k
*ar
= file
->private_data
;
2103 ret
= kstrtobool_from_user(ubuf
, count
, &val
);
2107 mutex_lock(&ar
->conf_mutex
);
2109 if (ar
->state
!= ATH10K_STATE_ON
&&
2110 ar
->state
!= ATH10K_STATE_RESTARTED
) {
2115 if (!(test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
) ^ val
)) {
2121 set_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2123 clear_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2125 ath10k_info(ar
, "restarting firmware due to Peer stats change");
2127 ath10k_core_start_recovery(ar
);
2131 mutex_unlock(&ar
->conf_mutex
);
2135 static ssize_t
ath10k_read_peer_stats(struct file
*file
, char __user
*ubuf
,
2136 size_t count
, loff_t
*ppos
)
2140 struct ath10k
*ar
= file
->private_data
;
2143 mutex_lock(&ar
->conf_mutex
);
2144 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2145 test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
));
2146 mutex_unlock(&ar
->conf_mutex
);
2148 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2151 static const struct file_operations fops_peer_stats
= {
2152 .read
= ath10k_read_peer_stats
,
2153 .write
= ath10k_write_peer_stats
,
2157 static ssize_t
ath10k_debug_fw_checksums_read(struct file
*file
,
2158 char __user
*user_buf
,
2159 size_t count
, loff_t
*ppos
)
2161 struct ath10k
*ar
= file
->private_data
;
2162 size_t len
= 0, buf_len
= 4096;
2166 buf
= kzalloc(buf_len
, GFP_KERNEL
);
2170 mutex_lock(&ar
->conf_mutex
);
2172 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2173 "firmware-N.bin\t\t%08x\n",
2174 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware
->data
,
2175 ar
->normal_mode_fw
.fw_file
.firmware
->size
));
2176 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2177 "athwlan\t\t\t%08x\n",
2178 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware_data
,
2179 ar
->normal_mode_fw
.fw_file
.firmware_len
));
2180 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2182 crc32_le(0, ar
->normal_mode_fw
.fw_file
.otp_data
,
2183 ar
->normal_mode_fw
.fw_file
.otp_len
));
2184 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2185 "codeswap\t\t%08x\n",
2186 crc32_le(0, ar
->normal_mode_fw
.fw_file
.codeswap_data
,
2187 ar
->normal_mode_fw
.fw_file
.codeswap_len
));
2188 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2189 "board-N.bin\t\t%08x\n",
2190 crc32_le(0, ar
->normal_mode_fw
.board
->data
,
2191 ar
->normal_mode_fw
.board
->size
));
2192 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2193 "board\t\t\t%08x\n",
2194 crc32_le(0, ar
->normal_mode_fw
.board_data
,
2195 ar
->normal_mode_fw
.board_len
));
2197 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2199 mutex_unlock(&ar
->conf_mutex
);
2205 static const struct file_operations fops_fw_checksums
= {
2206 .read
= ath10k_debug_fw_checksums_read
,
2207 .open
= simple_open
,
2208 .owner
= THIS_MODULE
,
2209 .llseek
= default_llseek
,
2212 static ssize_t
ath10k_sta_tid_stats_mask_read(struct file
*file
,
2213 char __user
*user_buf
,
2214 size_t count
, loff_t
*ppos
)
2216 struct ath10k
*ar
= file
->private_data
;
2220 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->sta_tid_stats_mask
);
2221 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2224 static ssize_t
ath10k_sta_tid_stats_mask_write(struct file
*file
,
2225 const char __user
*user_buf
,
2226 size_t count
, loff_t
*ppos
)
2228 struct ath10k
*ar
= file
->private_data
;
2232 ret
= kstrtoint_from_user(user_buf
, count
, 0, &mask
);
2236 ar
->sta_tid_stats_mask
= mask
;
2241 static const struct file_operations fops_sta_tid_stats_mask
= {
2242 .read
= ath10k_sta_tid_stats_mask_read
,
2243 .write
= ath10k_sta_tid_stats_mask_write
,
2244 .open
= simple_open
,
2245 .owner
= THIS_MODULE
,
2246 .llseek
= default_llseek
,
2249 static int ath10k_debug_tpc_stats_final_request(struct ath10k
*ar
)
2252 unsigned long time_left
;
2254 lockdep_assert_held(&ar
->conf_mutex
);
2256 reinit_completion(&ar
->debug
.tpc_complete
);
2258 ret
= ath10k_wmi_pdev_get_tpc_table_cmdid(ar
, WMI_TPC_CONFIG_PARAM
);
2260 ath10k_warn(ar
, "failed to request tpc table cmdid: %d\n", ret
);
2264 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
2272 static int ath10k_tpc_stats_final_open(struct inode
*inode
, struct file
*file
)
2274 struct ath10k
*ar
= inode
->i_private
;
2278 mutex_lock(&ar
->conf_mutex
);
2280 if (ar
->state
!= ATH10K_STATE_ON
) {
2285 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
2291 ret
= ath10k_debug_tpc_stats_final_request(ar
);
2293 ath10k_warn(ar
, "failed to request tpc stats final: %d\n",
2298 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
2299 file
->private_data
= buf
;
2301 mutex_unlock(&ar
->conf_mutex
);
2308 mutex_unlock(&ar
->conf_mutex
);
2312 static int ath10k_tpc_stats_final_release(struct inode
*inode
,
2315 vfree(file
->private_data
);
2320 static ssize_t
ath10k_tpc_stats_final_read(struct file
*file
,
2321 char __user
*user_buf
,
2322 size_t count
, loff_t
*ppos
)
2324 const char *buf
= file
->private_data
;
2325 unsigned int len
= strlen(buf
);
2327 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2330 static const struct file_operations fops_tpc_stats_final
= {
2331 .open
= ath10k_tpc_stats_final_open
,
2332 .release
= ath10k_tpc_stats_final_release
,
2333 .read
= ath10k_tpc_stats_final_read
,
2334 .owner
= THIS_MODULE
,
2335 .llseek
= default_llseek
,
2338 static ssize_t
ath10k_write_warm_hw_reset(struct file
*file
,
2339 const char __user
*user_buf
,
2340 size_t count
, loff_t
*ppos
)
2342 struct ath10k
*ar
= file
->private_data
;
2346 if (kstrtobool_from_user(user_buf
, count
, &val
))
2352 mutex_lock(&ar
->conf_mutex
);
2354 if (ar
->state
!= ATH10K_STATE_ON
) {
2359 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pdev_reset
,
2360 WMI_RST_MODE_WARM_RESET
);
2363 ath10k_warn(ar
, "failed to enable warm hw reset: %d\n", ret
);
2370 mutex_unlock(&ar
->conf_mutex
);
2374 static const struct file_operations fops_warm_hw_reset
= {
2375 .write
= ath10k_write_warm_hw_reset
,
2376 .open
= simple_open
,
2377 .owner
= THIS_MODULE
,
2378 .llseek
= default_llseek
,
2381 static void ath10k_peer_ps_state_disable(void *data
,
2382 struct ieee80211_sta
*sta
)
2384 struct ath10k
*ar
= data
;
2385 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
2387 spin_lock_bh(&ar
->data_lock
);
2388 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
2389 spin_unlock_bh(&ar
->data_lock
);
2392 static ssize_t
ath10k_write_ps_state_enable(struct file
*file
,
2393 const char __user
*user_buf
,
2394 size_t count
, loff_t
*ppos
)
2396 struct ath10k
*ar
= file
->private_data
;
2401 if (kstrtou8_from_user(user_buf
, count
, 0, &ps_state_enable
))
2404 if (ps_state_enable
> 1)
2407 mutex_lock(&ar
->conf_mutex
);
2409 if (ar
->ps_state_enable
== ps_state_enable
) {
2414 param
= ar
->wmi
.pdev_param
->peer_sta_ps_statechg_enable
;
2415 ret
= ath10k_wmi_pdev_set_param(ar
, param
, ps_state_enable
);
2417 ath10k_warn(ar
, "failed to enable ps_state_enable: %d\n",
2421 ar
->ps_state_enable
= ps_state_enable
;
2423 if (!ar
->ps_state_enable
)
2424 ieee80211_iterate_stations_atomic(ar
->hw
,
2425 ath10k_peer_ps_state_disable
,
2431 mutex_unlock(&ar
->conf_mutex
);
2436 static ssize_t
ath10k_read_ps_state_enable(struct file
*file
,
2437 char __user
*user_buf
,
2438 size_t count
, loff_t
*ppos
)
2440 struct ath10k
*ar
= file
->private_data
;
2444 mutex_lock(&ar
->conf_mutex
);
2445 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2446 ar
->ps_state_enable
);
2447 mutex_unlock(&ar
->conf_mutex
);
2449 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2452 static const struct file_operations fops_ps_state_enable
= {
2453 .read
= ath10k_read_ps_state_enable
,
2454 .write
= ath10k_write_ps_state_enable
,
2455 .open
= simple_open
,
2456 .owner
= THIS_MODULE
,
2457 .llseek
= default_llseek
,
2460 static ssize_t
ath10k_write_reset_htt_stats(struct file
*file
,
2461 const char __user
*user_buf
,
2462 size_t count
, loff_t
*ppos
)
2464 struct ath10k
*ar
= file
->private_data
;
2465 unsigned long reset
;
2468 ret
= kstrtoul_from_user(user_buf
, count
, 0, &reset
);
2472 if (reset
== 0 || reset
> 0x1ffff)
2475 mutex_lock(&ar
->conf_mutex
);
2477 ar
->debug
.reset_htt_stats
= reset
;
2479 ret
= ath10k_debug_htt_stats_req(ar
);
2483 ar
->debug
.reset_htt_stats
= 0;
2487 mutex_unlock(&ar
->conf_mutex
);
2491 static const struct file_operations fops_reset_htt_stats
= {
2492 .write
= ath10k_write_reset_htt_stats
,
2493 .owner
= THIS_MODULE
,
2494 .open
= simple_open
,
2495 .llseek
= default_llseek
,
2498 int ath10k_debug_create(struct ath10k
*ar
)
2500 ar
->debug
.cal_data
= vzalloc(ATH10K_DEBUG_CAL_DATA_LEN
);
2501 if (!ar
->debug
.cal_data
)
2504 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.pdevs
);
2505 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.vdevs
);
2506 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers
);
2507 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers_extd
);
2512 void ath10k_debug_destroy(struct ath10k
*ar
)
2514 vfree(ar
->debug
.cal_data
);
2515 ar
->debug
.cal_data
= NULL
;
2517 ath10k_debug_fw_stats_reset(ar
);
2519 kfree(ar
->debug
.tpc_stats
);
2520 kfree(ar
->debug
.tpc_stats_final
);
2523 int ath10k_debug_register(struct ath10k
*ar
)
2525 ar
->debug
.debugfs_phy
= debugfs_create_dir("ath10k",
2526 ar
->hw
->wiphy
->debugfsdir
);
2527 if (IS_ERR_OR_NULL(ar
->debug
.debugfs_phy
)) {
2528 if (IS_ERR(ar
->debug
.debugfs_phy
))
2529 return PTR_ERR(ar
->debug
.debugfs_phy
);
2534 INIT_DELAYED_WORK(&ar
->debug
.htt_stats_dwork
,
2535 ath10k_debug_htt_stats_dwork
);
2537 init_completion(&ar
->debug
.tpc_complete
);
2538 init_completion(&ar
->debug
.fw_stats_complete
);
2540 debugfs_create_file("fw_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2543 debugfs_create_file("fw_reset_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2544 &fops_fw_reset_stats
);
2546 debugfs_create_file("wmi_services", 0400, ar
->debug
.debugfs_phy
, ar
,
2547 &fops_wmi_services
);
2549 debugfs_create_file("simulate_fw_crash", 0600, ar
->debug
.debugfs_phy
, ar
,
2550 &fops_simulate_fw_crash
);
2552 debugfs_create_file("reg_addr", 0600, ar
->debug
.debugfs_phy
, ar
,
2555 debugfs_create_file("reg_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2558 debugfs_create_file("mem_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2561 debugfs_create_file("chip_id", 0400, ar
->debug
.debugfs_phy
, ar
,
2564 debugfs_create_file("htt_stats_mask", 0600, ar
->debug
.debugfs_phy
, ar
,
2565 &fops_htt_stats_mask
);
2567 debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar
->debug
.debugfs_phy
, ar
,
2568 &fops_htt_max_amsdu_ampdu
);
2570 debugfs_create_file("fw_dbglog", 0600, ar
->debug
.debugfs_phy
, ar
,
2573 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
2574 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
2575 debugfs_create_file("cal_data", 0400, ar
->debug
.debugfs_phy
, ar
,
2578 debugfs_create_file("nf_cal_period", 0600, ar
->debug
.debugfs_phy
, ar
,
2579 &fops_nf_cal_period
);
2582 debugfs_create_file("ani_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2585 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
2586 debugfs_create_file("dfs_simulate_radar", 0200, ar
->debug
.debugfs_phy
,
2587 ar
, &fops_simulate_radar
);
2589 debugfs_create_bool("dfs_block_radar_events", 0200,
2590 ar
->debug
.debugfs_phy
,
2591 &ar
->dfs_block_radar_events
);
2593 debugfs_create_file("dfs_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2597 debugfs_create_file("pktlog_filter", 0644, ar
->debug
.debugfs_phy
, ar
,
2598 &fops_pktlog_filter
);
2600 if (test_bit(WMI_SERVICE_THERM_THROT
, ar
->wmi
.svc_map
))
2601 debugfs_create_file("quiet_period", 0644, ar
->debug
.debugfs_phy
, ar
,
2602 &fops_quiet_period
);
2604 debugfs_create_file("tpc_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2607 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
))
2608 debugfs_create_file("btcoex", 0644, ar
->debug
.debugfs_phy
, ar
,
2611 if (test_bit(WMI_SERVICE_PEER_STATS
, ar
->wmi
.svc_map
)) {
2612 debugfs_create_file("peer_stats", 0644, ar
->debug
.debugfs_phy
, ar
,
2615 debugfs_create_file("enable_extd_tx_stats", 0644,
2616 ar
->debug
.debugfs_phy
, ar
,
2617 &fops_enable_extd_tx_stats
);
2620 debugfs_create_file("fw_checksums", 0400, ar
->debug
.debugfs_phy
, ar
,
2621 &fops_fw_checksums
);
2623 if (IS_ENABLED(CONFIG_MAC80211_DEBUGFS
))
2624 debugfs_create_file("sta_tid_stats_mask", 0600,
2625 ar
->debug
.debugfs_phy
,
2626 ar
, &fops_sta_tid_stats_mask
);
2628 if (test_bit(WMI_SERVICE_TPC_STATS_FINAL
, ar
->wmi
.svc_map
))
2629 debugfs_create_file("tpc_stats_final", 0400,
2630 ar
->debug
.debugfs_phy
, ar
,
2631 &fops_tpc_stats_final
);
2633 if (test_bit(WMI_SERVICE_RESET_CHIP
, ar
->wmi
.svc_map
))
2634 debugfs_create_file("warm_hw_reset", 0600,
2635 ar
->debug
.debugfs_phy
, ar
,
2636 &fops_warm_hw_reset
);
2638 debugfs_create_file("ps_state_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2639 &fops_ps_state_enable
);
2641 debugfs_create_file("reset_htt_stats", 0200, ar
->debug
.debugfs_phy
, ar
,
2642 &fops_reset_htt_stats
);
2647 void ath10k_debug_unregister(struct ath10k
*ar
)
2649 cancel_delayed_work_sync(&ar
->debug
.htt_stats_dwork
);
2652 #endif /* CONFIG_ATH10K_DEBUGFS */
2654 #ifdef CONFIG_ATH10K_DEBUG
2655 void __ath10k_dbg(struct ath10k
*ar
, enum ath10k_debug_mask mask
,
2656 const char *fmt
, ...)
2658 struct va_format vaf
;
2661 va_start(args
, fmt
);
2666 if (ath10k_debug_mask
& mask
)
2667 dev_printk(KERN_DEBUG
, ar
->dev
, "%pV", &vaf
);
2669 trace_ath10k_log_dbg(ar
, mask
, &vaf
);
2673 EXPORT_SYMBOL(__ath10k_dbg
);
2675 void ath10k_dbg_dump(struct ath10k
*ar
,
2676 enum ath10k_debug_mask mask
,
2677 const char *msg
, const char *prefix
,
2678 const void *buf
, size_t len
)
2684 if (ath10k_debug_mask
& mask
) {
2686 __ath10k_dbg(ar
, mask
, "%s\n", msg
);
2688 for (ptr
= buf
; (ptr
- buf
) < len
; ptr
+= 16) {
2690 linebuflen
+= scnprintf(linebuf
+ linebuflen
,
2691 sizeof(linebuf
) - linebuflen
,
2693 (prefix
? prefix
: ""),
2694 (unsigned int)(ptr
- buf
));
2695 hex_dump_to_buffer(ptr
, len
- (ptr
- buf
), 16, 1,
2696 linebuf
+ linebuflen
,
2697 sizeof(linebuf
) - linebuflen
, true);
2698 dev_printk(KERN_DEBUG
, ar
->dev
, "%s\n", linebuf
);
2702 /* tracing code doesn't like null strings :/ */
2703 trace_ath10k_log_dbg_dump(ar
, msg
? msg
: "", prefix
? prefix
: "",
2706 EXPORT_SYMBOL(ath10k_dbg_dump
);
2708 #endif /* CONFIG_ATH10K_DEBUG */