2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/module.h>
19 #include <linux/debugfs.h>
20 #include <linux/vmalloc.h>
21 #include <linux/utsname.h>
22 #include <linux/crc32.h>
23 #include <linux/firmware.h>
31 #define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
33 #define ATH10K_FW_CRASH_DUMP_VERSION 1
36 * enum ath10k_fw_crash_dump_type - types of data in the dump file
37 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
39 enum ath10k_fw_crash_dump_type
{
40 ATH10K_FW_CRASH_DUMP_REGISTERS
= 0,
42 ATH10K_FW_CRASH_DUMP_MAX
,
45 struct ath10k_tlv_dump_data
{
46 /* see ath10k_fw_crash_dump_type above */
52 /* pad to 32-bit boundaries as needed */
56 struct ath10k_dump_file_data
{
57 /* dump file information */
59 /* "ATH10K-FW-DUMP" */
64 /* file dump version */
67 /* some info we can get from ath10k struct that might help */
73 /* 0 for now, in place for later hardware */
76 __le32 target_version
;
77 __le32 fw_version_major
;
78 __le32 fw_version_minor
;
79 __le32 fw_version_release
;
80 __le32 fw_version_build
;
81 __le32 phy_capability
;
82 __le32 hw_min_tx_power
;
83 __le32 hw_max_tx_power
;
88 /* firmware version string */
89 char fw_ver
[ETHTOOL_FWVERS_LEN
];
91 /* Kernel related information */
93 /* time-of-day stamp */
96 /* time-of-day stamp, nano-seconds */
99 /* LINUX_VERSION_CODE */
100 __le32 kernel_ver_code
;
102 /* VERMAGIC_STRING */
105 /* room for growth w/out changing binary format */
108 /* struct ath10k_tlv_dump_data + more */
112 void ath10k_info(struct ath10k
*ar
, const char *fmt
, ...)
114 struct va_format vaf
= {
121 dev_info(ar
->dev
, "%pV", &vaf
);
122 trace_ath10k_log_info(ar
, &vaf
);
125 EXPORT_SYMBOL(ath10k_info
);
127 void ath10k_debug_print_hwfw_info(struct ath10k
*ar
)
129 const struct firmware
*firmware
;
130 char fw_features
[128] = {};
133 ath10k_core_get_fw_features_str(ar
, fw_features
, sizeof(fw_features
));
135 ath10k_info(ar
, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
139 ar
->id
.subsystem_vendor
, ar
->id
.subsystem_device
);
141 ath10k_info(ar
, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
142 IS_ENABLED(CONFIG_ATH10K_DEBUG
),
143 IS_ENABLED(CONFIG_ATH10K_DEBUGFS
),
144 IS_ENABLED(CONFIG_ATH10K_TRACING
),
145 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
),
146 IS_ENABLED(CONFIG_NL80211_TESTMODE
));
148 firmware
= ar
->normal_mode_fw
.fw_file
.firmware
;
150 crc
= crc32_le(0, firmware
->data
, firmware
->size
);
152 ath10k_info(ar
, "firmware ver %s api %d features %s crc32 %08x\n",
153 ar
->hw
->wiphy
->fw_version
,
159 void ath10k_debug_print_board_info(struct ath10k
*ar
)
163 if (ar
->id
.bmi_ids_valid
)
164 scnprintf(boardinfo
, sizeof(boardinfo
), "%d:%d",
165 ar
->id
.bmi_chip_id
, ar
->id
.bmi_board_id
);
167 scnprintf(boardinfo
, sizeof(boardinfo
), "N/A");
169 ath10k_info(ar
, "board_file api %d bmi_id %s crc32 %08x",
172 crc32_le(0, ar
->normal_mode_fw
.board
->data
,
173 ar
->normal_mode_fw
.board
->size
));
176 void ath10k_debug_print_boot_info(struct ath10k
*ar
)
178 ath10k_info(ar
, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
179 ar
->htt
.target_version_major
,
180 ar
->htt
.target_version_minor
,
181 ar
->normal_mode_fw
.fw_file
.wmi_op_version
,
182 ar
->normal_mode_fw
.fw_file
.htt_op_version
,
183 ath10k_cal_mode_str(ar
->cal_mode
),
184 ar
->max_num_stations
,
185 test_bit(ATH10K_FLAG_RAW_MODE
, &ar
->dev_flags
),
186 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED
, &ar
->dev_flags
));
189 void ath10k_print_driver_info(struct ath10k
*ar
)
191 ath10k_debug_print_hwfw_info(ar
);
192 ath10k_debug_print_board_info(ar
);
193 ath10k_debug_print_boot_info(ar
);
195 EXPORT_SYMBOL(ath10k_print_driver_info
);
197 void ath10k_err(struct ath10k
*ar
, const char *fmt
, ...)
199 struct va_format vaf
= {
206 dev_err(ar
->dev
, "%pV", &vaf
);
207 trace_ath10k_log_err(ar
, &vaf
);
210 EXPORT_SYMBOL(ath10k_err
);
212 void ath10k_warn(struct ath10k
*ar
, const char *fmt
, ...)
214 struct va_format vaf
= {
221 dev_warn_ratelimited(ar
->dev
, "%pV", &vaf
);
222 trace_ath10k_log_warn(ar
, &vaf
);
226 EXPORT_SYMBOL(ath10k_warn
);
228 #ifdef CONFIG_ATH10K_DEBUGFS
230 static ssize_t
ath10k_read_wmi_services(struct file
*file
,
231 char __user
*user_buf
,
232 size_t count
, loff_t
*ppos
)
234 struct ath10k
*ar
= file
->private_data
;
236 unsigned int len
= 0, buf_len
= 4096;
242 buf
= kzalloc(buf_len
, GFP_KERNEL
);
246 mutex_lock(&ar
->conf_mutex
);
251 spin_lock_bh(&ar
->data_lock
);
252 for (i
= 0; i
< WMI_SERVICE_MAX
; i
++) {
253 enabled
= test_bit(i
, ar
->wmi
.svc_map
);
254 name
= wmi_service_name(i
);
258 len
+= scnprintf(buf
+ len
, buf_len
- len
,
259 "%-40s %s (bit %d)\n",
260 "unknown", "enabled", i
);
265 len
+= scnprintf(buf
+ len
, buf_len
- len
,
267 name
, enabled
? "enabled" : "-");
269 spin_unlock_bh(&ar
->data_lock
);
271 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
273 mutex_unlock(&ar
->conf_mutex
);
279 static const struct file_operations fops_wmi_services
= {
280 .read
= ath10k_read_wmi_services
,
282 .owner
= THIS_MODULE
,
283 .llseek
= default_llseek
,
286 static void ath10k_fw_stats_pdevs_free(struct list_head
*head
)
288 struct ath10k_fw_stats_pdev
*i
, *tmp
;
290 list_for_each_entry_safe(i
, tmp
, head
, list
) {
296 static void ath10k_fw_stats_vdevs_free(struct list_head
*head
)
298 struct ath10k_fw_stats_vdev
*i
, *tmp
;
300 list_for_each_entry_safe(i
, tmp
, head
, list
) {
306 static void ath10k_fw_stats_peers_free(struct list_head
*head
)
308 struct ath10k_fw_stats_peer
*i
, *tmp
;
310 list_for_each_entry_safe(i
, tmp
, head
, list
) {
316 static void ath10k_fw_extd_stats_peers_free(struct list_head
*head
)
318 struct ath10k_fw_extd_stats_peer
*i
, *tmp
;
320 list_for_each_entry_safe(i
, tmp
, head
, list
) {
326 static void ath10k_debug_fw_stats_reset(struct ath10k
*ar
)
328 spin_lock_bh(&ar
->data_lock
);
329 ar
->debug
.fw_stats_done
= false;
330 ar
->debug
.fw_stats
.extended
= false;
331 ath10k_fw_stats_pdevs_free(&ar
->debug
.fw_stats
.pdevs
);
332 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
333 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
334 ath10k_fw_extd_stats_peers_free(&ar
->debug
.fw_stats
.peers_extd
);
335 spin_unlock_bh(&ar
->data_lock
);
338 void ath10k_debug_fw_stats_process(struct ath10k
*ar
, struct sk_buff
*skb
)
340 struct ath10k_fw_stats stats
= {};
341 bool is_start
, is_started
, is_end
;
346 INIT_LIST_HEAD(&stats
.pdevs
);
347 INIT_LIST_HEAD(&stats
.vdevs
);
348 INIT_LIST_HEAD(&stats
.peers
);
349 INIT_LIST_HEAD(&stats
.peers_extd
);
351 spin_lock_bh(&ar
->data_lock
);
352 ret
= ath10k_wmi_pull_fw_stats(ar
, skb
, &stats
);
354 ath10k_warn(ar
, "failed to pull fw stats: %d\n", ret
);
358 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
359 * splits the stats data and delivers it in a ping-pong fashion of
360 * request cmd-update event.
362 * However there is no explicit end-of-data. Instead start-of-data is
363 * used as an implicit one. This works as follows:
364 * a) discard stat update events until one with pdev stats is
365 * delivered - this skips session started at end of (b)
366 * b) consume stat update events until another one with pdev stats is
367 * delivered which is treated as end-of-data and is itself discarded
369 if (ath10k_peer_stats_enabled(ar
))
370 ath10k_sta_update_rx_duration(ar
, &stats
);
372 if (ar
->debug
.fw_stats_done
) {
373 if (!ath10k_peer_stats_enabled(ar
))
374 ath10k_warn(ar
, "received unsolicited stats update event\n");
379 num_peers
= ath10k_wmi_fw_stats_num_peers(&ar
->debug
.fw_stats
.peers
);
380 num_vdevs
= ath10k_wmi_fw_stats_num_vdevs(&ar
->debug
.fw_stats
.vdevs
);
381 is_start
= (list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
382 !list_empty(&stats
.pdevs
));
383 is_end
= (!list_empty(&ar
->debug
.fw_stats
.pdevs
) &&
384 !list_empty(&stats
.pdevs
));
387 list_splice_tail_init(&stats
.pdevs
, &ar
->debug
.fw_stats
.pdevs
);
390 ar
->debug
.fw_stats_done
= true;
392 is_started
= !list_empty(&ar
->debug
.fw_stats
.pdevs
);
394 if (is_started
&& !is_end
) {
395 if (num_peers
>= ATH10K_MAX_NUM_PEER_IDS
) {
396 /* Although this is unlikely impose a sane limit to
397 * prevent firmware from DoS-ing the host.
399 ath10k_fw_stats_peers_free(&ar
->debug
.fw_stats
.peers
);
400 ath10k_warn(ar
, "dropping fw peer stats\n");
404 if (num_vdevs
>= BITS_PER_LONG
) {
405 ath10k_fw_stats_vdevs_free(&ar
->debug
.fw_stats
.vdevs
);
406 ath10k_warn(ar
, "dropping fw vdev stats\n");
410 list_splice_tail_init(&stats
.peers
, &ar
->debug
.fw_stats
.peers
);
411 list_splice_tail_init(&stats
.vdevs
, &ar
->debug
.fw_stats
.vdevs
);
412 list_splice_tail_init(&stats
.peers_extd
,
413 &ar
->debug
.fw_stats
.peers_extd
);
416 complete(&ar
->debug
.fw_stats_complete
);
419 /* In some cases lists have been spliced and cleared. Free up
420 * resources if that is not the case.
422 ath10k_fw_stats_pdevs_free(&stats
.pdevs
);
423 ath10k_fw_stats_vdevs_free(&stats
.vdevs
);
424 ath10k_fw_stats_peers_free(&stats
.peers
);
425 ath10k_fw_extd_stats_peers_free(&stats
.peers_extd
);
427 spin_unlock_bh(&ar
->data_lock
);
430 static int ath10k_debug_fw_stats_request(struct ath10k
*ar
)
432 unsigned long timeout
, time_left
;
435 lockdep_assert_held(&ar
->conf_mutex
);
437 timeout
= jiffies
+ msecs_to_jiffies(1 * HZ
);
439 ath10k_debug_fw_stats_reset(ar
);
442 if (time_after(jiffies
, timeout
))
445 reinit_completion(&ar
->debug
.fw_stats_complete
);
447 ret
= ath10k_wmi_request_stats(ar
, ar
->fw_stats_req_mask
);
449 ath10k_warn(ar
, "could not request stats (%d)\n", ret
);
454 wait_for_completion_timeout(&ar
->debug
.fw_stats_complete
,
459 spin_lock_bh(&ar
->data_lock
);
460 if (ar
->debug
.fw_stats_done
) {
461 spin_unlock_bh(&ar
->data_lock
);
464 spin_unlock_bh(&ar
->data_lock
);
470 static int ath10k_fw_stats_open(struct inode
*inode
, struct file
*file
)
472 struct ath10k
*ar
= inode
->i_private
;
476 mutex_lock(&ar
->conf_mutex
);
478 if (ar
->state
!= ATH10K_STATE_ON
) {
483 buf
= vmalloc(ATH10K_FW_STATS_BUF_SIZE
);
489 ret
= ath10k_debug_fw_stats_request(ar
);
491 ath10k_warn(ar
, "failed to request fw stats: %d\n", ret
);
495 ret
= ath10k_wmi_fw_stats_fill(ar
, &ar
->debug
.fw_stats
, buf
);
497 ath10k_warn(ar
, "failed to fill fw stats: %d\n", ret
);
501 file
->private_data
= buf
;
503 mutex_unlock(&ar
->conf_mutex
);
510 mutex_unlock(&ar
->conf_mutex
);
514 static int ath10k_fw_stats_release(struct inode
*inode
, struct file
*file
)
516 vfree(file
->private_data
);
521 static ssize_t
ath10k_fw_stats_read(struct file
*file
, char __user
*user_buf
,
522 size_t count
, loff_t
*ppos
)
524 const char *buf
= file
->private_data
;
525 unsigned int len
= strlen(buf
);
527 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
530 static const struct file_operations fops_fw_stats
= {
531 .open
= ath10k_fw_stats_open
,
532 .release
= ath10k_fw_stats_release
,
533 .read
= ath10k_fw_stats_read
,
534 .owner
= THIS_MODULE
,
535 .llseek
= default_llseek
,
538 static ssize_t
ath10k_debug_fw_reset_stats_read(struct file
*file
,
539 char __user
*user_buf
,
540 size_t count
, loff_t
*ppos
)
542 struct ath10k
*ar
= file
->private_data
;
543 int ret
, len
, buf_len
;
547 buf
= kmalloc(buf_len
, GFP_KERNEL
);
551 spin_lock_bh(&ar
->data_lock
);
554 len
+= scnprintf(buf
+ len
, buf_len
- len
,
555 "fw_crash_counter\t\t%d\n", ar
->stats
.fw_crash_counter
);
556 len
+= scnprintf(buf
+ len
, buf_len
- len
,
557 "fw_warm_reset_counter\t\t%d\n",
558 ar
->stats
.fw_warm_reset_counter
);
559 len
+= scnprintf(buf
+ len
, buf_len
- len
,
560 "fw_cold_reset_counter\t\t%d\n",
561 ar
->stats
.fw_cold_reset_counter
);
563 spin_unlock_bh(&ar
->data_lock
);
565 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
572 static const struct file_operations fops_fw_reset_stats
= {
574 .read
= ath10k_debug_fw_reset_stats_read
,
575 .owner
= THIS_MODULE
,
576 .llseek
= default_llseek
,
579 /* This is a clean assert crash in firmware. */
580 static int ath10k_debug_fw_assert(struct ath10k
*ar
)
582 struct wmi_vdev_install_key_cmd
*cmd
;
585 skb
= ath10k_wmi_alloc_skb(ar
, sizeof(*cmd
) + 16);
589 cmd
= (struct wmi_vdev_install_key_cmd
*)skb
->data
;
590 memset(cmd
, 0, sizeof(*cmd
));
592 /* big enough number so that firmware asserts */
593 cmd
->vdev_id
= __cpu_to_le32(0x7ffe);
595 return ath10k_wmi_cmd_send(ar
, skb
,
596 ar
->wmi
.cmd
->vdev_install_key_cmdid
);
599 static ssize_t
ath10k_read_simulate_fw_crash(struct file
*file
,
600 char __user
*user_buf
,
601 size_t count
, loff_t
*ppos
)
604 "To simulate firmware crash write one of the keywords to this file:\n"
605 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
606 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
607 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
608 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
610 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
613 /* Simulate firmware crash:
614 * 'soft': Call wmi command causing firmware hang. This firmware hang is
615 * recoverable by warm firmware reset.
616 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
617 * vdev id. This is hard firmware crash because it is recoverable only by cold
620 static ssize_t
ath10k_write_simulate_fw_crash(struct file
*file
,
621 const char __user
*user_buf
,
622 size_t count
, loff_t
*ppos
)
624 struct ath10k
*ar
= file
->private_data
;
628 simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
630 /* make sure that buf is null terminated */
631 buf
[sizeof(buf
) - 1] = 0;
633 /* drop the possible '\n' from the end */
634 if (buf
[count
- 1] == '\n')
637 mutex_lock(&ar
->conf_mutex
);
639 if (ar
->state
!= ATH10K_STATE_ON
&&
640 ar
->state
!= ATH10K_STATE_RESTARTED
) {
645 if (!strcmp(buf
, "soft")) {
646 ath10k_info(ar
, "simulating soft firmware crash\n");
647 ret
= ath10k_wmi_force_fw_hang(ar
, WMI_FORCE_FW_HANG_ASSERT
, 0);
648 } else if (!strcmp(buf
, "hard")) {
649 ath10k_info(ar
, "simulating hard firmware crash\n");
650 /* 0x7fff is vdev id, and it is always out of range for all
651 * firmware variants in order to force a firmware crash.
653 ret
= ath10k_wmi_vdev_set_param(ar
, 0x7fff,
654 ar
->wmi
.vdev_param
->rts_threshold
,
656 } else if (!strcmp(buf
, "assert")) {
657 ath10k_info(ar
, "simulating firmware assert crash\n");
658 ret
= ath10k_debug_fw_assert(ar
);
659 } else if (!strcmp(buf
, "hw-restart")) {
660 ath10k_info(ar
, "user requested hw restart\n");
661 queue_work(ar
->workqueue
, &ar
->restart_work
);
669 ath10k_warn(ar
, "failed to simulate firmware crash: %d\n", ret
);
676 mutex_unlock(&ar
->conf_mutex
);
680 static const struct file_operations fops_simulate_fw_crash
= {
681 .read
= ath10k_read_simulate_fw_crash
,
682 .write
= ath10k_write_simulate_fw_crash
,
684 .owner
= THIS_MODULE
,
685 .llseek
= default_llseek
,
688 static ssize_t
ath10k_read_chip_id(struct file
*file
, char __user
*user_buf
,
689 size_t count
, loff_t
*ppos
)
691 struct ath10k
*ar
= file
->private_data
;
695 len
= scnprintf(buf
, sizeof(buf
), "0x%08x\n", ar
->chip_id
);
697 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
700 static const struct file_operations fops_chip_id
= {
701 .read
= ath10k_read_chip_id
,
703 .owner
= THIS_MODULE
,
704 .llseek
= default_llseek
,
707 struct ath10k_fw_crash_data
*
708 ath10k_debug_get_new_fw_crash_data(struct ath10k
*ar
)
710 struct ath10k_fw_crash_data
*crash_data
= ar
->debug
.fw_crash_data
;
712 lockdep_assert_held(&ar
->data_lock
);
714 crash_data
->crashed_since_read
= true;
715 uuid_le_gen(&crash_data
->uuid
);
716 getnstimeofday(&crash_data
->timestamp
);
720 EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data
);
722 static struct ath10k_dump_file_data
*ath10k_build_dump_file(struct ath10k
*ar
)
724 struct ath10k_fw_crash_data
*crash_data
= ar
->debug
.fw_crash_data
;
725 struct ath10k_dump_file_data
*dump_data
;
726 struct ath10k_tlv_dump_data
*dump_tlv
;
727 int hdr_len
= sizeof(*dump_data
);
728 unsigned int len
, sofar
= 0;
732 len
+= sizeof(*dump_tlv
) + sizeof(crash_data
->registers
);
736 /* This is going to get big when we start dumping FW RAM and such,
737 * so go ahead and use vmalloc.
743 spin_lock_bh(&ar
->data_lock
);
745 if (!crash_data
->crashed_since_read
) {
746 spin_unlock_bh(&ar
->data_lock
);
751 dump_data
= (struct ath10k_dump_file_data
*)(buf
);
752 strlcpy(dump_data
->df_magic
, "ATH10K-FW-DUMP",
753 sizeof(dump_data
->df_magic
));
754 dump_data
->len
= cpu_to_le32(len
);
756 dump_data
->version
= cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION
);
758 memcpy(dump_data
->uuid
, &crash_data
->uuid
, sizeof(dump_data
->uuid
));
759 dump_data
->chip_id
= cpu_to_le32(ar
->chip_id
);
760 dump_data
->bus_type
= cpu_to_le32(0);
761 dump_data
->target_version
= cpu_to_le32(ar
->target_version
);
762 dump_data
->fw_version_major
= cpu_to_le32(ar
->fw_version_major
);
763 dump_data
->fw_version_minor
= cpu_to_le32(ar
->fw_version_minor
);
764 dump_data
->fw_version_release
= cpu_to_le32(ar
->fw_version_release
);
765 dump_data
->fw_version_build
= cpu_to_le32(ar
->fw_version_build
);
766 dump_data
->phy_capability
= cpu_to_le32(ar
->phy_capability
);
767 dump_data
->hw_min_tx_power
= cpu_to_le32(ar
->hw_min_tx_power
);
768 dump_data
->hw_max_tx_power
= cpu_to_le32(ar
->hw_max_tx_power
);
769 dump_data
->ht_cap_info
= cpu_to_le32(ar
->ht_cap_info
);
770 dump_data
->vht_cap_info
= cpu_to_le32(ar
->vht_cap_info
);
771 dump_data
->num_rf_chains
= cpu_to_le32(ar
->num_rf_chains
);
773 strlcpy(dump_data
->fw_ver
, ar
->hw
->wiphy
->fw_version
,
774 sizeof(dump_data
->fw_ver
));
776 dump_data
->kernel_ver_code
= 0;
777 strlcpy(dump_data
->kernel_ver
, init_utsname()->release
,
778 sizeof(dump_data
->kernel_ver
));
780 dump_data
->tv_sec
= cpu_to_le64(crash_data
->timestamp
.tv_sec
);
781 dump_data
->tv_nsec
= cpu_to_le64(crash_data
->timestamp
.tv_nsec
);
783 /* Gather crash-dump */
784 dump_tlv
= (struct ath10k_tlv_dump_data
*)(buf
+ sofar
);
785 dump_tlv
->type
= cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS
);
786 dump_tlv
->tlv_len
= cpu_to_le32(sizeof(crash_data
->registers
));
787 memcpy(dump_tlv
->tlv_data
, &crash_data
->registers
,
788 sizeof(crash_data
->registers
));
789 sofar
+= sizeof(*dump_tlv
) + sizeof(crash_data
->registers
);
791 ar
->debug
.fw_crash_data
->crashed_since_read
= false;
793 spin_unlock_bh(&ar
->data_lock
);
798 static int ath10k_fw_crash_dump_open(struct inode
*inode
, struct file
*file
)
800 struct ath10k
*ar
= inode
->i_private
;
801 struct ath10k_dump_file_data
*dump
;
803 dump
= ath10k_build_dump_file(ar
);
807 file
->private_data
= dump
;
812 static ssize_t
ath10k_fw_crash_dump_read(struct file
*file
,
813 char __user
*user_buf
,
814 size_t count
, loff_t
*ppos
)
816 struct ath10k_dump_file_data
*dump_file
= file
->private_data
;
818 return simple_read_from_buffer(user_buf
, count
, ppos
,
820 le32_to_cpu(dump_file
->len
));
823 static int ath10k_fw_crash_dump_release(struct inode
*inode
,
826 vfree(file
->private_data
);
831 static const struct file_operations fops_fw_crash_dump
= {
832 .open
= ath10k_fw_crash_dump_open
,
833 .read
= ath10k_fw_crash_dump_read
,
834 .release
= ath10k_fw_crash_dump_release
,
835 .owner
= THIS_MODULE
,
836 .llseek
= default_llseek
,
839 static ssize_t
ath10k_reg_addr_read(struct file
*file
,
840 char __user
*user_buf
,
841 size_t count
, loff_t
*ppos
)
843 struct ath10k
*ar
= file
->private_data
;
845 unsigned int len
= 0;
848 mutex_lock(&ar
->conf_mutex
);
849 reg_addr
= ar
->debug
.reg_addr
;
850 mutex_unlock(&ar
->conf_mutex
);
852 len
+= scnprintf(buf
+ len
, sizeof(buf
) - len
, "0x%x\n", reg_addr
);
854 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
857 static ssize_t
ath10k_reg_addr_write(struct file
*file
,
858 const char __user
*user_buf
,
859 size_t count
, loff_t
*ppos
)
861 struct ath10k
*ar
= file
->private_data
;
865 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_addr
);
869 if (!IS_ALIGNED(reg_addr
, 4))
872 mutex_lock(&ar
->conf_mutex
);
873 ar
->debug
.reg_addr
= reg_addr
;
874 mutex_unlock(&ar
->conf_mutex
);
879 static const struct file_operations fops_reg_addr
= {
880 .read
= ath10k_reg_addr_read
,
881 .write
= ath10k_reg_addr_write
,
883 .owner
= THIS_MODULE
,
884 .llseek
= default_llseek
,
887 static ssize_t
ath10k_reg_value_read(struct file
*file
,
888 char __user
*user_buf
,
889 size_t count
, loff_t
*ppos
)
891 struct ath10k
*ar
= file
->private_data
;
894 u32 reg_addr
, reg_val
;
897 mutex_lock(&ar
->conf_mutex
);
899 if (ar
->state
!= ATH10K_STATE_ON
&&
900 ar
->state
!= ATH10K_STATE_UTF
) {
905 reg_addr
= ar
->debug
.reg_addr
;
907 reg_val
= ath10k_hif_read32(ar
, reg_addr
);
908 len
= scnprintf(buf
, sizeof(buf
), "0x%08x:0x%08x\n", reg_addr
, reg_val
);
910 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
913 mutex_unlock(&ar
->conf_mutex
);
918 static ssize_t
ath10k_reg_value_write(struct file
*file
,
919 const char __user
*user_buf
,
920 size_t count
, loff_t
*ppos
)
922 struct ath10k
*ar
= file
->private_data
;
923 u32 reg_addr
, reg_val
;
926 mutex_lock(&ar
->conf_mutex
);
928 if (ar
->state
!= ATH10K_STATE_ON
&&
929 ar
->state
!= ATH10K_STATE_UTF
) {
934 reg_addr
= ar
->debug
.reg_addr
;
936 ret
= kstrtou32_from_user(user_buf
, count
, 0, ®_val
);
940 ath10k_hif_write32(ar
, reg_addr
, reg_val
);
945 mutex_unlock(&ar
->conf_mutex
);
950 static const struct file_operations fops_reg_value
= {
951 .read
= ath10k_reg_value_read
,
952 .write
= ath10k_reg_value_write
,
954 .owner
= THIS_MODULE
,
955 .llseek
= default_llseek
,
958 static ssize_t
ath10k_mem_value_read(struct file
*file
,
959 char __user
*user_buf
,
960 size_t count
, loff_t
*ppos
)
962 struct ath10k
*ar
= file
->private_data
;
972 mutex_lock(&ar
->conf_mutex
);
974 buf
= vmalloc(count
);
980 if (ar
->state
!= ATH10K_STATE_ON
&&
981 ar
->state
!= ATH10K_STATE_UTF
) {
986 ret
= ath10k_hif_diag_read(ar
, *ppos
, buf
, count
);
988 ath10k_warn(ar
, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
993 ret
= copy_to_user(user_buf
, buf
, count
);
1005 mutex_unlock(&ar
->conf_mutex
);
1010 static ssize_t
ath10k_mem_value_write(struct file
*file
,
1011 const char __user
*user_buf
,
1012 size_t count
, loff_t
*ppos
)
1014 struct ath10k
*ar
= file
->private_data
;
1024 mutex_lock(&ar
->conf_mutex
);
1026 buf
= vmalloc(count
);
1032 if (ar
->state
!= ATH10K_STATE_ON
&&
1033 ar
->state
!= ATH10K_STATE_UTF
) {
1038 ret
= copy_from_user(buf
, user_buf
, count
);
1044 ret
= ath10k_hif_diag_write(ar
, *ppos
, buf
, count
);
1046 ath10k_warn(ar
, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1056 mutex_unlock(&ar
->conf_mutex
);
1061 static const struct file_operations fops_mem_value
= {
1062 .read
= ath10k_mem_value_read
,
1063 .write
= ath10k_mem_value_write
,
1064 .open
= simple_open
,
1065 .owner
= THIS_MODULE
,
1066 .llseek
= default_llseek
,
1069 static int ath10k_debug_htt_stats_req(struct ath10k
*ar
)
1074 lockdep_assert_held(&ar
->conf_mutex
);
1076 if (ar
->debug
.htt_stats_mask
== 0)
1077 /* htt stats are disabled */
1080 if (ar
->state
!= ATH10K_STATE_ON
)
1083 cookie
= get_jiffies_64();
1085 ret
= ath10k_htt_h2t_stats_req(&ar
->htt
, ar
->debug
.htt_stats_mask
,
1088 ath10k_warn(ar
, "failed to send htt stats request: %d\n", ret
);
1092 queue_delayed_work(ar
->workqueue
, &ar
->debug
.htt_stats_dwork
,
1093 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL
));
1098 static void ath10k_debug_htt_stats_dwork(struct work_struct
*work
)
1100 struct ath10k
*ar
= container_of(work
, struct ath10k
,
1101 debug
.htt_stats_dwork
.work
);
1103 mutex_lock(&ar
->conf_mutex
);
1105 ath10k_debug_htt_stats_req(ar
);
1107 mutex_unlock(&ar
->conf_mutex
);
1110 static ssize_t
ath10k_read_htt_stats_mask(struct file
*file
,
1111 char __user
*user_buf
,
1112 size_t count
, loff_t
*ppos
)
1114 struct ath10k
*ar
= file
->private_data
;
1118 len
= scnprintf(buf
, sizeof(buf
), "%lu\n", ar
->debug
.htt_stats_mask
);
1120 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1123 static ssize_t
ath10k_write_htt_stats_mask(struct file
*file
,
1124 const char __user
*user_buf
,
1125 size_t count
, loff_t
*ppos
)
1127 struct ath10k
*ar
= file
->private_data
;
1131 ret
= kstrtoul_from_user(user_buf
, count
, 0, &mask
);
1135 /* max 8 bit masks (for now) */
1139 mutex_lock(&ar
->conf_mutex
);
1141 ar
->debug
.htt_stats_mask
= mask
;
1143 ret
= ath10k_debug_htt_stats_req(ar
);
1150 mutex_unlock(&ar
->conf_mutex
);
1155 static const struct file_operations fops_htt_stats_mask
= {
1156 .read
= ath10k_read_htt_stats_mask
,
1157 .write
= ath10k_write_htt_stats_mask
,
1158 .open
= simple_open
,
1159 .owner
= THIS_MODULE
,
1160 .llseek
= default_llseek
,
1163 static ssize_t
ath10k_read_htt_max_amsdu_ampdu(struct file
*file
,
1164 char __user
*user_buf
,
1165 size_t count
, loff_t
*ppos
)
1167 struct ath10k
*ar
= file
->private_data
;
1172 mutex_lock(&ar
->conf_mutex
);
1174 amsdu
= ar
->htt
.max_num_amsdu
;
1175 ampdu
= ar
->htt
.max_num_ampdu
;
1176 mutex_unlock(&ar
->conf_mutex
);
1178 len
= scnprintf(buf
, sizeof(buf
), "%u %u\n", amsdu
, ampdu
);
1180 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1183 static ssize_t
ath10k_write_htt_max_amsdu_ampdu(struct file
*file
,
1184 const char __user
*user_buf
,
1185 size_t count
, loff_t
*ppos
)
1187 struct ath10k
*ar
= file
->private_data
;
1190 unsigned int amsdu
, ampdu
;
1192 simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
1194 /* make sure that buf is null terminated */
1195 buf
[sizeof(buf
) - 1] = 0;
1197 res
= sscanf(buf
, "%u %u", &amsdu
, &du
);
1202 mutex_lock(&ar
->conf_mutex
);
1204 res
= ath10k_htt_h2t_aggr_cfg_msg(&ar
->htt
, ampdu
, amsdu
);
1209 ar
->htt
.max_num_amsdu
= amsdu
;
1210 ar
->htt
.max_num_ampdu
= ampdu
;
1213 mutex_unlock(&ar
->conf_mutex
);
1217 static const struct file_operations fops_htt_max_amsdu_ampdu
= {
1218 .read
= ath10k_read_htt_max_amsdu_ampdu
,
1219 .write
= ath10k_write_htt_max_amsdu_ampdu
,
1220 .open
= simple_open
,
1221 .owner
= THIS_MODULE
,
1222 .llseek
= default_llseek
,
1225 static ssize_t
ath10k_read_fw_dbglog(struct file
*file
,
1226 char __user
*user_buf
,
1227 size_t count
, loff_t
*ppos
)
1229 struct ath10k
*ar
= file
->private_data
;
1233 len
= scnprintf(buf
, sizeof(buf
), "0x%08x %u\n",
1234 ar
->debug
.fw_dbglog_mask
, ar
->debug
.fw_dbglog_level
);
1236 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1239 static ssize_t
ath10k_write_fw_dbglog(struct file
*file
,
1240 const char __user
*user_buf
,
1241 size_t count
, loff_t
*ppos
)
1243 struct ath10k
*ar
= file
->private_data
;
1246 unsigned int log_level
, mask
;
1248 simple_write_to_buffer(buf
, sizeof(buf
) - 1, ppos
, user_buf
, count
);
1250 /* make sure that buf is null terminated */
1251 buf
[sizeof(buf
) - 1] = 0;
1253 ret
= sscanf(buf
, "%x %u", &mask
, &log_level
);
1259 /* default if user did not specify */
1260 log_level
= ATH10K_DBGLOG_LEVEL_WARN
;
1262 mutex_lock(&ar
->conf_mutex
);
1264 ar
->debug
.fw_dbglog_mask
= mask
;
1265 ar
->debug
.fw_dbglog_level
= log_level
;
1267 if (ar
->state
== ATH10K_STATE_ON
) {
1268 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1269 ar
->debug
.fw_dbglog_level
);
1271 ath10k_warn(ar
, "dbglog cfg failed from debugfs: %d\n",
1280 mutex_unlock(&ar
->conf_mutex
);
1285 /* TODO: Would be nice to always support ethtool stats, would need to
1286 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1287 * struct available..
1290 /* This generally cooresponds to the debugfs fw_stats file */
1291 static const char ath10k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1301 "d_tx_power", /* in .5 dbM I think */
1302 "d_rx_crc_err", /* fcs_bad */
1304 "d_tx_mpdus_queued",
1306 "d_tx_msdu_dropped",
1309 "d_tx_ppdu_hw_queued",
1311 "d_tx_fifo_underrun",
1314 "d_tx_excessive_retries",
1316 "d_tx_dropped_sw_retries",
1317 "d_tx_illegal_rate",
1318 "d_tx_continuous_xretries",
1320 "d_tx_mpdu_txop_limit",
1322 "d_rx_mid_ppdu_route_change",
1324 "d_rx_extra_frags_ring0",
1325 "d_rx_extra_frags_ring1",
1326 "d_rx_extra_frags_ring2",
1327 "d_rx_extra_frags_ring3",
1333 "d_rx_phy_err_drops",
1334 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1336 "d_fw_warm_reset_count",
1337 "d_fw_cold_reset_count",
1340 #define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1342 void ath10k_debug_get_et_strings(struct ieee80211_hw
*hw
,
1343 struct ieee80211_vif
*vif
,
1346 if (sset
== ETH_SS_STATS
)
1347 memcpy(data
, *ath10k_gstrings_stats
,
1348 sizeof(ath10k_gstrings_stats
));
1351 int ath10k_debug_get_et_sset_count(struct ieee80211_hw
*hw
,
1352 struct ieee80211_vif
*vif
, int sset
)
1354 if (sset
== ETH_SS_STATS
)
1355 return ATH10K_SSTATS_LEN
;
1360 void ath10k_debug_get_et_stats(struct ieee80211_hw
*hw
,
1361 struct ieee80211_vif
*vif
,
1362 struct ethtool_stats
*stats
, u64
*data
)
1364 struct ath10k
*ar
= hw
->priv
;
1365 static const struct ath10k_fw_stats_pdev zero_stats
= {};
1366 const struct ath10k_fw_stats_pdev
*pdev_stats
;
1369 mutex_lock(&ar
->conf_mutex
);
1371 if (ar
->state
== ATH10K_STATE_ON
) {
1372 ret
= ath10k_debug_fw_stats_request(ar
);
1374 /* just print a warning and try to use older results */
1376 "failed to get fw stats for ethtool: %d\n",
1381 pdev_stats
= list_first_entry_or_null(&ar
->debug
.fw_stats
.pdevs
,
1382 struct ath10k_fw_stats_pdev
,
1385 /* no results available so just return zeroes */
1386 pdev_stats
= &zero_stats
;
1389 spin_lock_bh(&ar
->data_lock
);
1391 data
[i
++] = pdev_stats
->hw_reaped
; /* ppdu reaped */
1392 data
[i
++] = 0; /* tx bytes */
1393 data
[i
++] = pdev_stats
->htt_mpdus
;
1394 data
[i
++] = 0; /* rx bytes */
1395 data
[i
++] = pdev_stats
->ch_noise_floor
;
1396 data
[i
++] = pdev_stats
->cycle_count
;
1397 data
[i
++] = pdev_stats
->phy_err_count
;
1398 data
[i
++] = pdev_stats
->rts_bad
;
1399 data
[i
++] = pdev_stats
->rts_good
;
1400 data
[i
++] = pdev_stats
->chan_tx_power
;
1401 data
[i
++] = pdev_stats
->fcs_bad
;
1402 data
[i
++] = pdev_stats
->no_beacons
;
1403 data
[i
++] = pdev_stats
->mpdu_enqued
;
1404 data
[i
++] = pdev_stats
->msdu_enqued
;
1405 data
[i
++] = pdev_stats
->wmm_drop
;
1406 data
[i
++] = pdev_stats
->local_enqued
;
1407 data
[i
++] = pdev_stats
->local_freed
;
1408 data
[i
++] = pdev_stats
->hw_queued
;
1409 data
[i
++] = pdev_stats
->hw_reaped
;
1410 data
[i
++] = pdev_stats
->underrun
;
1411 data
[i
++] = pdev_stats
->tx_abort
;
1412 data
[i
++] = pdev_stats
->mpdus_requed
;
1413 data
[i
++] = pdev_stats
->tx_ko
;
1414 data
[i
++] = pdev_stats
->data_rc
;
1415 data
[i
++] = pdev_stats
->sw_retry_failure
;
1416 data
[i
++] = pdev_stats
->illgl_rate_phy_err
;
1417 data
[i
++] = pdev_stats
->pdev_cont_xretry
;
1418 data
[i
++] = pdev_stats
->pdev_tx_timeout
;
1419 data
[i
++] = pdev_stats
->txop_ovf
;
1420 data
[i
++] = pdev_stats
->pdev_resets
;
1421 data
[i
++] = pdev_stats
->mid_ppdu_route_change
;
1422 data
[i
++] = pdev_stats
->status_rcvd
;
1423 data
[i
++] = pdev_stats
->r0_frags
;
1424 data
[i
++] = pdev_stats
->r1_frags
;
1425 data
[i
++] = pdev_stats
->r2_frags
;
1426 data
[i
++] = pdev_stats
->r3_frags
;
1427 data
[i
++] = pdev_stats
->htt_msdus
;
1428 data
[i
++] = pdev_stats
->htt_mpdus
;
1429 data
[i
++] = pdev_stats
->loc_msdus
;
1430 data
[i
++] = pdev_stats
->loc_mpdus
;
1431 data
[i
++] = pdev_stats
->phy_errs
;
1432 data
[i
++] = pdev_stats
->phy_err_drop
;
1433 data
[i
++] = pdev_stats
->mpdu_errs
;
1434 data
[i
++] = ar
->stats
.fw_crash_counter
;
1435 data
[i
++] = ar
->stats
.fw_warm_reset_counter
;
1436 data
[i
++] = ar
->stats
.fw_cold_reset_counter
;
1438 spin_unlock_bh(&ar
->data_lock
);
1440 mutex_unlock(&ar
->conf_mutex
);
1442 WARN_ON(i
!= ATH10K_SSTATS_LEN
);
1445 static const struct file_operations fops_fw_dbglog
= {
1446 .read
= ath10k_read_fw_dbglog
,
1447 .write
= ath10k_write_fw_dbglog
,
1448 .open
= simple_open
,
1449 .owner
= THIS_MODULE
,
1450 .llseek
= default_llseek
,
1453 static int ath10k_debug_cal_data_open(struct inode
*inode
, struct file
*file
)
1455 struct ath10k
*ar
= inode
->i_private
;
1461 mutex_lock(&ar
->conf_mutex
);
1463 if (ar
->state
!= ATH10K_STATE_ON
&&
1464 ar
->state
!= ATH10K_STATE_UTF
) {
1469 buf
= vmalloc(ar
->hw_params
.cal_data_len
);
1475 hi_addr
= host_interest_item_address(HI_ITEM(hi_board_data
));
1477 ret
= ath10k_hif_diag_read(ar
, hi_addr
, &addr
, sizeof(addr
));
1479 ath10k_warn(ar
, "failed to read hi_board_data address: %d\n", ret
);
1483 ret
= ath10k_hif_diag_read(ar
, le32_to_cpu(addr
), buf
,
1484 ar
->hw_params
.cal_data_len
);
1486 ath10k_warn(ar
, "failed to read calibration data: %d\n", ret
);
1490 file
->private_data
= buf
;
1492 mutex_unlock(&ar
->conf_mutex
);
1500 mutex_unlock(&ar
->conf_mutex
);
1505 static ssize_t
ath10k_debug_cal_data_read(struct file
*file
,
1506 char __user
*user_buf
,
1507 size_t count
, loff_t
*ppos
)
1509 struct ath10k
*ar
= file
->private_data
;
1510 void *buf
= file
->private_data
;
1512 return simple_read_from_buffer(user_buf
, count
, ppos
,
1513 buf
, ar
->hw_params
.cal_data_len
);
1516 static int ath10k_debug_cal_data_release(struct inode
*inode
,
1519 vfree(file
->private_data
);
1524 static ssize_t
ath10k_write_ani_enable(struct file
*file
,
1525 const char __user
*user_buf
,
1526 size_t count
, loff_t
*ppos
)
1528 struct ath10k
*ar
= file
->private_data
;
1532 if (kstrtou8_from_user(user_buf
, count
, 0, &enable
))
1535 mutex_lock(&ar
->conf_mutex
);
1537 if (ar
->ani_enabled
== enable
) {
1542 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->ani_enable
,
1545 ath10k_warn(ar
, "ani_enable failed from debugfs: %d\n", ret
);
1548 ar
->ani_enabled
= enable
;
1553 mutex_unlock(&ar
->conf_mutex
);
1558 static ssize_t
ath10k_read_ani_enable(struct file
*file
, char __user
*user_buf
,
1559 size_t count
, loff_t
*ppos
)
1561 struct ath10k
*ar
= file
->private_data
;
1565 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
1568 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1571 static const struct file_operations fops_ani_enable
= {
1572 .read
= ath10k_read_ani_enable
,
1573 .write
= ath10k_write_ani_enable
,
1574 .open
= simple_open
,
1575 .owner
= THIS_MODULE
,
1576 .llseek
= default_llseek
,
1579 static const struct file_operations fops_cal_data
= {
1580 .open
= ath10k_debug_cal_data_open
,
1581 .read
= ath10k_debug_cal_data_read
,
1582 .release
= ath10k_debug_cal_data_release
,
1583 .owner
= THIS_MODULE
,
1584 .llseek
= default_llseek
,
1587 static ssize_t
ath10k_read_nf_cal_period(struct file
*file
,
1588 char __user
*user_buf
,
1589 size_t count
, loff_t
*ppos
)
1591 struct ath10k
*ar
= file
->private_data
;
1595 len
= scnprintf(buf
, sizeof(buf
), "%d\n",
1596 ar
->debug
.nf_cal_period
);
1598 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1601 static ssize_t
ath10k_write_nf_cal_period(struct file
*file
,
1602 const char __user
*user_buf
,
1603 size_t count
, loff_t
*ppos
)
1605 struct ath10k
*ar
= file
->private_data
;
1606 unsigned long period
;
1609 ret
= kstrtoul_from_user(user_buf
, count
, 0, &period
);
1613 if (period
> WMI_PDEV_PARAM_CAL_PERIOD_MAX
)
1616 /* there's no way to switch back to the firmware default */
1620 mutex_lock(&ar
->conf_mutex
);
1622 ar
->debug
.nf_cal_period
= period
;
1624 if (ar
->state
!= ATH10K_STATE_ON
) {
1625 /* firmware is not running, nothing else to do */
1630 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->cal_period
,
1631 ar
->debug
.nf_cal_period
);
1633 ath10k_warn(ar
, "cal period cfg failed from debugfs: %d\n",
1641 mutex_unlock(&ar
->conf_mutex
);
1646 static const struct file_operations fops_nf_cal_period
= {
1647 .read
= ath10k_read_nf_cal_period
,
1648 .write
= ath10k_write_nf_cal_period
,
1649 .open
= simple_open
,
1650 .owner
= THIS_MODULE
,
1651 .llseek
= default_llseek
,
1654 #define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1656 static int ath10k_debug_tpc_stats_request(struct ath10k
*ar
)
1659 unsigned long time_left
;
1661 lockdep_assert_held(&ar
->conf_mutex
);
1663 reinit_completion(&ar
->debug
.tpc_complete
);
1665 ret
= ath10k_wmi_pdev_get_tpc_config(ar
, WMI_TPC_CONFIG_PARAM
);
1667 ath10k_warn(ar
, "failed to request tpc config: %d\n", ret
);
1671 time_left
= wait_for_completion_timeout(&ar
->debug
.tpc_complete
,
1679 void ath10k_debug_tpc_stats_process(struct ath10k
*ar
,
1680 struct ath10k_tpc_stats
*tpc_stats
)
1682 spin_lock_bh(&ar
->data_lock
);
1684 kfree(ar
->debug
.tpc_stats
);
1685 ar
->debug
.tpc_stats
= tpc_stats
;
1686 complete(&ar
->debug
.tpc_complete
);
1688 spin_unlock_bh(&ar
->data_lock
);
1691 static void ath10k_tpc_stats_print(struct ath10k_tpc_stats
*tpc_stats
,
1692 unsigned int j
, char *buf
, unsigned int *len
)
1694 unsigned int i
, buf_len
;
1695 static const char table_str
[][5] = { "CDD",
1698 static const char pream_str
[][6] = { "CCK",
1707 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1708 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1709 "********************************\n");
1710 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1711 "******************* %s POWER TABLE ****************\n",
1713 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1714 "********************************\n");
1715 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1716 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1718 for (i
= 0; i
< tpc_stats
->rate_max
; i
++) {
1719 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1720 "%8d %s 0x%2x %s\n", i
,
1721 pream_str
[tpc_stats
->tpc_table
[j
].pream_idx
[i
]],
1722 tpc_stats
->tpc_table
[j
].rate_code
[i
],
1723 tpc_stats
->tpc_table
[j
].tpc_value
[i
]);
1726 *len
+= scnprintf(buf
+ *len
, buf_len
- *len
,
1727 "***********************************\n");
1730 static void ath10k_tpc_stats_fill(struct ath10k
*ar
,
1731 struct ath10k_tpc_stats
*tpc_stats
,
1734 unsigned int len
, j
, buf_len
;
1737 buf_len
= ATH10K_TPC_CONFIG_BUF_SIZE
;
1739 spin_lock_bh(&ar
->data_lock
);
1742 ath10k_warn(ar
, "failed to get tpc stats\n");
1746 len
+= scnprintf(buf
+ len
, buf_len
- len
, "\n");
1747 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1748 "*************************************\n");
1749 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1750 "TPC config for channel %4d mode %d\n",
1751 tpc_stats
->chan_freq
,
1752 tpc_stats
->phy_mode
);
1753 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1754 "*************************************\n");
1755 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1756 "CTL = 0x%2x Reg. Domain = %2d\n",
1758 tpc_stats
->reg_domain
);
1759 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1760 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1761 tpc_stats
->twice_antenna_gain
,
1762 tpc_stats
->twice_antenna_reduction
);
1763 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1764 "Power Limit = %2d Reg. Max Power = %2d\n",
1765 tpc_stats
->power_limit
,
1766 tpc_stats
->twice_max_rd_power
/ 2);
1767 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1768 "Num tx chains = %2d Num supported rates = %2d\n",
1769 tpc_stats
->num_tx_chain
,
1770 tpc_stats
->rate_max
);
1772 for (j
= 0; j
< tpc_stats
->num_tx_chain
; j
++) {
1774 case WMI_TPC_TABLE_TYPE_CDD
:
1775 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1776 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1777 "CDD not supported\n");
1781 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1783 case WMI_TPC_TABLE_TYPE_STBC
:
1784 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1785 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1786 "STBC not supported\n");
1790 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1792 case WMI_TPC_TABLE_TYPE_TXBF
:
1793 if (tpc_stats
->flag
[j
] == ATH10K_TPC_TABLE_TYPE_FLAG
) {
1794 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1795 "TXBF not supported\n***************************\n");
1799 ath10k_tpc_stats_print(tpc_stats
, j
, buf
, &len
);
1802 len
+= scnprintf(buf
+ len
, buf_len
- len
,
1809 spin_unlock_bh(&ar
->data_lock
);
1817 static int ath10k_tpc_stats_open(struct inode
*inode
, struct file
*file
)
1819 struct ath10k
*ar
= inode
->i_private
;
1823 mutex_lock(&ar
->conf_mutex
);
1825 if (ar
->state
!= ATH10K_STATE_ON
) {
1830 buf
= vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE
);
1836 ret
= ath10k_debug_tpc_stats_request(ar
);
1838 ath10k_warn(ar
, "failed to request tpc config stats: %d\n",
1843 ath10k_tpc_stats_fill(ar
, ar
->debug
.tpc_stats
, buf
);
1844 file
->private_data
= buf
;
1846 mutex_unlock(&ar
->conf_mutex
);
1853 mutex_unlock(&ar
->conf_mutex
);
1857 static int ath10k_tpc_stats_release(struct inode
*inode
, struct file
*file
)
1859 vfree(file
->private_data
);
1864 static ssize_t
ath10k_tpc_stats_read(struct file
*file
, char __user
*user_buf
,
1865 size_t count
, loff_t
*ppos
)
1867 const char *buf
= file
->private_data
;
1868 unsigned int len
= strlen(buf
);
1870 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1873 static const struct file_operations fops_tpc_stats
= {
1874 .open
= ath10k_tpc_stats_open
,
1875 .release
= ath10k_tpc_stats_release
,
1876 .read
= ath10k_tpc_stats_read
,
1877 .owner
= THIS_MODULE
,
1878 .llseek
= default_llseek
,
1881 int ath10k_debug_start(struct ath10k
*ar
)
1885 lockdep_assert_held(&ar
->conf_mutex
);
1887 ret
= ath10k_debug_htt_stats_req(ar
);
1889 /* continue normally anyway, this isn't serious */
1890 ath10k_warn(ar
, "failed to start htt stats workqueue: %d\n",
1893 if (ar
->debug
.fw_dbglog_mask
) {
1894 ret
= ath10k_wmi_dbglog_cfg(ar
, ar
->debug
.fw_dbglog_mask
,
1895 ATH10K_DBGLOG_LEVEL_WARN
);
1898 ath10k_warn(ar
, "failed to enable dbglog during start: %d",
1902 if (ar
->debug
.pktlog_filter
) {
1903 ret
= ath10k_wmi_pdev_pktlog_enable(ar
,
1904 ar
->debug
.pktlog_filter
);
1908 "failed to enable pktlog filter %x: %d\n",
1909 ar
->debug
.pktlog_filter
, ret
);
1911 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
1914 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
1917 if (ar
->debug
.nf_cal_period
) {
1918 ret
= ath10k_wmi_pdev_set_param(ar
,
1919 ar
->wmi
.pdev_param
->cal_period
,
1920 ar
->debug
.nf_cal_period
);
1923 ath10k_warn(ar
, "cal period cfg failed from debug start: %d\n",
1930 void ath10k_debug_stop(struct ath10k
*ar
)
1932 lockdep_assert_held(&ar
->conf_mutex
);
1934 /* Must not use _sync to avoid deadlock, we do that in
1935 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1936 * warning from del_timer(). */
1937 if (ar
->debug
.htt_stats_mask
!= 0)
1938 cancel_delayed_work(&ar
->debug
.htt_stats_dwork
);
1940 ath10k_wmi_pdev_pktlog_disable(ar
);
1943 static ssize_t
ath10k_write_simulate_radar(struct file
*file
,
1944 const char __user
*user_buf
,
1945 size_t count
, loff_t
*ppos
)
1947 struct ath10k
*ar
= file
->private_data
;
1949 ieee80211_radar_detected(ar
->hw
);
1954 static const struct file_operations fops_simulate_radar
= {
1955 .write
= ath10k_write_simulate_radar
,
1956 .open
= simple_open
,
1957 .owner
= THIS_MODULE
,
1958 .llseek
= default_llseek
,
1961 #define ATH10K_DFS_STAT(s, p) (\
1962 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1963 ar->debug.dfs_stats.p))
1965 #define ATH10K_DFS_POOL_STAT(s, p) (\
1966 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1967 ar->debug.dfs_pool_stats.p))
1969 static ssize_t
ath10k_read_dfs_stats(struct file
*file
, char __user
*user_buf
,
1970 size_t count
, loff_t
*ppos
)
1972 int retval
= 0, len
= 0;
1973 const int size
= 8000;
1974 struct ath10k
*ar
= file
->private_data
;
1977 buf
= kzalloc(size
, GFP_KERNEL
);
1981 if (!ar
->dfs_detector
) {
1982 len
+= scnprintf(buf
+ len
, size
- len
, "DFS not enabled\n");
1986 ar
->debug
.dfs_pool_stats
=
1987 ar
->dfs_detector
->get_stats(ar
->dfs_detector
);
1989 len
+= scnprintf(buf
+ len
, size
- len
, "Pulse detector statistics:\n");
1991 ATH10K_DFS_STAT("reported phy errors", phy_errors
);
1992 ATH10K_DFS_STAT("pulse events reported", pulses_total
);
1993 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected
);
1994 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded
);
1995 ATH10K_DFS_STAT("Radars detected", radar_detected
);
1997 len
+= scnprintf(buf
+ len
, size
- len
, "Global Pool statistics:\n");
1998 ATH10K_DFS_POOL_STAT("Pool references", pool_reference
);
1999 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated
);
2000 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error
);
2001 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used
);
2002 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated
);
2003 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error
);
2004 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used
);
2010 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2016 static const struct file_operations fops_dfs_stats
= {
2017 .read
= ath10k_read_dfs_stats
,
2018 .open
= simple_open
,
2019 .owner
= THIS_MODULE
,
2020 .llseek
= default_llseek
,
2023 static ssize_t
ath10k_write_pktlog_filter(struct file
*file
,
2024 const char __user
*ubuf
,
2025 size_t count
, loff_t
*ppos
)
2027 struct ath10k
*ar
= file
->private_data
;
2031 if (kstrtouint_from_user(ubuf
, count
, 0, &filter
))
2034 mutex_lock(&ar
->conf_mutex
);
2036 if (ar
->state
!= ATH10K_STATE_ON
) {
2037 ar
->debug
.pktlog_filter
= filter
;
2042 if (filter
== ar
->debug
.pktlog_filter
) {
2048 ret
= ath10k_wmi_pdev_pktlog_enable(ar
, filter
);
2050 ath10k_warn(ar
, "failed to enable pktlog filter %x: %d\n",
2051 ar
->debug
.pktlog_filter
, ret
);
2055 ret
= ath10k_wmi_pdev_pktlog_disable(ar
);
2057 ath10k_warn(ar
, "failed to disable pktlog: %d\n", ret
);
2062 ar
->debug
.pktlog_filter
= filter
;
2066 mutex_unlock(&ar
->conf_mutex
);
2070 static ssize_t
ath10k_read_pktlog_filter(struct file
*file
, char __user
*ubuf
,
2071 size_t count
, loff_t
*ppos
)
2074 struct ath10k
*ar
= file
->private_data
;
2077 mutex_lock(&ar
->conf_mutex
);
2078 len
= scnprintf(buf
, sizeof(buf
) - len
, "%08x\n",
2079 ar
->debug
.pktlog_filter
);
2080 mutex_unlock(&ar
->conf_mutex
);
2082 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2085 static const struct file_operations fops_pktlog_filter
= {
2086 .read
= ath10k_read_pktlog_filter
,
2087 .write
= ath10k_write_pktlog_filter
,
2091 static ssize_t
ath10k_write_quiet_period(struct file
*file
,
2092 const char __user
*ubuf
,
2093 size_t count
, loff_t
*ppos
)
2095 struct ath10k
*ar
= file
->private_data
;
2098 if (kstrtouint_from_user(ubuf
, count
, 0, &period
))
2101 if (period
< ATH10K_QUIET_PERIOD_MIN
) {
2102 ath10k_warn(ar
, "Quiet period %u can not be lesser than 25ms\n",
2106 mutex_lock(&ar
->conf_mutex
);
2107 ar
->thermal
.quiet_period
= period
;
2108 ath10k_thermal_set_throttling(ar
);
2109 mutex_unlock(&ar
->conf_mutex
);
2114 static ssize_t
ath10k_read_quiet_period(struct file
*file
, char __user
*ubuf
,
2115 size_t count
, loff_t
*ppos
)
2118 struct ath10k
*ar
= file
->private_data
;
2121 mutex_lock(&ar
->conf_mutex
);
2122 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2123 ar
->thermal
.quiet_period
);
2124 mutex_unlock(&ar
->conf_mutex
);
2126 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2129 static const struct file_operations fops_quiet_period
= {
2130 .read
= ath10k_read_quiet_period
,
2131 .write
= ath10k_write_quiet_period
,
2135 static ssize_t
ath10k_write_btcoex(struct file
*file
,
2136 const char __user
*ubuf
,
2137 size_t count
, loff_t
*ppos
)
2139 struct ath10k
*ar
= file
->private_data
;
2146 buf_size
= min(count
, (sizeof(buf
) - 1));
2147 if (copy_from_user(buf
, ubuf
, buf_size
))
2150 buf
[buf_size
] = '\0';
2152 if (strtobool(buf
, &val
) != 0)
2155 mutex_lock(&ar
->conf_mutex
);
2157 if (ar
->state
!= ATH10K_STATE_ON
&&
2158 ar
->state
!= ATH10K_STATE_RESTARTED
) {
2163 if (!(test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
) ^ val
)) {
2168 pdev_param
= ar
->wmi
.pdev_param
->enable_btcoex
;
2169 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM
,
2170 ar
->running_fw
->fw_file
.fw_features
)) {
2171 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
, val
);
2173 ath10k_warn(ar
, "failed to enable btcoex: %d\n", ret
);
2178 ath10k_info(ar
, "restarting firmware due to btcoex change");
2179 queue_work(ar
->workqueue
, &ar
->restart_work
);
2183 set_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2185 clear_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
);
2190 mutex_unlock(&ar
->conf_mutex
);
2195 static ssize_t
ath10k_read_btcoex(struct file
*file
, char __user
*ubuf
,
2196 size_t count
, loff_t
*ppos
)
2199 struct ath10k
*ar
= file
->private_data
;
2202 mutex_lock(&ar
->conf_mutex
);
2203 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2204 test_bit(ATH10K_FLAG_BTCOEX
, &ar
->dev_flags
));
2205 mutex_unlock(&ar
->conf_mutex
);
2207 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2210 static const struct file_operations fops_btcoex
= {
2211 .read
= ath10k_read_btcoex
,
2212 .write
= ath10k_write_btcoex
,
2216 static ssize_t
ath10k_write_peer_stats(struct file
*file
,
2217 const char __user
*ubuf
,
2218 size_t count
, loff_t
*ppos
)
2220 struct ath10k
*ar
= file
->private_data
;
2226 buf_size
= min(count
, (sizeof(buf
) - 1));
2227 if (copy_from_user(buf
, ubuf
, buf_size
))
2230 buf
[buf_size
] = '\0';
2232 if (strtobool(buf
, &val
) != 0)
2235 mutex_lock(&ar
->conf_mutex
);
2237 if (ar
->state
!= ATH10K_STATE_ON
&&
2238 ar
->state
!= ATH10K_STATE_RESTARTED
) {
2243 if (!(test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
) ^ val
)) {
2249 set_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2251 clear_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
);
2253 ath10k_info(ar
, "restarting firmware due to Peer stats change");
2255 queue_work(ar
->workqueue
, &ar
->restart_work
);
2259 mutex_unlock(&ar
->conf_mutex
);
2263 static ssize_t
ath10k_read_peer_stats(struct file
*file
, char __user
*ubuf
,
2264 size_t count
, loff_t
*ppos
)
2268 struct ath10k
*ar
= file
->private_data
;
2271 mutex_lock(&ar
->conf_mutex
);
2272 len
= scnprintf(buf
, sizeof(buf
) - len
, "%d\n",
2273 test_bit(ATH10K_FLAG_PEER_STATS
, &ar
->dev_flags
));
2274 mutex_unlock(&ar
->conf_mutex
);
2276 return simple_read_from_buffer(ubuf
, count
, ppos
, buf
, len
);
2279 static const struct file_operations fops_peer_stats
= {
2280 .read
= ath10k_read_peer_stats
,
2281 .write
= ath10k_write_peer_stats
,
2285 static ssize_t
ath10k_debug_fw_checksums_read(struct file
*file
,
2286 char __user
*user_buf
,
2287 size_t count
, loff_t
*ppos
)
2289 struct ath10k
*ar
= file
->private_data
;
2290 unsigned int len
= 0, buf_len
= 4096;
2294 buf
= kzalloc(buf_len
, GFP_KERNEL
);
2298 mutex_lock(&ar
->conf_mutex
);
2300 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2301 "firmware-N.bin\t\t%08x\n",
2302 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware
->data
,
2303 ar
->normal_mode_fw
.fw_file
.firmware
->size
));
2304 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2305 "athwlan\t\t\t%08x\n",
2306 crc32_le(0, ar
->normal_mode_fw
.fw_file
.firmware_data
,
2307 ar
->normal_mode_fw
.fw_file
.firmware_len
));
2308 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2310 crc32_le(0, ar
->normal_mode_fw
.fw_file
.otp_data
,
2311 ar
->normal_mode_fw
.fw_file
.otp_len
));
2312 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2313 "codeswap\t\t%08x\n",
2314 crc32_le(0, ar
->normal_mode_fw
.fw_file
.codeswap_data
,
2315 ar
->normal_mode_fw
.fw_file
.codeswap_len
));
2316 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2317 "board-N.bin\t\t%08x\n",
2318 crc32_le(0, ar
->normal_mode_fw
.board
->data
,
2319 ar
->normal_mode_fw
.board
->size
));
2320 len
+= scnprintf(buf
+ len
, buf_len
- len
,
2321 "board\t\t\t%08x\n",
2322 crc32_le(0, ar
->normal_mode_fw
.board_data
,
2323 ar
->normal_mode_fw
.board_len
));
2325 ret_cnt
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
2327 mutex_unlock(&ar
->conf_mutex
);
2333 static const struct file_operations fops_fw_checksums
= {
2334 .read
= ath10k_debug_fw_checksums_read
,
2335 .open
= simple_open
,
2336 .owner
= THIS_MODULE
,
2337 .llseek
= default_llseek
,
2340 int ath10k_debug_create(struct ath10k
*ar
)
2342 ar
->debug
.fw_crash_data
= vzalloc(sizeof(*ar
->debug
.fw_crash_data
));
2343 if (!ar
->debug
.fw_crash_data
)
2346 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.pdevs
);
2347 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.vdevs
);
2348 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers
);
2349 INIT_LIST_HEAD(&ar
->debug
.fw_stats
.peers_extd
);
2354 void ath10k_debug_destroy(struct ath10k
*ar
)
2356 vfree(ar
->debug
.fw_crash_data
);
2357 ar
->debug
.fw_crash_data
= NULL
;
2359 ath10k_debug_fw_stats_reset(ar
);
2361 kfree(ar
->debug
.tpc_stats
);
2364 int ath10k_debug_register(struct ath10k
*ar
)
2366 ar
->debug
.debugfs_phy
= debugfs_create_dir("ath10k",
2367 ar
->hw
->wiphy
->debugfsdir
);
2368 if (IS_ERR_OR_NULL(ar
->debug
.debugfs_phy
)) {
2369 if (IS_ERR(ar
->debug
.debugfs_phy
))
2370 return PTR_ERR(ar
->debug
.debugfs_phy
);
2375 INIT_DELAYED_WORK(&ar
->debug
.htt_stats_dwork
,
2376 ath10k_debug_htt_stats_dwork
);
2378 init_completion(&ar
->debug
.tpc_complete
);
2379 init_completion(&ar
->debug
.fw_stats_complete
);
2381 debugfs_create_file("fw_stats", S_IRUSR
, ar
->debug
.debugfs_phy
, ar
,
2384 debugfs_create_file("fw_reset_stats", S_IRUSR
, ar
->debug
.debugfs_phy
,
2385 ar
, &fops_fw_reset_stats
);
2387 debugfs_create_file("wmi_services", S_IRUSR
, ar
->debug
.debugfs_phy
, ar
,
2388 &fops_wmi_services
);
2390 debugfs_create_file("simulate_fw_crash", S_IRUSR
| S_IWUSR
,
2391 ar
->debug
.debugfs_phy
, ar
, &fops_simulate_fw_crash
);
2393 debugfs_create_file("fw_crash_dump", S_IRUSR
, ar
->debug
.debugfs_phy
,
2394 ar
, &fops_fw_crash_dump
);
2396 debugfs_create_file("reg_addr", S_IRUSR
| S_IWUSR
,
2397 ar
->debug
.debugfs_phy
, ar
, &fops_reg_addr
);
2399 debugfs_create_file("reg_value", S_IRUSR
| S_IWUSR
,
2400 ar
->debug
.debugfs_phy
, ar
, &fops_reg_value
);
2402 debugfs_create_file("mem_value", S_IRUSR
| S_IWUSR
,
2403 ar
->debug
.debugfs_phy
, ar
, &fops_mem_value
);
2405 debugfs_create_file("chip_id", S_IRUSR
, ar
->debug
.debugfs_phy
,
2408 debugfs_create_file("htt_stats_mask", S_IRUSR
| S_IWUSR
,
2409 ar
->debug
.debugfs_phy
, ar
, &fops_htt_stats_mask
);
2411 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR
| S_IWUSR
,
2412 ar
->debug
.debugfs_phy
, ar
,
2413 &fops_htt_max_amsdu_ampdu
);
2415 debugfs_create_file("fw_dbglog", S_IRUSR
| S_IWUSR
,
2416 ar
->debug
.debugfs_phy
, ar
, &fops_fw_dbglog
);
2418 debugfs_create_file("cal_data", S_IRUSR
, ar
->debug
.debugfs_phy
,
2419 ar
, &fops_cal_data
);
2421 debugfs_create_file("ani_enable", S_IRUSR
| S_IWUSR
,
2422 ar
->debug
.debugfs_phy
, ar
, &fops_ani_enable
);
2424 debugfs_create_file("nf_cal_period", S_IRUSR
| S_IWUSR
,
2425 ar
->debug
.debugfs_phy
, ar
, &fops_nf_cal_period
);
2427 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED
)) {
2428 debugfs_create_file("dfs_simulate_radar", S_IWUSR
,
2429 ar
->debug
.debugfs_phy
, ar
,
2430 &fops_simulate_radar
);
2432 debugfs_create_bool("dfs_block_radar_events", S_IWUSR
,
2433 ar
->debug
.debugfs_phy
,
2434 &ar
->dfs_block_radar_events
);
2436 debugfs_create_file("dfs_stats", S_IRUSR
,
2437 ar
->debug
.debugfs_phy
, ar
,
2441 debugfs_create_file("pktlog_filter", S_IRUGO
| S_IWUSR
,
2442 ar
->debug
.debugfs_phy
, ar
, &fops_pktlog_filter
);
2444 debugfs_create_file("quiet_period", S_IRUGO
| S_IWUSR
,
2445 ar
->debug
.debugfs_phy
, ar
, &fops_quiet_period
);
2447 debugfs_create_file("tpc_stats", S_IRUSR
,
2448 ar
->debug
.debugfs_phy
, ar
, &fops_tpc_stats
);
2450 if (test_bit(WMI_SERVICE_COEX_GPIO
, ar
->wmi
.svc_map
))
2451 debugfs_create_file("btcoex", S_IRUGO
| S_IWUSR
,
2452 ar
->debug
.debugfs_phy
, ar
, &fops_btcoex
);
2454 if (test_bit(WMI_SERVICE_PEER_STATS
, ar
->wmi
.svc_map
))
2455 debugfs_create_file("peer_stats", S_IRUGO
| S_IWUSR
,
2456 ar
->debug
.debugfs_phy
, ar
,
2459 debugfs_create_file("fw_checksums", S_IRUSR
,
2460 ar
->debug
.debugfs_phy
, ar
, &fops_fw_checksums
);
2465 void ath10k_debug_unregister(struct ath10k
*ar
)
2467 cancel_delayed_work_sync(&ar
->debug
.htt_stats_dwork
);
2470 #endif /* CONFIG_ATH10K_DEBUGFS */
2472 #ifdef CONFIG_ATH10K_DEBUG
2473 void ath10k_dbg(struct ath10k
*ar
, enum ath10k_debug_mask mask
,
2474 const char *fmt
, ...)
2476 struct va_format vaf
;
2479 va_start(args
, fmt
);
2484 if (ath10k_debug_mask
& mask
)
2485 dev_printk(KERN_DEBUG
, ar
->dev
, "%pV", &vaf
);
2487 trace_ath10k_log_dbg(ar
, mask
, &vaf
);
2491 EXPORT_SYMBOL(ath10k_dbg
);
2493 void ath10k_dbg_dump(struct ath10k
*ar
,
2494 enum ath10k_debug_mask mask
,
2495 const char *msg
, const char *prefix
,
2496 const void *buf
, size_t len
)
2499 unsigned int linebuflen
;
2502 if (ath10k_debug_mask
& mask
) {
2504 ath10k_dbg(ar
, mask
, "%s\n", msg
);
2506 for (ptr
= buf
; (ptr
- buf
) < len
; ptr
+= 16) {
2508 linebuflen
+= scnprintf(linebuf
+ linebuflen
,
2509 sizeof(linebuf
) - linebuflen
,
2511 (prefix
? prefix
: ""),
2512 (unsigned int)(ptr
- buf
));
2513 hex_dump_to_buffer(ptr
, len
- (ptr
- buf
), 16, 1,
2514 linebuf
+ linebuflen
,
2515 sizeof(linebuf
) - linebuflen
, true);
2516 dev_printk(KERN_DEBUG
, ar
->dev
, "%s\n", linebuf
);
2520 /* tracing code doesn't like null strings :/ */
2521 trace_ath10k_log_dbg_dump(ar
, msg
? msg
: "", prefix
? prefix
: "",
2524 EXPORT_SYMBOL(ath10k_dbg_dump
);
2526 #endif /* CONFIG_ATH10K_DEBUG */