2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <linux/module.h>
20 #include <linux/debugfs.h>
21 #include <linux/vmalloc.h>
22 #include <linux/crc32.h>
23 #include <linux/firmware.h>
31 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
33 #define ATH10K_DEBUG_CAL_DATA_LEN 12064
35 void ath10k_info(struct ath10k
*ar
, const char *fmt
, ...)
37 struct va_format vaf
= {
44 dev_info(ar
->dev
, "%pV", &vaf
);
45 trace_ath10k_log_info(ar
, &vaf
);
48 EXPORT_SYMBOL(ath10k_info
);
50 void ath10k_debug_print_hwfw_info(struct ath10k
*ar
)
52 const struct firmware
*firmware
;
53 char fw_features
[128] = {};
56 ath10k_core_get_fw_features_str(ar
, fw_features
, sizeof(fw_features
));
58 ath10k_info(ar
, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
62 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
64 ath10k_info(ar
, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
65 IS_ENABLED(CONFIG_ATH10K_DEBUG
),
66 IS_ENABLED(CONFIG_ATH10K_DEBUGFS
),
67 IS_ENABLED(CONFIG_ATH10K_TRACING
),
68 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
),
69 IS_ENABLED(CONFIG_NL80211_TESTMODE
));
71 firmware
= ar
->normal_mode_fw
.fw_file
.firmware
;
73 crc
= crc32_le(0, firmware
->data
, firmware
->size
);
75 ath10k_info(ar
, "firmware ver %s api %d features %s crc32 %08x\n",
76 ar
->hw
->wiphy
->fw_version
,
82 void ath10k_debug_print_board_info(struct ath10k
*ar
)
85 const struct firmware
*board
;
88 if (ar
->id
.bmi_ids_valid
)
89 scnprintf(boardinfo
, sizeof(boardinfo
), "%d:%d",
90 ar
->id
.bmi_chip_id
, ar
->id
.bmi_board_id
);
92 scnprintf(boardinfo
, sizeof(boardinfo
), "N/A");
94 board
= ar
->normal_mode_fw
.board
;
95 if (!IS_ERR_OR_NULL(board
))
96 crc
= crc32_le(0, board
->data
, board
->size
);
100 ath10k_info(ar
, "board_file api %d bmi_id %s crc32 %08x",
106 void ath10k_debug_print_boot_info(struct ath10k
*ar
)
108 ath10k_info(ar
, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
109 ar
->htt
.target_version_major
,
110 ar
->htt
.target_version_minor
,
111 ar
->normal_mode_fw
.fw_file
.wmi_op_version
,
112 ar
->normal_mode_fw
.fw_file
.htt_op_version
,
113 ath10k_cal_mode_str(ar
->cal_mode
),
114 ar
->max_num_stations
,
115 test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
),
116 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
));
119 void ath10k_print_driver_info(struct ath10k
*ar
)
121 ath10k_debug_print_hwfw_info(ar
);
122 ath10k_debug_print_board_info(ar
);
123 ath10k_debug_print_boot_info(ar
);
125 EXPORT_SYMBOL(ath10k_print_driver_info
);
127 void ath10k_err(struct ath10k
*ar
, const char *fmt
, ...)
129 struct va_format vaf
= {
136 dev_err(ar
->dev
, "%pV", &vaf
);
137 trace_ath10k_log_err(ar
, &vaf
);
140 EXPORT_SYMBOL(ath10k_err
);
142 void ath10k_warn(struct ath10k
*ar
, const char *fmt
, ...)
144 struct va_format vaf
= {
151 dev_warn_ratelimited(ar
->dev
, "%pV", &vaf
);
152 trace_ath10k_log_warn(ar
, &vaf
);
156 EXPORT_SYMBOL(ath10k_warn
);
158 #ifdef CONFIG_ATH10K_DEBUGFS
160 static ssize_t
ath10k_read_wmi_services(struct file
*file
,
161 char __user
*user_buf
,
162 size_t count
, loff_t
*ppos
)
164 struct ath10k
*ar
= file
->private_data
;
166 size_t len
= 0, buf_len
= 8192;
172 buf
= kzalloc(buf_len
, GFP_KERNEL
);
176 mutex_lock(&ar
->conf_mutex
);
178 spin_lock_bh(&ar
->data_lock
);
179 for (i
= 0; i
< WMI_SERVICE_MAX
; i
++) {
180 enabled
= test_bit(i
, ar
->wmi
.svc_map
);
181 name
= wmi_service_name(i
);
185 len
+= scnprintf(buf
+ len
, buf_len
- len
,
186 "%-40s %s (bit %d)\n",
187 "unknown", "enabled", i
);
192 len
+= scnprintf(buf
+ len
, buf_len
- len
,
194 name
, enabled
? "enabled" : "-");
196 spin_unlock_bh(&ar
->data_lock
);
198 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
200 mutex_unlock(&ar
->conf_mutex
);
206 static const struct file_operations fops_wmi_services
= {
207 .read
= ath10k_read_wmi_services
,
209 .owner
= THIS_MODULE
,
210 .llseek
= default_llseek
,
213 static void ath10k_fw_stats_pdevs_free(struct list_head
*head
)
215 struct ath10k_fw_stats_pdev
*i
, *tmp
;
217 list_for_each_entry_safe(i
, tmp
, head
, list
) {
223 static void ath10k_fw_stats_vdevs_free(struct list_head
*head
)
225 struct ath10k_fw_stats_vdev
*i
, *tmp
;
227 list_for_each_entry_safe(i
, tmp
, head
, list
) {
233 static void ath10k_fw_stats_peers_free(struct list_head
*head
)
235 struct ath10k_fw_stats_peer
*i
, *tmp
;
237 list_for_each_entry_safe(i
, tmp
, head
, list
) {
243 static void ath10k_fw_extd_stats_peers_free(struct list_head
*head
)
245 struct ath10k_fw_extd_stats_peer
*i
, *tmp
;
247 list_for_each_entry_safe(i
, tmp
, head
, list
) {
253 static void ath10k_debug_fw_stats_reset(struct ath10k
*ar
)
255 spin_lock_bh(&ar
->data_lock
);
256 ar
->debug
.fw_stats_done
= false;
257 ar
->debug
.fw_stats
.extended
= false;
258 ath10k_fw_stats_pdevs_free(&ar
->debug
.fw_stats
.pdevs
);
259 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
260 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
261 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
262 spin_unlock_bh(&ar
->data_lock
);
265 void ath10k_debug_fw_stats_process(struct ath10k
*ar
, struct sk_buff
*skb
)
267 struct ath10k_fw_stats stats
= {};
268 bool is_start
, is_started
, is_end
;
273 INIT_LIST_HEAD(&stats
.pdevs
);
274 INIT_LIST_HEAD(&stats
.vdevs
);
275 INIT_LIST_HEAD(&stats
.peers
);
276 INIT_LIST_HEAD(&stats
.peers_extd
);
278 spin_lock_bh(&ar
->data_lock
);
279 ret
= ath10k_wmi_pull_fw_stats(ar
, skb
, &stats
);
281 ath10k_warn(ar
, "failed to pull fw stats: %d\n", ret
);
285 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
286 * splits the stats data and delivers it in a ping-pong fashion of
287 * request cmd-update event.
289 * However there is no explicit end-of-data. Instead start-of-data is
290 * used as an implicit one. This works as follows:
291 * a) discard stat update events until one with pdev stats is
292 * delivered - this skips session started at end of (b)
293 * b) consume stat update events until another one with pdev stats is
294 * delivered which is treated as end-of-data and is itself discarded
296 if (ath10k_peer_stats_enabled(ar
))
297 ath10k_sta_update_rx_duration(ar
, &stats
);
299 if (ar
->debug
.fw_stats_done
) {
300 if (!ath10k_peer_stats_enabled(ar
))
301 ath10k_warn(ar
, "received unsolicited stats update event\n");
306 num_peers
= ath10k_wmi_fw_stats_num_peers(&ar
->debug
.fw_stats
.peers
);
307 num_vdevs
= ath10k_wmi_fw_stats_num_vdevs(&ar
->debug
.fw_stats
.vdevs
);
308 is_start
= (list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
309 !list_empty(&stats
.pdevs
));
310 is_end
= (!list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
311 !list_empty(&stats
.pdevs
));
314 list_splice_tail_init(&stats
.pdevs
, &ar
->debug
.fw_stats
.pdevs
);
317 ar
->debug
.fw_stats_done
= true;
319 is_started
= !list_empty(&ar
->debug
.fw_stats
.pdevs
);
321 if (is_started
&& !is_end
) {
322 if (num_peers
>= ATH10K_MAX_NUM_PEER_IDS
) {
323 /* Although this is unlikely impose a sane limit to
324 * prevent firmware from DoS-ing the host.
326 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
327 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
328 ath10k_warn(ar
, "dropping fw peer stats\n");
332 if (num_vdevs
>= BITS_PER_LONG
) {
333 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
334 ath10k_warn(ar
, "dropping fw vdev stats\n");
338 if (!list_empty(&stats
.peers
))
339 list_splice_tail_init(&stats
.peers_extd
,
340 &ar
->debug
.fw_stats
.peers_extd
);
342 list_splice_tail_init(&stats
.peers
, &ar
->debug
.fw_stats
.peers
);
343 list_splice_tail_init(&stats
.vdevs
, &ar
->debug
.fw_stats
.vdevs
);
346 complete(&ar
->debug
.fw_stats_complete
);
349 /* In some cases lists have been spliced and cleared. Free up
350 * resources if that is not the case.
352 ath10k_fw_stats_pdevs_free(&stats
.pdevs
);
353 ath10k_fw_stats_vdevs_free(&stats
.vdevs
);
354 ath10k_fw_stats_peers_free(&stats
.peers
);
355 ath10k_fw_extd_stats_peers_free(&stats
.peers_extd
);
357 spin_unlock_bh(&ar
->data_lock
);
360 static int ath10k_debug_fw_stats_request(struct ath10k
*ar
)
362 unsigned long timeout
, time_left
;
365 lockdep_assert_held(&ar
->conf_mutex
);
367 timeout
= jiffies
+ msecs_to_jiffies(1 * HZ
);
369 ath10k_debug_fw_stats_reset(ar
);
372 if (time_after(jiffies
, timeout
))
375 reinit_completion(&ar
->debug
.fw_stats_complete
);
377 ret
= ath10k_wmi_request_stats(ar
, ar
->fw_stats_req_mask
);
379 ath10k_warn(ar
, "could not request stats (%d)\n", ret
);
384 wait_for_completion_timeout(&ar
->debug
.fw_stats_complete
,
389 spin_lock_bh(&ar
->data_lock
);
390 if (ar
->debug
.fw_stats_done
) {
391 spin_unlock_bh(&ar
->data_lock
);
394 spin_unlock_bh(&ar
->data_lock
);
400 static int ath10k_fw_stats_open(struct inode
*inode
, struct file
*file
)
402 struct ath10k
*ar
= inode
->i_private
;
406 mutex_lock(&ar
->conf_mutex
);
408 if (ar
->state
!= ATH10K_STATE_ON
) {
413 buf
= vmalloc(ATH10K_FW_STATS_BUF_SIZE
);
419 ret
= ath10k_debug_fw_stats_request(ar
);
421 ath10k_warn(ar
, "failed to request fw stats: %d\n", ret
);
425 ret
= ath10k_wmi_fw_stats_fill(ar
, &ar
->debug
.fw_stats
, buf
);
427 ath10k_warn(ar
, "failed to fill fw stats: %d\n", ret
);
431 file
->private_data
= buf
;
433 mutex_unlock(&ar
->conf_mutex
);
440 mutex_unlock(&ar
->conf_mutex
);
444 static int ath10k_fw_stats_release(struct inode
*inode
, struct file
*file
)
446 vfree(file
->private_data
);
451 static ssize_t
ath10k_fw_stats_read(struct file
*file
, char __user
*user_buf
,
452 size_t count
, loff_t
*ppos
)
454 const char *buf
= file
->private_data
;
455 size_t len
= strlen(buf
);
457 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
460 static const struct file_operations fops_fw_stats
= {
461 .open
= ath10k_fw_stats_open
,
462 .release
= ath10k_fw_stats_release
,
463 .read
= ath10k_fw_stats_read
,
464 .owner
= THIS_MODULE
,
465 .llseek
= default_llseek
,
468 static ssize_t
ath10k_debug_fw_reset_stats_read(struct file
*file
,
469 char __user
*user_buf
,
470 size_t count
, loff_t
*ppos
)
472 struct ath10k
*ar
= file
->private_data
;
474 size_t len
= 0, buf_len
= 500;
477 buf
= kmalloc(buf_len
, GFP_KERNEL
);
481 spin_lock_bh(&ar
->data_lock
);
483 len
+= scnprintf(buf
+ len
, buf_len
- len
,
484 "fw_crash_counter\t\t%d\n", ar
->stats
.fw_crash_counter
);
485 len
+= scnprintf(buf
+ len
, buf_len
- len
,
486 "fw_warm_reset_counter\t\t%d\n",
487 ar
->stats
.fw_warm_reset_counter
);
488 len
+= scnprintf(buf
+ len
, buf_len
- len
,
489 "fw_cold_reset_counter\t\t%d\n",
490 ar
->stats
.fw_cold_reset_counter
);
492 spin_unlock_bh(&ar
->data_lock
);
494 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
501 static const struct file_operations fops_fw_reset_stats
= {
503 .read
= ath10k_debug_fw_reset_stats_read
,
504 .owner
= THIS_MODULE
,
505 .llseek
= default_llseek
,
508 /* This is a clean assert crash in firmware. */
509 static int ath10k_debug_fw_assert(struct ath10k
*ar
)
511 struct wmi_vdev_install_key_cmd
*cmd
;
514 skb
= ath10k_wmi_alloc_skb(ar
, sizeof(*cmd
) + 16);
518 cmd
= (struct wmi_vdev_install_key_cmd
*)skb
->data
;
519 memset(cmd
, 0, sizeof(*cmd
));
521 /* big enough number so that firmware asserts */
522 cmd
->vdev_id
= __cpu_to_le32(0x7ffe);
524 return ath10k_wmi_cmd_send(ar
, skb
,
525 ar
->wmi
.cmd
->vdev_install_key_cmdid
);
528 static ssize_t
ath10k_read_simulate_fw_crash(struct file
*file
,
529 char __user
*user_buf
,
530 size_t count
, loff_t
*ppos
)
533 "To simulate firmware crash write one of the keywords to this file:\n"
534 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
535 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
536 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
537 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
539 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
542 /* Simulate firmware crash:
543 * 'soft': Call wmi command causing firmware hang. This firmware hang is
544 * recoverable by warm firmware reset.
545 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
546 * vdev id. This is hard firmware crash because it is recoverable only by cold
549 static ssize_t
ath10k_write_simulate_fw_crash(struct file
*file
,
550 const char __user
*user_buf
,
551 size_t count
, loff_t
*ppos
)
553 struct ath10k
*ar
= file
->private_data
;
558 /* filter partial writes and invalid commands */
559 if (*ppos
!= 0 || count
>= sizeof(buf
) || count
== 0)
562 rc
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
566 /* drop the possible '\n' from the end */
567 if (buf
[*ppos
- 1] == '\n')
568 buf
[*ppos
- 1] = '\0';
570 mutex_lock(&ar
->conf_mutex
);
572 if (ar
->state
!= ATH10K_STATE_ON
&&
573 ar
->state
!= ATH10K_STATE_RESTARTED
) {
578 if (!strcmp(buf
, "soft")) {
579 ath10k_info(ar
, "simulating soft firmware crash\n");
580 ret
= ath10k_wmi_force_fw_hang(ar
, WMI_FORCE_FW_HANG_ASSERT
, 0);
581 } else if (!strcmp(buf
, "hard")) {
582 ath10k_info(ar
, "simulating hard firmware crash\n");
583 /* 0x7fff is vdev id, and it is always out of range for all
584 * firmware variants in order to force a firmware crash.
586 ret
= ath10k_wmi_vdev_set_param(ar
, 0x7fff,
587 ar
->wmi
.vdev_param
->rts_threshold
,
589 } else if (!strcmp(buf
, "assert")) {
590 ath10k_info(ar
, "simulating firmware assert crash\n");
591 ret
= ath10k_debug_fw_assert(ar
);
592 } else if (!strcmp(buf
, "hw-restart")) {
593 ath10k_info(ar
, "user requested hw restart\n");
594 queue_work(ar
->workqueue
, &ar
->restart_work
);
602 ath10k_warn(ar
, "failed to simulate firmware crash: %d\n", ret
);
609 mutex_unlock(&ar
->conf_mutex
);
613 static const struct file_operations fops_simulate_fw_crash
= {
614 .read
= ath10k_read_simulate_fw_crash
,
615 .write
= ath10k_write_simulate_fw_crash
,
617 .owner
= THIS_MODULE
,
618 .llseek
= default_llseek
,
621 static ssize_t
ath10k_read_chip_id(struct file
*file
, char __user
*user_buf
,
622 size_t count
, loff_t
*ppos
)
624 struct ath10k
*ar
= file
->private_data
;
628 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->chip_id
);
630 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
633 static const struct file_operations fops_chip_id
= {
634 .read
= ath10k_read_chip_id
,
636 .owner
= THIS_MODULE
,
637 .llseek
= default_llseek
,
640 static ssize_t
ath10k_reg_addr_read(struct file
*file
,
641 char __user
*user_buf
,
642 size_t count
, loff_t
*ppos
)
644 struct ath10k
*ar
= file
->private_data
;
649 mutex_lock(&ar
->conf_mutex
);
650 reg_addr
= ar
->debug
.reg_addr
;
651 mutex_unlock(&ar
->conf_mutex
);
653 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "0x%x\n", reg_addr
);
655 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
658 static ssize_t
ath10k_reg_addr_write(struct file
*file
,
659 const char __user
*user_buf
,
660 size_t count
, loff_t
*ppos
)
662 struct ath10k
*ar
= file
->private_data
;
666 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_addr
);
670 if (!IS_ALIGNED(reg_addr
, 4))
673 mutex_lock(&ar
->conf_mutex
);
674 ar
->debug
.reg_addr
= reg_addr
;
675 mutex_unlock(&ar
->conf_mutex
);
680 static const struct file_operations fops_reg_addr
= {
681 .read
= ath10k_reg_addr_read
,
682 .write
= ath10k_reg_addr_write
,
684 .owner
= THIS_MODULE
,
685 .llseek
= default_llseek
,
688 static ssize_t
ath10k_reg_value_read(struct file
*file
,
689 char __user
*user_buf
,
690 size_t count
, loff_t
*ppos
)
692 struct ath10k
*ar
= file
->private_data
;
695 u32 reg_addr
, reg_val
;
698 mutex_lock(&ar
->conf_mutex
);
700 if (ar
->state
!= ATH10K_STATE_ON
&&
701 ar
->state
!= ATH10K_STATE_UTF
) {
706 reg_addr
= ar
->debug
.reg_addr
;
708 reg_val
= ath10k_hif_read32(ar
, reg_addr
);
709 len
= scnprintf(buf
, sizeof(buf
), "0x%08x:0x%08x\n", reg_addr
, reg_val
);
711 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
714 mutex_unlock(&ar
->conf_mutex
);
719 static ssize_t
ath10k_reg_value_write(struct file
*file
,
720 const char __user
*user_buf
,
721 size_t count
, loff_t
*ppos
)
723 struct ath10k
*ar
= file
->private_data
;
724 u32 reg_addr
, reg_val
;
727 mutex_lock(&ar
->conf_mutex
);
729 if (ar
->state
!= ATH10K_STATE_ON
&&
730 ar
->state
!= ATH10K_STATE_UTF
) {
735 reg_addr
= ar
->debug
.reg_addr
;
737 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_val
);
741 ath10k_hif_write32(ar
, reg_addr
, reg_val
);
746 mutex_unlock(&ar
->conf_mutex
);
751 static const struct file_operations fops_reg_value
= {
752 .read
= ath10k_reg_value_read
,
753 .write
= ath10k_reg_value_write
,
755 .owner
= THIS_MODULE
,
756 .llseek
= default_llseek
,
759 static ssize_t
ath10k_mem_value_read(struct file
*file
,
760 char __user
*user_buf
,
761 size_t count
, loff_t
*ppos
)
763 struct ath10k
*ar
= file
->private_data
;
773 mutex_lock(&ar
->conf_mutex
);
775 buf
= vmalloc(count
);
781 if (ar
->state
!= ATH10K_STATE_ON
&&
782 ar
->state
!= ATH10K_STATE_UTF
) {
787 ret
= ath10k_hif_diag_read(ar
, *ppos
, buf
, count
);
789 ath10k_warn(ar
, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
794 ret
= copy_to_user(user_buf
, buf
, count
);
806 mutex_unlock(&ar
->conf_mutex
);
811 static ssize_t
ath10k_mem_value_write(struct file
*file
,
812 const char __user
*user_buf
,
813 size_t count
, loff_t
*ppos
)
815 struct ath10k
*ar
= file
->private_data
;
825 mutex_lock(&ar
->conf_mutex
);
827 buf
= vmalloc(count
);
833 if (ar
->state
!= ATH10K_STATE_ON
&&
834 ar
->state
!= ATH10K_STATE_UTF
) {
839 ret
= copy_from_user(buf
, user_buf
, count
);
845 ret
= ath10k_hif_diag_write(ar
, *ppos
, buf
, count
);
847 ath10k_warn(ar
, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
857 mutex_unlock(&ar
->conf_mutex
);
862 static const struct file_operations fops_mem_value
= {
863 .read
= ath10k_mem_value_read
,
864 .write
= ath10k_mem_value_write
,
866 .owner
= THIS_MODULE
,
867 .llseek
= default_llseek
,
870 static int ath10k_debug_htt_stats_req(struct ath10k
*ar
)
875 lockdep_assert_held(&ar
->conf_mutex
);
877 if (ar
->debug
.htt_stats_mask
== 0)
878 /* htt stats are disabled */
881 if (ar
->state
!= ATH10K_STATE_ON
)
884 cookie
= get_jiffies_64();
886 ret
= ath10k_htt_h2t_stats_req(&ar
->htt
, ar
->debug
.htt_stats_mask
,
889 ath10k_warn(ar
, "failed to send htt stats request: %d\n", ret
);
893 queue_delayed_work(ar
->workqueue
, &ar
->debug
.htt_stats_dwork
,
894 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL
));
899 static void ath10k_debug_htt_stats_dwork(struct work_struct
*work
)
901 struct ath10k
*ar
= container_of(work
, struct ath10k
,
902 debug
.htt_stats_dwork
.work
);
904 mutex_lock(&ar
->conf_mutex
);
906 ath10k_debug_htt_stats_req(ar
);
908 mutex_unlock(&ar
->conf_mutex
);
911 static ssize_t
ath10k_read_htt_stats_mask(struct file
*file
,
912 char __user
*user_buf
,
913 size_t count
, loff_t
*ppos
)
915 struct ath10k
*ar
= file
->private_data
;
919 len
= scnprintf(buf
, sizeof(buf
), "%lu\n", ar
->debug
.htt_stats_mask
);
921 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
924 static ssize_t
ath10k_write_htt_stats_mask(struct file
*file
,
925 const char __user
*user_buf
,
926 size_t count
, loff_t
*ppos
)
928 struct ath10k
*ar
= file
->private_data
;
932 ret
= kstrtoul_from_user(user_buf
, count
, 0, &mask
);
936 /* max 8 bit masks (for now) */
940 mutex_lock(&ar
->conf_mutex
);
942 ar
->debug
.htt_stats_mask
= mask
;
944 ret
= ath10k_debug_htt_stats_req(ar
);
951 mutex_unlock(&ar
->conf_mutex
);
956 static const struct file_operations fops_htt_stats_mask
= {
957 .read
= ath10k_read_htt_stats_mask
,
958 .write
= ath10k_write_htt_stats_mask
,
960 .owner
= THIS_MODULE
,
961 .llseek
= default_llseek
,
964 static ssize_t
ath10k_read_htt_max_amsdu_ampdu(struct file
*file
,
965 char __user
*user_buf
,
966 size_t count
, loff_t
*ppos
)
968 struct ath10k
*ar
= file
->private_data
;
973 mutex_lock(&ar
->conf_mutex
);
975 amsdu
= ar
->htt
.max_num_amsdu
;
976 ampdu
= ar
->htt
.max_num_ampdu
;
977 mutex_unlock(&ar
->conf_mutex
);
979 len
= scnprintf(buf
, sizeof(buf
), "%u %u\n", amsdu
, ampdu
);
981 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
984 static ssize_t
ath10k_write_htt_max_amsdu_ampdu(struct file
*file
,
985 const char __user
*user_buf
,
986 size_t count
, loff_t
*ppos
)
988 struct ath10k
*ar
= file
->private_data
;
991 unsigned int amsdu
, ampdu
;
993 res
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
998 res
= sscanf(buf
, "%u %u", &amsdu
, &du
);
1003 mutex_lock(&ar
->conf_mutex
);
1005 res
= ath10k_htt_h2t_aggr_cfg_msg(&ar
->htt
, ampdu
, amsdu
);
1010 ar
->htt
.max_num_amsdu
= amsdu
;
1011 ar
->htt
.max_num_ampdu
= ampdu
;
1014 mutex_unlock(&ar
->conf_mutex
);
1018 static const struct file_operations fops_htt_max_amsdu_ampdu
= {
1019 .read
= ath10k_read_htt_max_amsdu_ampdu
,
1020 .write
= ath10k_write_htt_max_amsdu_ampdu
,
1021 .open
= simple_open
,
1022 .owner
= THIS_MODULE
,
1023 .llseek
= default_llseek
,
1026 static ssize_t
ath10k_read_fw_dbglog(struct file
*file
,
1027 char __user
*user_buf
,
1028 size_t count
, loff_t
*ppos
)
1030 struct ath10k
*ar
= file
->private_data
;
1034 len
= scnprintf(buf
, sizeof(buf
), "0x%16llx %u\n",
1035 ar
->debug
.fw_dbglog_mask
, ar
->debug
.fw_dbglog_level
);
1037 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1040 static ssize_t
ath10k_write_fw_dbglog(struct file
*file
,
1041 const char __user
*user_buf
,
1042 size_t count
, loff_t
*ppos
)
1044 struct ath10k
*ar
= file
->private_data
;
1047 unsigned int log_level
;
1050 ret
= simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
,
1055 ret
= sscanf(buf
, "%llx %u", &mask
, &log_level
);
1061 /* default if user did not specify */
1062 log_level
= ATH10K_DBGLOG_LEVEL_WARN
;
1064 mutex_lock(&ar
->conf_mutex
);
1066 ar
->debug
.fw_dbglog_mask
= mask
;
1067 ar
->debug
.fw_dbglog_level
= log_level
;
1069 if (ar
->state
== ATH10K_STATE_ON
) {
1070 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1071 ar
->debug
.fw_dbglog_level
);
1073 ath10k_warn(ar
, "dbglog cfg failed from debugfs: %d\n",
1082 mutex_unlock(&ar
->conf_mutex
);
1087 /* TODO: Would be nice to always support ethtool stats, would need to
1088 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1089 * struct available..
1092 /* This generally cooresponds to the debugfs fw_stats file */
1093 static const char ath10k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1103 "d_tx_power", /* in .5 dbM I think */
1104 "d_rx_crc_err", /* fcs_bad */
1106 "d_tx_mpdus_queued",
1108 "d_tx_msdu_dropped",
1111 "d_tx_ppdu_hw_queued",
1113 "d_tx_fifo_underrun",
1116 "d_tx_excessive_retries",
1118 "d_tx_dropped_sw_retries",
1119 "d_tx_illegal_rate",
1120 "d_tx_continuous_xretries",
1122 "d_tx_mpdu_txop_limit",
1124 "d_rx_mid_ppdu_route_change",
1126 "d_rx_extra_frags_ring0",
1127 "d_rx_extra_frags_ring1",
1128 "d_rx_extra_frags_ring2",
1129 "d_rx_extra_frags_ring3",
1135 "d_rx_phy_err_drops",
1136 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1138 "d_fw_warm_reset_count",
1139 "d_fw_cold_reset_count",
1142 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1144 void ath10k_debug_get_et_strings(struct ieee80211_hw
*hw
,
1145 struct ieee80211_vif
*vif
,
1148 if (sset
== ETH_SS_STATS
)
1149 memcpy(data
, *ath10k_gstrings_stats
,
1150 sizeof(ath10k_gstrings_stats
));
1153 int ath10k_debug_get_et_sset_count(struct ieee80211_hw
*hw
,
1154 struct ieee80211_vif
*vif
, int sset
)
1156 if (sset
== ETH_SS_STATS
)
1157 return ATH10K_SSTATS_LEN
;
1162 void ath10k_debug_get_et_stats(struct ieee80211_hw
*hw
,
1163 struct ieee80211_vif
*vif
,
1164 struct ethtool_stats
*stats
, u64
*data
)
1166 struct ath10k
*ar
= hw
->priv
;
1167 static const struct ath10k_fw_stats_pdev zero_stats
= {};
1168 const struct ath10k_fw_stats_pdev
*pdev_stats
;
1171 mutex_lock(&ar
->conf_mutex
);
1173 if (ar
->state
== ATH10K_STATE_ON
) {
1174 ret
= ath10k_debug_fw_stats_request(ar
);
1176 /* just print a warning and try to use older results */
1178 "failed to get fw stats for ethtool: %d\n",
1183 pdev_stats
= list_first_entry_or_null(&ar
->debug
.fw_stats
.pdevs
,
1184 struct ath10k_fw_stats_pdev
,
1187 /* no results available so just return zeroes */
1188 pdev_stats
= &zero_stats
;
1191 spin_lock_bh(&ar
->data_lock
);
1193 data
[i
++] = pdev_stats
->hw_reaped
; /* ppdu reaped */
1194 data
[i
++] = 0; /* tx bytes */
1195 data
[i
++] = pdev_stats
->htt_mpdus
;
1196 data
[i
++] = 0; /* rx bytes */
1197 data
[i
++] = pdev_stats
->ch_noise_floor
;
1198 data
[i
++] = pdev_stats
->cycle_count
;
1199 data
[i
++] = pdev_stats
->phy_err_count
;
1200 data
[i
++] = pdev_stats
->rts_bad
;
1201 data
[i
++] = pdev_stats
->rts_good
;
1202 data
[i
++] = pdev_stats
->chan_tx_power
;
1203 data
[i
++] = pdev_stats
->fcs_bad
;
1204 data
[i
++] = pdev_stats
->no_beacons
;
1205 data
[i
++] = pdev_stats
->mpdu_enqued
;
1206 data
[i
++] = pdev_stats
->msdu_enqued
;
1207 data
[i
++] = pdev_stats
->wmm_drop
;
1208 data
[i
++] = pdev_stats
->local_enqued
;
1209 data
[i
++] = pdev_stats
->local_freed
;
1210 data
[i
++] = pdev_stats
->hw_queued
;
1211 data
[i
++] = pdev_stats
->hw_reaped
;
1212 data
[i
++] = pdev_stats
->underrun
;
1213 data
[i
++] = pdev_stats
->tx_abort
;
1214 data
[i
++] = pdev_stats
->mpdus_requed
;
1215 data
[i
++] = pdev_stats
->tx_ko
;
1216 data
[i
++] = pdev_stats
->data_rc
;
1217 data
[i
++] = pdev_stats
->sw_retry_failure
;
1218 data
[i
++] = pdev_stats
->illgl_rate_phy_err
;
1219 data
[i
++] = pdev_stats
->pdev_cont_xretry
;
1220 data
[i
++] = pdev_stats
->pdev_tx_timeout
;
1221 data
[i
++] = pdev_stats
->txop_ovf
;
1222 data
[i
++] = pdev_stats
->pdev_resets
;
1223 data
[i
++] = pdev_stats
->mid_ppdu_route_change
;
1224 data
[i
++] = pdev_stats
->status_rcvd
;
1225 data
[i
++] = pdev_stats
->r0_frags
;
1226 data
[i
++] = pdev_stats
->r1_frags
;
1227 data
[i
++] = pdev_stats
->r2_frags
;
1228 data
[i
++] = pdev_stats
->r3_frags
;
1229 data
[i
++] = pdev_stats
->htt_msdus
;
1230 data
[i
++] = pdev_stats
->htt_mpdus
;
1231 data
[i
++] = pdev_stats
->loc_msdus
;
1232 data
[i
++] = pdev_stats
->loc_mpdus
;
1233 data
[i
++] = pdev_stats
->phy_errs
;
1234 data
[i
++] = pdev_stats
->phy_err_drop
;
1235 data
[i
++] = pdev_stats
->mpdu_errs
;
1236 data
[i
++] = ar
->stats
.fw_crash_counter
;
1237 data
[i
++] = ar
->stats
.fw_warm_reset_counter
;
1238 data
[i
++] = ar
->stats
.fw_cold_reset_counter
;
1240 spin_unlock_bh(&ar
->data_lock
);
1242 mutex_unlock(&ar
->conf_mutex
);
1244 WARN_ON(i
!= ATH10K_SSTATS_LEN
);
1247 static const struct file_operations fops_fw_dbglog
= {
1248 .read
= ath10k_read_fw_dbglog
,
1249 .write
= ath10k_write_fw_dbglog
,
1250 .open
= simple_open
,
1251 .owner
= THIS_MODULE
,
1252 .llseek
= default_llseek
,
1255 static int ath10k_debug_cal_data_fetch(struct ath10k
*ar
)
1261 lockdep_assert_held(&ar
->conf_mutex
);
1263 if (WARN_ON(ar
->hw_params
.cal_data_len
> ATH10K_DEBUG_CAL_DATA_LEN
))
1266 hi_addr
= host_interest_item_address(HI_ITEM(hi_board_data
));
1268 ret
= ath10k_hif_diag_read(ar
, hi_addr
, &addr
, sizeof(addr
));
1270 ath10k_warn(ar
, "failed to read hi_board_data address: %d\n",
1275 ret
= ath10k_hif_diag_read(ar
, le32_to_cpu(addr
), ar
->debug
.cal_data
,
1276 ar
->hw_params
.cal_data_len
);
1278 ath10k_warn(ar
, "failed to read calibration data: %d\n", ret
);
1285 static int ath10k_debug_cal_data_open(struct inode
*inode
, struct file
*file
)
1287 struct ath10k
*ar
= inode
->i_private
;
1289 mutex_lock(&ar
->conf_mutex
);
1291 if (ar
->state
== ATH10K_STATE_ON
||
1292 ar
->state
== ATH10K_STATE_UTF
) {
1293 ath10k_debug_cal_data_fetch(ar
);
1296 file
->private_data
= ar
;
1297 mutex_unlock(&ar
->conf_mutex
);
1302 static ssize_t
ath10k_debug_cal_data_read(struct file
*file
,
1303 char __user
*user_buf
,
1304 size_t count
, loff_t
*ppos
)
1306 struct ath10k
*ar
= file
->private_data
;
1308 mutex_lock(&ar
->conf_mutex
);
1310 count
= simple_read_from_buffer(user_buf
, count
, ppos
,
1312 ar
->hw_params
.cal_data_len
);
1314 mutex_unlock(&ar
->conf_mutex
);
1319 static ssize_t
ath10k_write_ani_enable(struct file
*file
,
1320 const char __user
*user_buf
,
1321 size_t count
, loff_t
*ppos
)
1323 struct ath10k
*ar
= file
->private_data
;
1327 if (kstrtou8_from_user(user_buf
, count
, 0, &enable
))
1330 mutex_lock(&ar
->conf_mutex
);
1332 if (ar
->ani_enabled
== enable
) {
1337 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->ani_enable
,
1340 ath10k_warn(ar
, "ani_enable failed from debugfs: %d\n", ret
);
1343 ar
->ani_enabled
= enable
;
1348 mutex_unlock(&ar
->conf_mutex
);
1353 static ssize_t
ath10k_read_ani_enable(struct file
*file
, char __user
*user_buf
,
1354 size_t count
, loff_t
*ppos
)
1356 struct ath10k
*ar
= file
->private_data
;
1360 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->ani_enabled
);
1362 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1365 static const struct file_operations fops_ani_enable
= {
1366 .read
= ath10k_read_ani_enable
,
1367 .write
= ath10k_write_ani_enable
,
1368 .open
= simple_open
,
1369 .owner
= THIS_MODULE
,
1370 .llseek
= default_llseek
,
1373 static const struct file_operations fops_cal_data
= {
1374 .open
= ath10k_debug_cal_data_open
,
1375 .read
= ath10k_debug_cal_data_read
,
1376 .owner
= THIS_MODULE
,
1377 .llseek
= default_llseek
,
1380 static ssize_t
ath10k_read_nf_cal_period(struct file
*file
,
1381 char __user
*user_buf
,
1382 size_t count
, loff_t
*ppos
)
1384 struct ath10k
*ar
= file
->private_data
;
1388 len
= scnprintf(buf
, sizeof(buf
), "%d\n", ar
->debug
.nf_cal_period
);
1390 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1393 static ssize_t
ath10k_write_nf_cal_period(struct file
*file
,
1394 const char __user
*user_buf
,
1395 size_t count
, loff_t
*ppos
)
1397 struct ath10k
*ar
= file
->private_data
;
1398 unsigned long period
;
1401 ret
= kstrtoul_from_user(user_buf
, count
, 0, &period
);
1405 if (period
> WMI_PDEV_PARAM_CAL_PERIOD_MAX
)
1408 /* there's no way to switch back to the firmware default */
1412 mutex_lock(&ar
->conf_mutex
);
1414 ar
->debug
.nf_cal_period
= period
;
1416 if (ar
->state
!= ATH10K_STATE_ON
) {
1417 /* firmware is not running, nothing else to do */
1422 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->cal_period
,
1423 ar
->debug
.nf_cal_period
);
1425 ath10k_warn(ar
, "cal period cfg failed from debugfs: %d\n",
1433 mutex_unlock(&ar
->conf_mutex
);
1438 static const struct file_operations fops_nf_cal_period
= {
1439 .read
= ath10k_read_nf_cal_period
,
1440 .write
= ath10k_write_nf_cal_period
,
1441 .open
= simple_open
,
1442 .owner
= THIS_MODULE
,
1443 .llseek
= default_llseek
,
1446 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1448 static int ath10k_debug_tpc_stats_request(struct ath10k
*ar
)
1451 unsigned long time_left
;
1453 lockdep_assert_held(&ar
->conf_mutex
);
1455 reinit_completion(&ar
->debug
.tpc_complete
);
1457 ret
= ath10k_wmi_pdev_get_tpc_config(ar
, WMI_TPC_CONFIG_PARAM
);
1459 ath10k_warn(ar
, "failed to request tpc config: %d\n", ret
);
1463 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
1471 void ath10k_debug_tpc_stats_process(struct ath10k
*ar
,
1472 struct ath10k_tpc_stats
*tpc_stats
)
1474 spin_lock_bh(&ar
->data_lock
);
1476 kfree(ar
->debug
.tpc_stats
);
1477 ar
->debug
.tpc_stats
= tpc_stats
;
1478 complete(&ar
->debug
.tpc_complete
);
1480 spin_unlock_bh(&ar
->data_lock
);
1484 ath10k_debug_tpc_stats_final_process(struct ath10k
*ar
,
1485 struct ath10k_tpc_stats_final
*tpc_stats
)
1487 spin_lock_bh(&ar
->data_lock
);
1489 kfree(ar
->debug
.tpc_stats_final
);
1490 ar
->debug
.tpc_stats_final
= tpc_stats
;
1491 complete(&ar
->debug
.tpc_complete
);
1493 spin_unlock_bh(&ar
->data_lock
);
1496 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats
*tpc_stats
,
1497 unsigned int j
, char *buf
, size_t *len
)
1501 static const char table_str
[][5] = { "CDD",
1504 static const char pream_str
[][6] = { "CCK",
1513 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1514 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1515 "********************************\n");
1516 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1517 "******************* %s POWER TABLE ****************\n",
1519 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1520 "********************************\n");
1521 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1522 "No. Preamble Rate_code ");
1524 for (i
= 0; i
< WMI_TPC_TX_N_CHAIN
; i
++)
1525 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1528 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
, "\n");
1530 for (i
= 0; i
< tpc_stats
->rate_max
; i
++) {
1531 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1532 "%8d %s 0x%2x %s\n", i
,
1533 pream_str
[tpc_stats
->tpc_table
[j
].pream_idx
[i
]],
1534 tpc_stats
->tpc_table
[j
].rate_code
[i
],
1535 tpc_stats
->tpc_table
[j
].tpc_value
[i
]);
1538 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1539 "***********************************\n");
1542 static void ath10k_tpc_stats_fill(struct ath10k
*ar
,
1543 struct ath10k_tpc_stats
*tpc_stats
,
1547 size_t len
, buf_len
;
1550 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1552 spin_lock_bh(&ar
->data_lock
);
1555 ath10k_warn(ar
, "failed to get tpc stats\n");
1559 len
+= scnprintf(buf
+ len
, buf_len
- len
, "\n");
1560 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1561 "*************************************\n");
1562 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1563 "TPC config for channel %4d mode %d\n",
1564 tpc_stats
->chan_freq
,
1565 tpc_stats
->phy_mode
);
1566 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1567 "*************************************\n");
1568 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1569 "CTL = 0x%2x Reg. Domain = %2d\n",
1571 tpc_stats
->reg_domain
);
1572 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1573 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1574 tpc_stats
->twice_antenna_gain
,
1575 tpc_stats
->twice_antenna_reduction
);
1576 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1577 "Power Limit = %2d Reg. Max Power = %2d\n",
1578 tpc_stats
->power_limit
,
1579 tpc_stats
->twice_max_rd_power
/ 2);
1580 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1581 "Num tx chains = %2d Num supported rates = %2d\n",
1582 tpc_stats
->num_tx_chain
,
1583 tpc_stats
->rate_max
);
1585 for (j
= 0; j
< WMI_TPC_FLAG
; j
++) {
1587 case WMI_TPC_TABLE_TYPE_CDD
:
1588 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1589 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1590 "CDD not supported\n");
1594 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1596 case WMI_TPC_TABLE_TYPE_STBC
:
1597 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1598 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1599 "STBC not supported\n");
1603 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1605 case WMI_TPC_TABLE_TYPE_TXBF
:
1606 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1607 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1608 "TXBF not supported\n***************************\n");
1612 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1615 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1622 spin_unlock_bh(&ar
->data_lock
);
1630 static int ath10k_tpc_stats_open(struct inode
*inode
, struct file
*file
)
1632 struct ath10k
*ar
= inode
->i_private
;
1636 mutex_lock(&ar
->conf_mutex
);
1638 if (ar
->state
!= ATH10K_STATE_ON
) {
1643 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
1649 ret
= ath10k_debug_tpc_stats_request(ar
);
1651 ath10k_warn(ar
, "failed to request tpc config stats: %d\n",
1656 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
1657 file
->private_data
= buf
;
1659 mutex_unlock(&ar
->conf_mutex
);
1666 mutex_unlock(&ar
->conf_mutex
);
1670 static int ath10k_tpc_stats_release(struct inode
*inode
, struct file
*file
)
1672 vfree(file
->private_data
);
1677 static ssize_t
ath10k_tpc_stats_read(struct file
*file
, char __user
*user_buf
,
1678 size_t count
, loff_t
*ppos
)
1680 const char *buf
= file
->private_data
;
1681 size_t len
= strlen(buf
);
1683 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1686 static const struct file_operations fops_tpc_stats
= {
1687 .open
= ath10k_tpc_stats_open
,
1688 .release
= ath10k_tpc_stats_release
,
1689 .read
= ath10k_tpc_stats_read
,
1690 .owner
= THIS_MODULE
,
1691 .llseek
= default_llseek
,
1694 int ath10k_debug_start(struct ath10k
*ar
)
1698 lockdep_assert_held(&ar
->conf_mutex
);
1700 ret
= ath10k_debug_htt_stats_req(ar
);
1702 /* continue normally anyway, this isn't serious */
1703 ath10k_warn(ar
, "failed to start htt stats workqueue: %d\n",
1706 if (ar
->debug
.fw_dbglog_mask
) {
1707 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1708 ATH10K_DBGLOG_LEVEL_WARN
);
1711 ath10k_warn(ar
, "failed to enable dbglog during start: %d",
1715 if (ar
->pktlog_filter
) {
1716 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
1721 "failed to enable pktlog filter %x: %d\n",
1722 ar
->pktlog_filter
, ret
);
1724 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1727 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1730 if (ar
->debug
.nf_cal_period
&&
1731 !test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1732 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
1733 ret
= ath10k_wmi_pdev_set_param(ar
,
1734 ar
->wmi
.pdev_param
->cal_period
,
1735 ar
->debug
.nf_cal_period
);
1738 ath10k_warn(ar
, "cal period cfg failed from debug start: %d\n",
1745 void ath10k_debug_stop(struct ath10k
*ar
)
1747 lockdep_assert_held(&ar
->conf_mutex
);
1749 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
1750 ar
->normal_mode_fw
.fw_file
.fw_features
))
1751 ath10k_debug_cal_data_fetch(ar
);
1753 /* Must not use _sync to avoid deadlock, we do that in
1754 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1755 * warning from del_timer().
1757 if (ar
->debug
.htt_stats_mask
!= 0)
1758 cancel_delayed_work(&ar
->debug
.htt_stats_dwork
);
1760 ath10k_wmi_pdev_pktlog_disable(ar
);
1763 static ssize_t
ath10k_write_simulate_radar(struct file
*file
,
1764 const char __user
*user_buf
,
1765 size_t count
, loff_t
*ppos
)
1767 struct ath10k
*ar
= file
->private_data
;
1768 struct ath10k_vif
*arvif
;
1770 /* Just check for for the first vif alone, as all the vifs will be
1771 * sharing the same channel and if the channel is disabled, all the
1772 * vifs will share the same 'is_started' state.
1774 arvif
= list_first_entry(&ar
->arvifs
, typeof(*arvif
), list
);
1775 if (!arvif
->is_started
)
1778 ieee80211_radar_detected(ar
->hw
);
1783 static const struct file_operations fops_simulate_radar
= {
1784 .write
= ath10k_write_simulate_radar
,
1785 .open
= simple_open
,
1786 .owner
= THIS_MODULE
,
1787 .llseek
= default_llseek
,
1790 #define ATH10K_DFS_STAT(s, p) (\
1791 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1792 ar->debug.dfs_stats.p))
1794 #define ATH10K_DFS_POOL_STAT(s, p) (\
1795 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1796 ar->debug.dfs_pool_stats.p))
1798 static ssize_t
ath10k_read_dfs_stats(struct file
*file
, char __user
*user_buf
,
1799 size_t count
, loff_t
*ppos
)
1801 int retval
= 0, len
= 0;
1802 const int size
= 8000;
1803 struct ath10k
*ar
= file
->private_data
;
1806 buf
= kzalloc(size
, GFP_KERNEL
);
1810 if (!ar
->dfs_detector
) {
1811 len
+= scnprintf(buf
+ len
, size
- len
, "DFS not enabled\n");
1815 ar
->debug
.dfs_pool_stats
=
1816 ar
->dfs_detector
->get_stats(ar
->dfs_detector
);
1818 len
+= scnprintf(buf
+ len
, size
- len
, "Pulse detector statistics:\n");
1820 ATH10K_DFS_STAT("reported phy errors", phy_errors
);
1821 ATH10K_DFS_STAT("pulse events reported", pulses_total
);
1822 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected
);
1823 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded
);
1824 ATH10K_DFS_STAT("Radars detected", radar_detected
);
1826 len
+= scnprintf(buf
+ len
, size
- len
, "Global Pool statistics:\n");
1827 ATH10K_DFS_POOL_STAT("Pool references", pool_reference
);
1828 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated
);
1829 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error
);
1830 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used
);
1831 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated
);
1832 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error
);
1833 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used
);
1839 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1845 static const struct file_operations fops_dfs_stats
= {
1846 .read
= ath10k_read_dfs_stats
,
1847 .open
= simple_open
,
1848 .owner
= THIS_MODULE
,
1849 .llseek
= default_llseek
,
1852 static ssize_t
ath10k_write_pktlog_filter(struct file
*file
,
1853 const char __user
*ubuf
,
1854 size_t count
, loff_t
*ppos
)
1856 struct ath10k
*ar
= file
->private_data
;
1860 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
1863 mutex_lock(&ar
->conf_mutex
);
1865 if (ar
->state
!= ATH10K_STATE_ON
) {
1866 ar
->pktlog_filter
= filter
;
1871 if (filter
== ar
->pktlog_filter
) {
1877 ret
= ath10k_wmi_pdev_pktlog_enable(ar
, filter
);
1879 ath10k_warn(ar
, "failed to enable pktlog filter %x: %d\n",
1880 ar
->pktlog_filter
, ret
);
1884 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1886 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1891 ar
->pktlog_filter
= filter
;
1895 mutex_unlock(&ar
->conf_mutex
);
1899 static ssize_t
ath10k_read_pktlog_filter(struct file
*file
, char __user
*ubuf
,
1900 size_t count
, loff_t
*ppos
)
1903 struct ath10k
*ar
= file
->private_data
;
1906 mutex_lock(&ar
->conf_mutex
);
1907 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
1909 mutex_unlock(&ar
->conf_mutex
);
1911 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1914 static const struct file_operations fops_pktlog_filter
= {
1915 .read
= ath10k_read_pktlog_filter
,
1916 .write
= ath10k_write_pktlog_filter
,
1920 static ssize_t
ath10k_write_quiet_period(struct file
*file
,
1921 const char __user
*ubuf
,
1922 size_t count
, loff_t
*ppos
)
1924 struct ath10k
*ar
= file
->private_data
;
1927 if (kstrtouint_from_user(ubuf
, count
, 0, &period
))
1930 if (period
< ATH10K_QUIET_PERIOD_MIN
) {
1931 ath10k_warn(ar
, "Quiet period %u can not be lesser than 25ms\n",
1935 mutex_lock(&ar
->conf_mutex
);
1936 ar
->thermal
.quiet_period
= period
;
1937 ath10k_thermal_set_throttling(ar
);
1938 mutex_unlock(&ar
->conf_mutex
);
1943 static ssize_t
ath10k_read_quiet_period(struct file
*file
, char __user
*ubuf
,
1944 size_t count
, loff_t
*ppos
)
1947 struct ath10k
*ar
= file
->private_data
;
1950 mutex_lock(&ar
->conf_mutex
);
1951 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
1952 ar
->thermal
.quiet_period
);
1953 mutex_unlock(&ar
->conf_mutex
);
1955 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
1958 static const struct file_operations fops_quiet_period
= {
1959 .read
= ath10k_read_quiet_period
,
1960 .write
= ath10k_write_quiet_period
,
1964 static ssize_t
ath10k_write_btcoex(struct file
*file
,
1965 const char __user
*ubuf
,
1966 size_t count
, loff_t
*ppos
)
1968 struct ath10k
*ar
= file
->private_data
;
1975 buf_size
= min(count
, (sizeof(buf
) - 1));
1976 if (copy_from_user(buf
, ubuf
, buf_size
))
1979 buf
[buf_size
] = '\0';
1981 if (strtobool(buf
, &val
) != 0)
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 queue_work(ar
->workqueue
, &ar
->restart_work
);
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 queue_work(ar
->workqueue
, &ar
->restart_work
);
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 if (!(test_bit(WMI_SERVICE_RESET_CHIP
, ar
->wmi
.svc_map
)))
2377 ath10k_warn(ar
, "wmi service for reset chip is not available\n");
2379 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pdev_reset
,
2380 WMI_RST_MODE_WARM_RESET
);
2383 ath10k_warn(ar
, "failed to enable warm hw reset: %d\n", ret
);
2390 mutex_unlock(&ar
->conf_mutex
);
2394 static const struct file_operations fops_warm_hw_reset
= {
2395 .write
= ath10k_write_warm_hw_reset
,
2396 .open
= simple_open
,
2397 .owner
= THIS_MODULE
,
2398 .llseek
= default_llseek
,
2401 static void ath10k_peer_ps_state_disable(void *data
,
2402 struct ieee80211_sta
*sta
)
2404 struct ath10k
*ar
= data
;
2405 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
2407 spin_lock_bh(&ar
->data_lock
);
2408 arsta
->peer_ps_state
= WMI_PEER_PS_STATE_DISABLED
;
2409 spin_unlock_bh(&ar
->data_lock
);
2412 static ssize_t
ath10k_write_ps_state_enable(struct file
*file
,
2413 const char __user
*user_buf
,
2414 size_t count
, loff_t
*ppos
)
2416 struct ath10k
*ar
= file
->private_data
;
2421 if (kstrtou8_from_user(user_buf
, count
, 0, &ps_state_enable
))
2424 if (ps_state_enable
> 1)
2427 mutex_lock(&ar
->conf_mutex
);
2429 if (ar
->ps_state_enable
== ps_state_enable
) {
2434 param
= ar
->wmi
.pdev_param
->peer_sta_ps_statechg_enable
;
2435 ret
= ath10k_wmi_pdev_set_param(ar
, param
, ps_state_enable
);
2437 ath10k_warn(ar
, "failed to enable ps_state_enable: %d\n",
2441 ar
->ps_state_enable
= ps_state_enable
;
2443 if (!ar
->ps_state_enable
)
2444 ieee80211_iterate_stations_atomic(ar
->hw
,
2445 ath10k_peer_ps_state_disable
,
2451 mutex_unlock(&ar
->conf_mutex
);
2456 static ssize_t
ath10k_read_ps_state_enable(struct file
*file
,
2457 char __user
*user_buf
,
2458 size_t count
, loff_t
*ppos
)
2460 struct ath10k
*ar
= file
->private_data
;
2464 mutex_lock(&ar
->conf_mutex
);
2465 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2466 ar
->ps_state_enable
);
2467 mutex_unlock(&ar
->conf_mutex
);
2469 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2472 static const struct file_operations fops_ps_state_enable
= {
2473 .read
= ath10k_read_ps_state_enable
,
2474 .write
= ath10k_write_ps_state_enable
,
2475 .open
= simple_open
,
2476 .owner
= THIS_MODULE
,
2477 .llseek
= default_llseek
,
2480 int ath10k_debug_create(struct ath10k
*ar
)
2482 ar
->debug
.cal_data
= vzalloc(ATH10K_DEBUG_CAL_DATA_LEN
);
2483 if (!ar
->debug
.cal_data
)
2486 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.pdevs
);
2487 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.vdevs
);
2488 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers
);
2489 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers_extd
);
2494 void ath10k_debug_destroy(struct ath10k
*ar
)
2496 vfree(ar
->debug
.cal_data
);
2497 ar
->debug
.cal_data
= NULL
;
2499 ath10k_debug_fw_stats_reset(ar
);
2501 kfree(ar
->debug
.tpc_stats
);
2504 int ath10k_debug_register(struct ath10k
*ar
)
2506 ar
->debug
.debugfs_phy
= debugfs_create_dir("ath10k",
2507 ar
->hw
->wiphy
->debugfsdir
);
2508 if (IS_ERR_OR_NULL(ar
->debug
.debugfs_phy
)) {
2509 if (IS_ERR(ar
->debug
.debugfs_phy
))
2510 return PTR_ERR(ar
->debug
.debugfs_phy
);
2515 INIT_DELAYED_WORK(&ar
->debug
.htt_stats_dwork
,
2516 ath10k_debug_htt_stats_dwork
);
2518 init_completion(&ar
->debug
.tpc_complete
);
2519 init_completion(&ar
->debug
.fw_stats_complete
);
2521 debugfs_create_file("fw_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2524 debugfs_create_file("fw_reset_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2525 &fops_fw_reset_stats
);
2527 debugfs_create_file("wmi_services", 0400, ar
->debug
.debugfs_phy
, ar
,
2528 &fops_wmi_services
);
2530 debugfs_create_file("simulate_fw_crash", 0600, ar
->debug
.debugfs_phy
, ar
,
2531 &fops_simulate_fw_crash
);
2533 debugfs_create_file("reg_addr", 0600, ar
->debug
.debugfs_phy
, ar
,
2536 debugfs_create_file("reg_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2539 debugfs_create_file("mem_value", 0600, ar
->debug
.debugfs_phy
, ar
,
2542 debugfs_create_file("chip_id", 0400, ar
->debug
.debugfs_phy
, ar
,
2545 debugfs_create_file("htt_stats_mask", 0600, ar
->debug
.debugfs_phy
, ar
,
2546 &fops_htt_stats_mask
);
2548 debugfs_create_file("htt_max_amsdu_ampdu", 0600, ar
->debug
.debugfs_phy
, ar
,
2549 &fops_htt_max_amsdu_ampdu
);
2551 debugfs_create_file("fw_dbglog", 0600, ar
->debug
.debugfs_phy
, ar
,
2554 if (!test_bit(ATH10K_FW_FEATURE_NON_BMI
,
2555 ar
->normal_mode_fw
.fw_file
.fw_features
)) {
2556 debugfs_create_file("cal_data", 0400, ar
->debug
.debugfs_phy
, ar
,
2559 debugfs_create_file("nf_cal_period", 0600, ar
->debug
.debugfs_phy
, ar
,
2560 &fops_nf_cal_period
);
2563 debugfs_create_file("ani_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2566 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
2567 debugfs_create_file("dfs_simulate_radar", 0200, ar
->debug
.debugfs_phy
,
2568 ar
, &fops_simulate_radar
);
2570 debugfs_create_bool("dfs_block_radar_events", 0200,
2571 ar
->debug
.debugfs_phy
,
2572 &ar
->dfs_block_radar_events
);
2574 debugfs_create_file("dfs_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2578 debugfs_create_file("pktlog_filter", 0644, ar
->debug
.debugfs_phy
, ar
,
2579 &fops_pktlog_filter
);
2581 debugfs_create_file("quiet_period", 0644, ar
->debug
.debugfs_phy
, ar
,
2582 &fops_quiet_period
);
2584 debugfs_create_file("tpc_stats", 0400, ar
->debug
.debugfs_phy
, ar
,
2587 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
))
2588 debugfs_create_file("btcoex", 0644, ar
->debug
.debugfs_phy
, ar
,
2591 if (test_bit(WMI_SERVICE_PEER_STATS
, ar
->wmi
.svc_map
)) {
2592 debugfs_create_file("peer_stats", 0644, ar
->debug
.debugfs_phy
, ar
,
2595 debugfs_create_file("enable_extd_tx_stats", 0644,
2596 ar
->debug
.debugfs_phy
, ar
,
2597 &fops_enable_extd_tx_stats
);
2600 debugfs_create_file("fw_checksums", 0400, ar
->debug
.debugfs_phy
, ar
,
2601 &fops_fw_checksums
);
2603 if (IS_ENABLED(CONFIG_MAC80211_DEBUGFS
))
2604 debugfs_create_file("sta_tid_stats_mask", 0600,
2605 ar
->debug
.debugfs_phy
,
2606 ar
, &fops_sta_tid_stats_mask
);
2608 if (test_bit(WMI_SERVICE_TPC_STATS_FINAL
, ar
->wmi
.svc_map
))
2609 debugfs_create_file("tpc_stats_final", 0400,
2610 ar
->debug
.debugfs_phy
, ar
,
2611 &fops_tpc_stats_final
);
2613 debugfs_create_file("warm_hw_reset", 0600, ar
->debug
.debugfs_phy
, ar
,
2614 &fops_warm_hw_reset
);
2616 debugfs_create_file("ps_state_enable", 0600, ar
->debug
.debugfs_phy
, ar
,
2617 &fops_ps_state_enable
);
2622 void ath10k_debug_unregister(struct ath10k
*ar
)
2624 cancel_delayed_work_sync(&ar
->debug
.htt_stats_dwork
);
2627 #endif /* CONFIG_ATH10K_DEBUGFS */
2629 #ifdef CONFIG_ATH10K_DEBUG
2630 void ath10k_dbg(struct ath10k
*ar
, enum ath10k_debug_mask mask
,
2631 const char *fmt
, ...)
2633 struct va_format vaf
;
2636 va_start(args
, fmt
);
2641 if (ath10k_debug_mask
& mask
)
2642 dev_printk(KERN_DEBUG
, ar
->dev
, "%pV", &vaf
);
2644 trace_ath10k_log_dbg(ar
, mask
, &vaf
);
2648 EXPORT_SYMBOL(ath10k_dbg
);
2650 void ath10k_dbg_dump(struct ath10k
*ar
,
2651 enum ath10k_debug_mask mask
,
2652 const char *msg
, const char *prefix
,
2653 const void *buf
, size_t len
)
2659 if (ath10k_debug_mask
& mask
) {
2661 ath10k_dbg(ar
, mask
, "%s\n", msg
);
2663 for (ptr
= buf
; (ptr
- buf
) < len
; ptr
+= 16) {
2665 linebuflen
+= scnprintf(linebuf
+ linebuflen
,
2666 sizeof(linebuf
) - linebuflen
,
2668 (prefix
? prefix
: ""),
2669 (unsigned int)(ptr
- buf
));
2670 hex_dump_to_buffer(ptr
, len
- (ptr
- buf
), 16, 1,
2671 linebuf
+ linebuflen
,
2672 sizeof(linebuf
) - linebuflen
, true);
2673 dev_printk(KERN_DEBUG
, ar
->dev
, "%s\n", linebuf
);
2677 /* tracing code doesn't like null strings :/ */
2678 trace_ath10k_log_dbg_dump(ar
, msg
? msg
: "", prefix
? prefix
: "",
2681 EXPORT_SYMBOL(ath10k_dbg_dump
);
2683 #endif /* CONFIG_ATH10K_DEBUG */