]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/ath/ath10k/debug.c
Merge remote-tracking branches 'asoc/topic/inntel', 'asoc/topic/input', 'asoc/topic...
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / ath / ath10k / debug.c
CommitLineData
5e3dd157
KV
1/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
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.
8 *
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.
16 */
17
18#include <linux/module.h>
19#include <linux/debugfs.h>
384914b2 20#include <linux/vmalloc.h>
12c27156 21#include <linux/utsname.h>
3e58044b
KV
22#include <linux/crc32.h>
23#include <linux/firmware.h>
5e3dd157
KV
24
25#include "core.h"
26#include "debug.h"
7869b4fa 27#include "hif.h"
d7579d12 28#include "wmi-ops.h"
5e3dd157 29
a3d135e5
KV
30/* ms */
31#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
32
f67b107d
MF
33#define ATH10K_DEBUG_CAL_DATA_LEN 12064
34
384914b2
BG
35#define ATH10K_FW_CRASH_DUMP_VERSION 1
36
37/**
38 * enum ath10k_fw_crash_dump_type - types of data in the dump file
39 * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
40 */
41enum ath10k_fw_crash_dump_type {
42 ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
43
44 ATH10K_FW_CRASH_DUMP_MAX,
45};
46
47struct ath10k_tlv_dump_data {
48 /* see ath10k_fw_crash_dump_type above */
49 __le32 type;
50
51 /* in bytes */
52 __le32 tlv_len;
53
54 /* pad to 32-bit boundaries as needed */
55 u8 tlv_data[];
56} __packed;
57
58struct ath10k_dump_file_data {
59 /* dump file information */
60
61 /* "ATH10K-FW-DUMP" */
62 char df_magic[16];
63
64 __le32 len;
65
66 /* file dump version */
67 __le32 version;
68
69 /* some info we can get from ath10k struct that might help */
70
71 u8 uuid[16];
72
73 __le32 chip_id;
74
75 /* 0 for now, in place for later hardware */
76 __le32 bus_type;
77
78 __le32 target_version;
79 __le32 fw_version_major;
80 __le32 fw_version_minor;
81 __le32 fw_version_release;
82 __le32 fw_version_build;
83 __le32 phy_capability;
84 __le32 hw_min_tx_power;
85 __le32 hw_max_tx_power;
86 __le32 ht_cap_info;
87 __le32 vht_cap_info;
88 __le32 num_rf_chains;
89
90 /* firmware version string */
91 char fw_ver[ETHTOOL_FWVERS_LEN];
92
93 /* Kernel related information */
94
95 /* time-of-day stamp */
96 __le64 tv_sec;
97
98 /* time-of-day stamp, nano-seconds */
99 __le64 tv_nsec;
100
101 /* LINUX_VERSION_CODE */
102 __le32 kernel_ver_code;
103
104 /* VERMAGIC_STRING */
105 char kernel_ver[64];
106
107 /* room for growth w/out changing binary format */
108 u8 unused[128];
109
110 /* struct ath10k_tlv_dump_data + more */
111 u8 data[0];
112} __packed;
113
babcb3ed 114void ath10k_info(struct ath10k *ar, const char *fmt, ...)
5e3dd157
KV
115{
116 struct va_format vaf = {
117 .fmt = fmt,
118 };
119 va_list args;
5e3dd157
KV
120
121 va_start(args, fmt);
122 vaf.va = &args;
babcb3ed 123 dev_info(ar->dev, "%pV", &vaf);
d35a6c18 124 trace_ath10k_log_info(ar, &vaf);
5e3dd157 125 va_end(args);
5e3dd157
KV
126}
127EXPORT_SYMBOL(ath10k_info);
128
23f591ea 129void ath10k_debug_print_hwfw_info(struct ath10k *ar)
8a0c797e 130{
7ebf721d 131 const struct firmware *firmware;
84e3df60 132 char fw_features[128] = {};
8866c727 133 u32 crc = 0;
b27bc5a4
MK
134
135 ath10k_core_get_fw_features_str(ar, fw_features, sizeof(fw_features));
136
8605c022 137 ath10k_info(ar, "%s target 0x%08x chip_id 0x%08x sub %04x:%04x",
8a0c797e
KV
138 ar->hw_params.name,
139 ar->target_version,
140 ar->chip_id,
8605c022 141 ar->id.subsystem_vendor, ar->id.subsystem_device);
f0de90bc 142
23f591ea 143 ath10k_info(ar, "kconfig debug %d debugfs %d tracing %d dfs %d testmode %d\n",
97f2645f
MY
144 IS_ENABLED(CONFIG_ATH10K_DEBUG),
145 IS_ENABLED(CONFIG_ATH10K_DEBUGFS),
146 IS_ENABLED(CONFIG_ATH10K_TRACING),
147 IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED),
148 IS_ENABLED(CONFIG_NL80211_TESTMODE));
23f591ea 149
7ebf721d
KV
150 firmware = ar->normal_mode_fw.fw_file.firmware;
151 if (firmware)
152 crc = crc32_le(0, firmware->data, firmware->size);
8866c727 153
3e58044b 154 ath10k_info(ar, "firmware ver %s api %d features %s crc32 %08x\n",
8a0c797e
KV
155 ar->hw->wiphy->fw_version,
156 ar->fw_api,
3e58044b 157 fw_features,
8866c727 158 crc);
23f591ea
KV
159}
160
161void ath10k_debug_print_board_info(struct ath10k *ar)
162{
163 char boardinfo[100];
164
165 if (ar->id.bmi_ids_valid)
166 scnprintf(boardinfo, sizeof(boardinfo), "%d:%d",
167 ar->id.bmi_chip_id, ar->id.bmi_board_id);
168 else
169 scnprintf(boardinfo, sizeof(boardinfo), "N/A");
f0de90bc 170
3e58044b 171 ath10k_info(ar, "board_file api %d bmi_id %s crc32 %08x",
8605c022 172 ar->bd_api,
3e58044b 173 boardinfo,
7ebf721d
KV
174 crc32_le(0, ar->normal_mode_fw.board->data,
175 ar->normal_mode_fw.board->size));
23f591ea 176}
f0de90bc 177
23f591ea
KV
178void ath10k_debug_print_boot_info(struct ath10k *ar)
179{
f0de90bc 180 ath10k_info(ar, "htt-ver %d.%d wmi-op %d htt-op %d cal %s max-sta %d raw %d hwcrypto %d\n",
8a0c797e 181 ar->htt.target_version_major,
34b28b6e 182 ar->htt.target_version_minor,
bf3c13ab 183 ar->normal_mode_fw.fw_file.wmi_op_version,
77561f93 184 ar->normal_mode_fw.fw_file.htt_op_version,
cfd1061e 185 ath10k_cal_mode_str(ar->cal_mode),
b27bc5a4 186 ar->max_num_stations,
ccec9038 187 test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags),
f0de90bc 188 !test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags));
8a0c797e 189}
23f591ea
KV
190
191void ath10k_print_driver_info(struct ath10k *ar)
192{
193 ath10k_debug_print_hwfw_info(ar);
194 ath10k_debug_print_board_info(ar);
195 ath10k_debug_print_boot_info(ar);
196}
8a0c797e
KV
197EXPORT_SYMBOL(ath10k_print_driver_info);
198
babcb3ed 199void ath10k_err(struct ath10k *ar, const char *fmt, ...)
5e3dd157
KV
200{
201 struct va_format vaf = {
202 .fmt = fmt,
203 };
204 va_list args;
5e3dd157
KV
205
206 va_start(args, fmt);
207 vaf.va = &args;
babcb3ed 208 dev_err(ar->dev, "%pV", &vaf);
d35a6c18 209 trace_ath10k_log_err(ar, &vaf);
5e3dd157 210 va_end(args);
5e3dd157
KV
211}
212EXPORT_SYMBOL(ath10k_err);
213
babcb3ed 214void ath10k_warn(struct ath10k *ar, const char *fmt, ...)
5e3dd157
KV
215{
216 struct va_format vaf = {
217 .fmt = fmt,
218 };
219 va_list args;
5e3dd157
KV
220
221 va_start(args, fmt);
222 vaf.va = &args;
7aa7a72a 223 dev_warn_ratelimited(ar->dev, "%pV", &vaf);
d35a6c18 224 trace_ath10k_log_warn(ar, &vaf);
5e3dd157
KV
225
226 va_end(args);
5e3dd157
KV
227}
228EXPORT_SYMBOL(ath10k_warn);
229
230#ifdef CONFIG_ATH10K_DEBUGFS
231
5e3dd157
KV
232static ssize_t ath10k_read_wmi_services(struct file *file,
233 char __user *user_buf,
234 size_t count, loff_t *ppos)
235{
236 struct ath10k *ar = file->private_data;
237 char *buf;
cff990ce
MK
238 unsigned int len = 0, buf_len = 4096;
239 const char *name;
5e3dd157 240 ssize_t ret_cnt;
cff990ce 241 bool enabled;
5e3dd157
KV
242 int i;
243
244 buf = kzalloc(buf_len, GFP_KERNEL);
245 if (!buf)
246 return -ENOMEM;
247
248 mutex_lock(&ar->conf_mutex);
249
250 if (len > buf_len)
251 len = buf_len;
252
acfe7ecf 253 spin_lock_bh(&ar->data_lock);
c4f8c836 254 for (i = 0; i < WMI_SERVICE_MAX; i++) {
acfe7ecf 255 enabled = test_bit(i, ar->wmi.svc_map);
cff990ce
MK
256 name = wmi_service_name(i);
257
258 if (!name) {
259 if (enabled)
260 len += scnprintf(buf + len, buf_len - len,
261 "%-40s %s (bit %d)\n",
262 "unknown", "enabled", i);
263
264 continue;
265 }
5e3dd157
KV
266
267 len += scnprintf(buf + len, buf_len - len,
cff990ce
MK
268 "%-40s %s\n",
269 name, enabled ? "enabled" : "-");
5e3dd157 270 }
acfe7ecf 271 spin_unlock_bh(&ar->data_lock);
5e3dd157
KV
272
273 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
274
275 mutex_unlock(&ar->conf_mutex);
276
277 kfree(buf);
278 return ret_cnt;
279}
280
281static const struct file_operations fops_wmi_services = {
282 .read = ath10k_read_wmi_services,
283 .open = simple_open,
284 .owner = THIS_MODULE,
285 .llseek = default_llseek,
286};
287
b4619ea2 288static void ath10k_fw_stats_pdevs_free(struct list_head *head)
5326849a
MK
289{
290 struct ath10k_fw_stats_pdev *i, *tmp;
291
292 list_for_each_entry_safe(i, tmp, head, list) {
293 list_del(&i->list);
294 kfree(i);
295 }
296}
297
b4619ea2 298static void ath10k_fw_stats_vdevs_free(struct list_head *head)
7b6b153a
MK
299{
300 struct ath10k_fw_stats_vdev *i, *tmp;
301
302 list_for_each_entry_safe(i, tmp, head, list) {
303 list_del(&i->list);
304 kfree(i);
305 }
306}
307
b4619ea2 308static void ath10k_fw_stats_peers_free(struct list_head *head)
5326849a
MK
309{
310 struct ath10k_fw_stats_peer *i, *tmp;
311
312 list_for_each_entry_safe(i, tmp, head, list) {
313 list_del(&i->list);
314 kfree(i);
315 }
316}
317
4a49ae94
MSS
318static void ath10k_fw_extd_stats_peers_free(struct list_head *head)
319{
320 struct ath10k_fw_extd_stats_peer *i, *tmp;
321
322 list_for_each_entry_safe(i, tmp, head, list) {
323 list_del(&i->list);
324 kfree(i);
325 }
326}
327
5326849a
MK
328static void ath10k_debug_fw_stats_reset(struct ath10k *ar)
329{
330 spin_lock_bh(&ar->data_lock);
331 ar->debug.fw_stats_done = false;
4a49ae94 332 ar->debug.fw_stats.extended = false;
b4619ea2
MSS
333 ath10k_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
334 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
335 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
4a49ae94 336 ath10k_fw_extd_stats_peers_free(&ar->debug.fw_stats.peers_extd);
5326849a
MK
337 spin_unlock_bh(&ar->data_lock);
338}
339
60ef401a 340void ath10k_debug_fw_stats_process(struct ath10k *ar, struct sk_buff *skb)
5e3dd157 341{
5326849a 342 struct ath10k_fw_stats stats = {};
cc61a1bb 343 bool is_start, is_started, is_end;
5326849a 344 size_t num_peers;
7b6b153a 345 size_t num_vdevs;
d15fb520 346 int ret;
5e3dd157 347
5326849a 348 INIT_LIST_HEAD(&stats.pdevs);
7b6b153a 349 INIT_LIST_HEAD(&stats.vdevs);
5326849a 350 INIT_LIST_HEAD(&stats.peers);
4a49ae94 351 INIT_LIST_HEAD(&stats.peers_extd);
5e3dd157 352
5326849a
MK
353 spin_lock_bh(&ar->data_lock);
354 ret = ath10k_wmi_pull_fw_stats(ar, skb, &stats);
d15fb520
MK
355 if (ret) {
356 ath10k_warn(ar, "failed to pull fw stats: %d\n", ret);
5db879ae 357 goto free;
5e3dd157
KV
358 }
359
5326849a
MK
360 /* Stat data may exceed htc-wmi buffer limit. In such case firmware
361 * splits the stats data and delivers it in a ping-pong fashion of
362 * request cmd-update event.
363 *
364 * However there is no explicit end-of-data. Instead start-of-data is
365 * used as an implicit one. This works as follows:
366 * a) discard stat update events until one with pdev stats is
367 * delivered - this skips session started at end of (b)
368 * b) consume stat update events until another one with pdev stats is
369 * delivered which is treated as end-of-data and is itself discarded
370 */
cc61a1bb 371 if (ath10k_peer_stats_enabled(ar))
4a49ae94 372 ath10k_sta_update_rx_duration(ar, &stats);
74135f59 373
e0b6ce00 374 if (ar->debug.fw_stats_done) {
cc61a1bb 375 if (!ath10k_peer_stats_enabled(ar))
e0b6ce00
MSS
376 ath10k_warn(ar, "received unsolicited stats update event\n");
377
5326849a
MK
378 goto free;
379 }
380
bc6f9ae6
MP
381 num_peers = ath10k_wmi_fw_stats_num_peers(&ar->debug.fw_stats.peers);
382 num_vdevs = ath10k_wmi_fw_stats_num_vdevs(&ar->debug.fw_stats.vdevs);
5326849a
MK
383 is_start = (list_empty(&ar->debug.fw_stats.pdevs) &&
384 !list_empty(&stats.pdevs));
385 is_end = (!list_empty(&ar->debug.fw_stats.pdevs) &&
386 !list_empty(&stats.pdevs));
387
388 if (is_start)
389 list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
390
391 if (is_end)
392 ar->debug.fw_stats_done = true;
393
394 is_started = !list_empty(&ar->debug.fw_stats.pdevs);
395
396 if (is_started && !is_end) {
397 if (num_peers >= ATH10K_MAX_NUM_PEER_IDS) {
398 /* Although this is unlikely impose a sane limit to
399 * prevent firmware from DoS-ing the host.
400 */
d57e7f2e 401 ath10k_fw_stats_peers_free(&ar->debug.fw_stats.peers);
5326849a
MK
402 ath10k_warn(ar, "dropping fw peer stats\n");
403 goto free;
404 }
405
7b6b153a 406 if (num_vdevs >= BITS_PER_LONG) {
d57e7f2e 407 ath10k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
7b6b153a
MK
408 ath10k_warn(ar, "dropping fw vdev stats\n");
409 goto free;
410 }
411
5326849a 412 list_splice_tail_init(&stats.peers, &ar->debug.fw_stats.peers);
7b6b153a 413 list_splice_tail_init(&stats.vdevs, &ar->debug.fw_stats.vdevs);
4a49ae94
MSS
414 list_splice_tail_init(&stats.peers_extd,
415 &ar->debug.fw_stats.peers_extd);
5326849a
MK
416 }
417
60ef401a 418 complete(&ar->debug.fw_stats_complete);
5e3dd157 419
5326849a
MK
420free:
421 /* In some cases lists have been spliced and cleared. Free up
422 * resources if that is not the case.
423 */
b4619ea2
MSS
424 ath10k_fw_stats_pdevs_free(&stats.pdevs);
425 ath10k_fw_stats_vdevs_free(&stats.vdevs);
426 ath10k_fw_stats_peers_free(&stats.peers);
4a49ae94 427 ath10k_fw_extd_stats_peers_free(&stats.peers_extd);
5326849a 428
87571bf0 429 spin_unlock_bh(&ar->data_lock);
5e3dd157
KV
430}
431
5326849a 432static int ath10k_debug_fw_stats_request(struct ath10k *ar)
5e3dd157 433{
6e8d5438 434 unsigned long timeout, time_left;
5e3dd157
KV
435 int ret;
436
fb2e9c0c 437 lockdep_assert_held(&ar->conf_mutex);
5e3dd157 438
6e8d5438 439 timeout = jiffies + msecs_to_jiffies(1 * HZ);
5326849a
MK
440
441 ath10k_debug_fw_stats_reset(ar);
442
443 for (;;) {
444 if (time_after(jiffies, timeout))
445 return -ETIMEDOUT;
446
447 reinit_completion(&ar->debug.fw_stats_complete);
448
6274cd41 449 ret = ath10k_wmi_request_stats(ar, ar->fw_stats_req_mask);
5326849a
MK
450 if (ret) {
451 ath10k_warn(ar, "could not request stats (%d)\n", ret);
452 return ret;
453 }
5e3dd157 454
6e8d5438
NMG
455 time_left =
456 wait_for_completion_timeout(&ar->debug.fw_stats_complete,
457 1 * HZ);
458 if (!time_left)
5326849a
MK
459 return -ETIMEDOUT;
460
461 spin_lock_bh(&ar->data_lock);
462 if (ar->debug.fw_stats_done) {
463 spin_unlock_bh(&ar->data_lock);
464 break;
465 }
466 spin_unlock_bh(&ar->data_lock);
467 }
fb2e9c0c
MK
468
469 return 0;
470}
471
fb2e9c0c
MK
472static int ath10k_fw_stats_open(struct inode *inode, struct file *file)
473{
474 struct ath10k *ar = inode->i_private;
475 void *buf = NULL;
476 int ret;
477
478 mutex_lock(&ar->conf_mutex);
479
480 if (ar->state != ATH10K_STATE_ON) {
481 ret = -ENETDOWN;
482 goto err_unlock;
483 }
484
485 buf = vmalloc(ATH10K_FW_STATS_BUF_SIZE);
486 if (!buf) {
487 ret = -ENOMEM;
488 goto err_unlock;
489 }
490
5326849a 491 ret = ath10k_debug_fw_stats_request(ar);
fb2e9c0c
MK
492 if (ret) {
493 ath10k_warn(ar, "failed to request fw stats: %d\n", ret);
494 goto err_free;
495 }
496
bc6f9ae6
MP
497 ret = ath10k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, buf);
498 if (ret) {
499 ath10k_warn(ar, "failed to fill fw stats: %d\n", ret);
500 goto err_free;
501 }
502
fb2e9c0c 503 file->private_data = buf;
5e3dd157
KV
504
505 mutex_unlock(&ar->conf_mutex);
fb2e9c0c
MK
506 return 0;
507
508err_free:
509 vfree(buf);
510
511err_unlock:
512 mutex_unlock(&ar->conf_mutex);
513 return ret;
514}
515
516static int ath10k_fw_stats_release(struct inode *inode, struct file *file)
517{
518 vfree(file->private_data);
519
520 return 0;
521}
522
523static ssize_t ath10k_fw_stats_read(struct file *file, char __user *user_buf,
524 size_t count, loff_t *ppos)
525{
526 const char *buf = file->private_data;
527 unsigned int len = strlen(buf);
528
529 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
5e3dd157
KV
530}
531
532static const struct file_operations fops_fw_stats = {
fb2e9c0c
MK
533 .open = ath10k_fw_stats_open,
534 .release = ath10k_fw_stats_release,
60ef401a 535 .read = ath10k_fw_stats_read,
5e3dd157
KV
536 .owner = THIS_MODULE,
537 .llseek = default_llseek,
538};
539
f51dbe73
BG
540static ssize_t ath10k_debug_fw_reset_stats_read(struct file *file,
541 char __user *user_buf,
542 size_t count, loff_t *ppos)
543{
544 struct ath10k *ar = file->private_data;
545 int ret, len, buf_len;
546 char *buf;
547
548 buf_len = 500;
549 buf = kmalloc(buf_len, GFP_KERNEL);
550 if (!buf)
551 return -ENOMEM;
552
553 spin_lock_bh(&ar->data_lock);
554
555 len = 0;
556 len += scnprintf(buf + len, buf_len - len,
557 "fw_crash_counter\t\t%d\n", ar->stats.fw_crash_counter);
558 len += scnprintf(buf + len, buf_len - len,
559 "fw_warm_reset_counter\t\t%d\n",
560 ar->stats.fw_warm_reset_counter);
561 len += scnprintf(buf + len, buf_len - len,
562 "fw_cold_reset_counter\t\t%d\n",
563 ar->stats.fw_cold_reset_counter);
564
565 spin_unlock_bh(&ar->data_lock);
566
567 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
568
569 kfree(buf);
570
571 return ret;
572}
573
574static const struct file_operations fops_fw_reset_stats = {
575 .open = simple_open,
576 .read = ath10k_debug_fw_reset_stats_read,
577 .owner = THIS_MODULE,
578 .llseek = default_llseek,
579};
580
d5aebc77
BG
581/* This is a clean assert crash in firmware. */
582static int ath10k_debug_fw_assert(struct ath10k *ar)
583{
584 struct wmi_vdev_install_key_cmd *cmd;
585 struct sk_buff *skb;
586
587 skb = ath10k_wmi_alloc_skb(ar, sizeof(*cmd) + 16);
588 if (!skb)
589 return -ENOMEM;
590
591 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
592 memset(cmd, 0, sizeof(*cmd));
593
594 /* big enough number so that firmware asserts */
595 cmd->vdev_id = __cpu_to_le32(0x7ffe);
596
597 return ath10k_wmi_cmd_send(ar, skb,
598 ar->wmi.cmd->vdev_install_key_cmdid);
599}
600
278c4a85
MK
601static ssize_t ath10k_read_simulate_fw_crash(struct file *file,
602 char __user *user_buf,
603 size_t count, loff_t *ppos)
604{
75cb96d3
KV
605 const char buf[] =
606 "To simulate firmware crash write one of the keywords to this file:\n"
607 "`soft` - this will send WMI_FORCE_FW_HANG_ASSERT to firmware if FW supports that command.\n"
608 "`hard` - this will send to firmware command with illegal parameters causing firmware crash.\n"
605cdba1
MK
609 "`assert` - this will send special illegal parameter to firmware to cause assert failure and crash.\n"
610 "`hw-restart` - this will simply queue hw restart without fw/hw actually crashing.\n";
8c656992 611
278c4a85
MK
612 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
613}
614
8c656992
MP
615/* Simulate firmware crash:
616 * 'soft': Call wmi command causing firmware hang. This firmware hang is
617 * recoverable by warm firmware reset.
618 * 'hard': Force firmware crash by setting any vdev parameter for not allowed
619 * vdev id. This is hard firmware crash because it is recoverable only by cold
620 * firmware reset.
621 */
278c4a85
MK
622static ssize_t ath10k_write_simulate_fw_crash(struct file *file,
623 const char __user *user_buf,
624 size_t count, loff_t *ppos)
625{
626 struct ath10k *ar = file->private_data;
8c656992 627 char buf[32];
278c4a85
MK
628 int ret;
629
278c4a85 630 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
8c656992
MP
631
632 /* make sure that buf is null terminated */
633 buf[sizeof(buf) - 1] = 0;
278c4a85 634
f5e30751
MSS
635 /* drop the possible '\n' from the end */
636 if (buf[count - 1] == '\n')
637 buf[count - 1] = 0;
638
639 mutex_lock(&ar->conf_mutex);
640
278c4a85
MK
641 if (ar->state != ATH10K_STATE_ON &&
642 ar->state != ATH10K_STATE_RESTARTED) {
643 ret = -ENETDOWN;
644 goto exit;
645 }
646
8c656992 647 if (!strcmp(buf, "soft")) {
7aa7a72a 648 ath10k_info(ar, "simulating soft firmware crash\n");
8c656992
MP
649 ret = ath10k_wmi_force_fw_hang(ar, WMI_FORCE_FW_HANG_ASSERT, 0);
650 } else if (!strcmp(buf, "hard")) {
7aa7a72a 651 ath10k_info(ar, "simulating hard firmware crash\n");
611b3682
BG
652 /* 0x7fff is vdev id, and it is always out of range for all
653 * firmware variants in order to force a firmware crash.
654 */
655 ret = ath10k_wmi_vdev_set_param(ar, 0x7fff,
5b07e07f
KV
656 ar->wmi.vdev_param->rts_threshold,
657 0);
d5aebc77
BG
658 } else if (!strcmp(buf, "assert")) {
659 ath10k_info(ar, "simulating firmware assert crash\n");
660 ret = ath10k_debug_fw_assert(ar);
605cdba1
MK
661 } else if (!strcmp(buf, "hw-restart")) {
662 ath10k_info(ar, "user requested hw restart\n");
663 queue_work(ar->workqueue, &ar->restart_work);
664 ret = 0;
8c656992
MP
665 } else {
666 ret = -EINVAL;
667 goto exit;
668 }
278c4a85 669
8c656992 670 if (ret) {
7aa7a72a 671 ath10k_warn(ar, "failed to simulate firmware crash: %d\n", ret);
8c656992
MP
672 goto exit;
673 }
278c4a85 674
8c656992 675 ret = count;
278c4a85
MK
676
677exit:
678 mutex_unlock(&ar->conf_mutex);
679 return ret;
680}
681
682static const struct file_operations fops_simulate_fw_crash = {
683 .read = ath10k_read_simulate_fw_crash,
684 .write = ath10k_write_simulate_fw_crash,
685 .open = simple_open,
686 .owner = THIS_MODULE,
687 .llseek = default_llseek,
688};
689
763b8cd3
KV
690static ssize_t ath10k_read_chip_id(struct file *file, char __user *user_buf,
691 size_t count, loff_t *ppos)
692{
693 struct ath10k *ar = file->private_data;
694 unsigned int len;
695 char buf[50];
696
697 len = scnprintf(buf, sizeof(buf), "0x%08x\n", ar->chip_id);
698
699 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
700}
701
702static const struct file_operations fops_chip_id = {
703 .read = ath10k_read_chip_id,
704 .open = simple_open,
705 .owner = THIS_MODULE,
706 .llseek = default_llseek,
707};
708
384914b2
BG
709struct ath10k_fw_crash_data *
710ath10k_debug_get_new_fw_crash_data(struct ath10k *ar)
711{
712 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
713
714 lockdep_assert_held(&ar->data_lock);
715
716 crash_data->crashed_since_read = true;
717 uuid_le_gen(&crash_data->uuid);
718 getnstimeofday(&crash_data->timestamp);
719
720 return crash_data;
721}
722EXPORT_SYMBOL(ath10k_debug_get_new_fw_crash_data);
723
724static struct ath10k_dump_file_data *ath10k_build_dump_file(struct ath10k *ar)
725{
726 struct ath10k_fw_crash_data *crash_data = ar->debug.fw_crash_data;
727 struct ath10k_dump_file_data *dump_data;
728 struct ath10k_tlv_dump_data *dump_tlv;
729 int hdr_len = sizeof(*dump_data);
730 unsigned int len, sofar = 0;
731 unsigned char *buf;
732
733 len = hdr_len;
734 len += sizeof(*dump_tlv) + sizeof(crash_data->registers);
735
736 sofar += hdr_len;
737
738 /* This is going to get big when we start dumping FW RAM and such,
739 * so go ahead and use vmalloc.
740 */
741 buf = vzalloc(len);
742 if (!buf)
743 return NULL;
744
745 spin_lock_bh(&ar->data_lock);
746
747 if (!crash_data->crashed_since_read) {
748 spin_unlock_bh(&ar->data_lock);
749 vfree(buf);
750 return NULL;
751 }
752
753 dump_data = (struct ath10k_dump_file_data *)(buf);
754 strlcpy(dump_data->df_magic, "ATH10K-FW-DUMP",
755 sizeof(dump_data->df_magic));
756 dump_data->len = cpu_to_le32(len);
757
758 dump_data->version = cpu_to_le32(ATH10K_FW_CRASH_DUMP_VERSION);
759
760 memcpy(dump_data->uuid, &crash_data->uuid, sizeof(dump_data->uuid));
761 dump_data->chip_id = cpu_to_le32(ar->chip_id);
762 dump_data->bus_type = cpu_to_le32(0);
763 dump_data->target_version = cpu_to_le32(ar->target_version);
764 dump_data->fw_version_major = cpu_to_le32(ar->fw_version_major);
765 dump_data->fw_version_minor = cpu_to_le32(ar->fw_version_minor);
766 dump_data->fw_version_release = cpu_to_le32(ar->fw_version_release);
767 dump_data->fw_version_build = cpu_to_le32(ar->fw_version_build);
768 dump_data->phy_capability = cpu_to_le32(ar->phy_capability);
769 dump_data->hw_min_tx_power = cpu_to_le32(ar->hw_min_tx_power);
770 dump_data->hw_max_tx_power = cpu_to_le32(ar->hw_max_tx_power);
771 dump_data->ht_cap_info = cpu_to_le32(ar->ht_cap_info);
772 dump_data->vht_cap_info = cpu_to_le32(ar->vht_cap_info);
773 dump_data->num_rf_chains = cpu_to_le32(ar->num_rf_chains);
774
775 strlcpy(dump_data->fw_ver, ar->hw->wiphy->fw_version,
776 sizeof(dump_data->fw_ver));
777
12c27156
JB
778 dump_data->kernel_ver_code = 0;
779 strlcpy(dump_data->kernel_ver, init_utsname()->release,
384914b2
BG
780 sizeof(dump_data->kernel_ver));
781
782 dump_data->tv_sec = cpu_to_le64(crash_data->timestamp.tv_sec);
783 dump_data->tv_nsec = cpu_to_le64(crash_data->timestamp.tv_nsec);
784
785 /* Gather crash-dump */
786 dump_tlv = (struct ath10k_tlv_dump_data *)(buf + sofar);
787 dump_tlv->type = cpu_to_le32(ATH10K_FW_CRASH_DUMP_REGISTERS);
788 dump_tlv->tlv_len = cpu_to_le32(sizeof(crash_data->registers));
789 memcpy(dump_tlv->tlv_data, &crash_data->registers,
790 sizeof(crash_data->registers));
791 sofar += sizeof(*dump_tlv) + sizeof(crash_data->registers);
792
793 ar->debug.fw_crash_data->crashed_since_read = false;
794
795 spin_unlock_bh(&ar->data_lock);
796
797 return dump_data;
798}
799
800static int ath10k_fw_crash_dump_open(struct inode *inode, struct file *file)
801{
802 struct ath10k *ar = inode->i_private;
803 struct ath10k_dump_file_data *dump;
804
805 dump = ath10k_build_dump_file(ar);
806 if (!dump)
807 return -ENODATA;
808
809 file->private_data = dump;
810
811 return 0;
812}
813
814static ssize_t ath10k_fw_crash_dump_read(struct file *file,
815 char __user *user_buf,
816 size_t count, loff_t *ppos)
817{
818 struct ath10k_dump_file_data *dump_file = file->private_data;
819
820 return simple_read_from_buffer(user_buf, count, ppos,
821 dump_file,
822 le32_to_cpu(dump_file->len));
823}
824
825static int ath10k_fw_crash_dump_release(struct inode *inode,
826 struct file *file)
827{
828 vfree(file->private_data);
829
830 return 0;
831}
832
833static const struct file_operations fops_fw_crash_dump = {
834 .open = ath10k_fw_crash_dump_open,
835 .read = ath10k_fw_crash_dump_read,
836 .release = ath10k_fw_crash_dump_release,
837 .owner = THIS_MODULE,
838 .llseek = default_llseek,
839};
840
077a3804
YL
841static ssize_t ath10k_reg_addr_read(struct file *file,
842 char __user *user_buf,
843 size_t count, loff_t *ppos)
844{
845 struct ath10k *ar = file->private_data;
846 u8 buf[32];
847 unsigned int len = 0;
848 u32 reg_addr;
849
850 mutex_lock(&ar->conf_mutex);
851 reg_addr = ar->debug.reg_addr;
852 mutex_unlock(&ar->conf_mutex);
853
854 len += scnprintf(buf + len, sizeof(buf) - len, "0x%x\n", reg_addr);
855
856 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
857}
858
859static ssize_t ath10k_reg_addr_write(struct file *file,
860 const char __user *user_buf,
861 size_t count, loff_t *ppos)
862{
863 struct ath10k *ar = file->private_data;
864 u32 reg_addr;
865 int ret;
866
867 ret = kstrtou32_from_user(user_buf, count, 0, &reg_addr);
868 if (ret)
869 return ret;
870
871 if (!IS_ALIGNED(reg_addr, 4))
872 return -EFAULT;
873
874 mutex_lock(&ar->conf_mutex);
875 ar->debug.reg_addr = reg_addr;
876 mutex_unlock(&ar->conf_mutex);
877
878 return count;
879}
880
881static const struct file_operations fops_reg_addr = {
882 .read = ath10k_reg_addr_read,
883 .write = ath10k_reg_addr_write,
884 .open = simple_open,
885 .owner = THIS_MODULE,
886 .llseek = default_llseek,
887};
888
889static ssize_t ath10k_reg_value_read(struct file *file,
890 char __user *user_buf,
891 size_t count, loff_t *ppos)
892{
893 struct ath10k *ar = file->private_data;
894 u8 buf[48];
895 unsigned int len;
896 u32 reg_addr, reg_val;
897 int ret;
898
899 mutex_lock(&ar->conf_mutex);
900
901 if (ar->state != ATH10K_STATE_ON &&
902 ar->state != ATH10K_STATE_UTF) {
903 ret = -ENETDOWN;
904 goto exit;
905 }
906
907 reg_addr = ar->debug.reg_addr;
908
909 reg_val = ath10k_hif_read32(ar, reg_addr);
910 len = scnprintf(buf, sizeof(buf), "0x%08x:0x%08x\n", reg_addr, reg_val);
911
912 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
913
914exit:
915 mutex_unlock(&ar->conf_mutex);
916
917 return ret;
918}
919
920static ssize_t ath10k_reg_value_write(struct file *file,
921 const char __user *user_buf,
922 size_t count, loff_t *ppos)
923{
924 struct ath10k *ar = file->private_data;
925 u32 reg_addr, reg_val;
926 int ret;
927
928 mutex_lock(&ar->conf_mutex);
929
930 if (ar->state != ATH10K_STATE_ON &&
931 ar->state != ATH10K_STATE_UTF) {
932 ret = -ENETDOWN;
933 goto exit;
934 }
935
936 reg_addr = ar->debug.reg_addr;
937
938 ret = kstrtou32_from_user(user_buf, count, 0, &reg_val);
939 if (ret)
940 goto exit;
941
942 ath10k_hif_write32(ar, reg_addr, reg_val);
943
944 ret = count;
945
946exit:
947 mutex_unlock(&ar->conf_mutex);
948
949 return ret;
950}
951
952static const struct file_operations fops_reg_value = {
953 .read = ath10k_reg_value_read,
954 .write = ath10k_reg_value_write,
955 .open = simple_open,
956 .owner = THIS_MODULE,
957 .llseek = default_llseek,
958};
959
9f65ad25
YL
960static ssize_t ath10k_mem_value_read(struct file *file,
961 char __user *user_buf,
962 size_t count, loff_t *ppos)
963{
964 struct ath10k *ar = file->private_data;
965 u8 *buf;
966 int ret;
967
968 if (*ppos < 0)
969 return -EINVAL;
970
971 if (!count)
972 return 0;
973
974 mutex_lock(&ar->conf_mutex);
975
976 buf = vmalloc(count);
977 if (!buf) {
978 ret = -ENOMEM;
979 goto exit;
980 }
981
982 if (ar->state != ATH10K_STATE_ON &&
983 ar->state != ATH10K_STATE_UTF) {
984 ret = -ENETDOWN;
985 goto exit;
986 }
987
988 ret = ath10k_hif_diag_read(ar, *ppos, buf, count);
989 if (ret) {
990 ath10k_warn(ar, "failed to read address 0x%08x via diagnose window fnrom debugfs: %d\n",
991 (u32)(*ppos), ret);
992 goto exit;
993 }
994
995 ret = copy_to_user(user_buf, buf, count);
996 if (ret) {
997 ret = -EFAULT;
998 goto exit;
999 }
1000
1001 count -= ret;
1002 *ppos += count;
1003 ret = count;
1004
1005exit:
1006 vfree(buf);
1007 mutex_unlock(&ar->conf_mutex);
1008
1009 return ret;
1010}
1011
1012static ssize_t ath10k_mem_value_write(struct file *file,
1013 const char __user *user_buf,
1014 size_t count, loff_t *ppos)
1015{
1016 struct ath10k *ar = file->private_data;
1017 u8 *buf;
1018 int ret;
1019
1020 if (*ppos < 0)
1021 return -EINVAL;
1022
1023 if (!count)
1024 return 0;
1025
1026 mutex_lock(&ar->conf_mutex);
1027
1028 buf = vmalloc(count);
1029 if (!buf) {
1030 ret = -ENOMEM;
1031 goto exit;
1032 }
1033
1034 if (ar->state != ATH10K_STATE_ON &&
1035 ar->state != ATH10K_STATE_UTF) {
1036 ret = -ENETDOWN;
1037 goto exit;
1038 }
1039
1040 ret = copy_from_user(buf, user_buf, count);
1041 if (ret) {
1042 ret = -EFAULT;
1043 goto exit;
1044 }
1045
1046 ret = ath10k_hif_diag_write(ar, *ppos, buf, count);
1047 if (ret) {
1048 ath10k_warn(ar, "failed to write address 0x%08x via diagnose window from debugfs: %d\n",
1049 (u32)(*ppos), ret);
1050 goto exit;
1051 }
1052
1053 *ppos += count;
1054 ret = count;
1055
1056exit:
1057 vfree(buf);
1058 mutex_unlock(&ar->conf_mutex);
1059
1060 return ret;
1061}
1062
1063static const struct file_operations fops_mem_value = {
1064 .read = ath10k_mem_value_read,
1065 .write = ath10k_mem_value_write,
1066 .open = simple_open,
1067 .owner = THIS_MODULE,
1068 .llseek = default_llseek,
1069};
1070
a3d135e5
KV
1071static int ath10k_debug_htt_stats_req(struct ath10k *ar)
1072{
1073 u64 cookie;
1074 int ret;
1075
1076 lockdep_assert_held(&ar->conf_mutex);
1077
1078 if (ar->debug.htt_stats_mask == 0)
1079 /* htt stats are disabled */
1080 return 0;
1081
1082 if (ar->state != ATH10K_STATE_ON)
1083 return 0;
1084
1085 cookie = get_jiffies_64();
1086
1087 ret = ath10k_htt_h2t_stats_req(&ar->htt, ar->debug.htt_stats_mask,
1088 cookie);
1089 if (ret) {
7aa7a72a 1090 ath10k_warn(ar, "failed to send htt stats request: %d\n", ret);
a3d135e5
KV
1091 return ret;
1092 }
1093
1094 queue_delayed_work(ar->workqueue, &ar->debug.htt_stats_dwork,
1095 msecs_to_jiffies(ATH10K_DEBUG_HTT_STATS_INTERVAL));
1096
1097 return 0;
1098}
1099
1100static void ath10k_debug_htt_stats_dwork(struct work_struct *work)
1101{
1102 struct ath10k *ar = container_of(work, struct ath10k,
1103 debug.htt_stats_dwork.work);
1104
1105 mutex_lock(&ar->conf_mutex);
1106
1107 ath10k_debug_htt_stats_req(ar);
1108
1109 mutex_unlock(&ar->conf_mutex);
1110}
1111
1112static ssize_t ath10k_read_htt_stats_mask(struct file *file,
5b07e07f
KV
1113 char __user *user_buf,
1114 size_t count, loff_t *ppos)
a3d135e5
KV
1115{
1116 struct ath10k *ar = file->private_data;
1117 char buf[32];
1118 unsigned int len;
1119
1120 len = scnprintf(buf, sizeof(buf), "%lu\n", ar->debug.htt_stats_mask);
1121
1122 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1123}
1124
1125static ssize_t ath10k_write_htt_stats_mask(struct file *file,
5b07e07f
KV
1126 const char __user *user_buf,
1127 size_t count, loff_t *ppos)
a3d135e5
KV
1128{
1129 struct ath10k *ar = file->private_data;
1130 unsigned long mask;
1131 int ret;
1132
1133 ret = kstrtoul_from_user(user_buf, count, 0, &mask);
1134 if (ret)
1135 return ret;
1136
1137 /* max 8 bit masks (for now) */
1138 if (mask > 0xff)
1139 return -E2BIG;
1140
1141 mutex_lock(&ar->conf_mutex);
1142
1143 ar->debug.htt_stats_mask = mask;
1144
1145 ret = ath10k_debug_htt_stats_req(ar);
1146 if (ret)
1147 goto out;
1148
1149 ret = count;
1150
1151out:
1152 mutex_unlock(&ar->conf_mutex);
1153
1154 return ret;
1155}
1156
1157static const struct file_operations fops_htt_stats_mask = {
1158 .read = ath10k_read_htt_stats_mask,
1159 .write = ath10k_write_htt_stats_mask,
1160 .open = simple_open,
1161 .owner = THIS_MODULE,
1162 .llseek = default_llseek,
1163};
1164
d385623a
JD
1165static ssize_t ath10k_read_htt_max_amsdu_ampdu(struct file *file,
1166 char __user *user_buf,
1167 size_t count, loff_t *ppos)
1168{
1169 struct ath10k *ar = file->private_data;
1170 char buf[64];
81ec3c09 1171 u8 amsdu, ampdu;
d385623a
JD
1172 unsigned int len;
1173
1174 mutex_lock(&ar->conf_mutex);
1175
ccec9038
DL
1176 amsdu = ar->htt.max_num_amsdu;
1177 ampdu = ar->htt.max_num_ampdu;
d385623a
JD
1178 mutex_unlock(&ar->conf_mutex);
1179
1180 len = scnprintf(buf, sizeof(buf), "%u %u\n", amsdu, ampdu);
1181
1182 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1183}
1184
1185static ssize_t ath10k_write_htt_max_amsdu_ampdu(struct file *file,
1186 const char __user *user_buf,
1187 size_t count, loff_t *ppos)
1188{
1189 struct ath10k *ar = file->private_data;
1190 int res;
1191 char buf[64];
1192 unsigned int amsdu, ampdu;
1193
1194 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1195
1196 /* make sure that buf is null terminated */
1197 buf[sizeof(buf) - 1] = 0;
1198
1199 res = sscanf(buf, "%u %u", &amsdu, &ampdu);
1200
1201 if (res != 2)
1202 return -EINVAL;
1203
1204 mutex_lock(&ar->conf_mutex);
1205
1206 res = ath10k_htt_h2t_aggr_cfg_msg(&ar->htt, ampdu, amsdu);
1207 if (res)
1208 goto out;
1209
1210 res = count;
ccec9038
DL
1211 ar->htt.max_num_amsdu = amsdu;
1212 ar->htt.max_num_ampdu = ampdu;
d385623a
JD
1213
1214out:
1215 mutex_unlock(&ar->conf_mutex);
1216 return res;
1217}
1218
1219static const struct file_operations fops_htt_max_amsdu_ampdu = {
1220 .read = ath10k_read_htt_max_amsdu_ampdu,
1221 .write = ath10k_write_htt_max_amsdu_ampdu,
1222 .open = simple_open,
1223 .owner = THIS_MODULE,
1224 .llseek = default_llseek,
1225};
1226
f118a3e5 1227static ssize_t ath10k_read_fw_dbglog(struct file *file,
5b07e07f
KV
1228 char __user *user_buf,
1229 size_t count, loff_t *ppos)
f118a3e5
KV
1230{
1231 struct ath10k *ar = file->private_data;
1232 unsigned int len;
afcbc82c 1233 char buf[96];
f118a3e5 1234
afcbc82c 1235 len = scnprintf(buf, sizeof(buf), "0x%16llx %u\n",
467210a6 1236 ar->debug.fw_dbglog_mask, ar->debug.fw_dbglog_level);
f118a3e5
KV
1237
1238 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1239}
1240
1241static ssize_t ath10k_write_fw_dbglog(struct file *file,
1242 const char __user *user_buf,
1243 size_t count, loff_t *ppos)
1244{
1245 struct ath10k *ar = file->private_data;
f118a3e5 1246 int ret;
afcbc82c
MK
1247 char buf[96];
1248 unsigned int log_level;
1249 u64 mask;
f118a3e5 1250
467210a6
SJ
1251 simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count);
1252
1253 /* make sure that buf is null terminated */
1254 buf[sizeof(buf) - 1] = 0;
1255
afcbc82c 1256 ret = sscanf(buf, "%llx %u", &mask, &log_level);
467210a6
SJ
1257
1258 if (!ret)
1259 return -EINVAL;
1260
1261 if (ret == 1)
1262 /* default if user did not specify */
1263 log_level = ATH10K_DBGLOG_LEVEL_WARN;
f118a3e5
KV
1264
1265 mutex_lock(&ar->conf_mutex);
1266
1267 ar->debug.fw_dbglog_mask = mask;
467210a6 1268 ar->debug.fw_dbglog_level = log_level;
f118a3e5
KV
1269
1270 if (ar->state == ATH10K_STATE_ON) {
467210a6
SJ
1271 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1272 ar->debug.fw_dbglog_level);
f118a3e5 1273 if (ret) {
7aa7a72a 1274 ath10k_warn(ar, "dbglog cfg failed from debugfs: %d\n",
f118a3e5
KV
1275 ret);
1276 goto exit;
1277 }
1278 }
1279
1280 ret = count;
1281
1282exit:
1283 mutex_unlock(&ar->conf_mutex);
1284
1285 return ret;
1286}
1287
6cddcc7a
BG
1288/* TODO: Would be nice to always support ethtool stats, would need to
1289 * move the stats storage out of ath10k_debug, or always have ath10k_debug
1290 * struct available..
1291 */
1292
1293/* This generally cooresponds to the debugfs fw_stats file */
1294static const char ath10k_gstrings_stats[][ETH_GSTRING_LEN] = {
1295 "tx_pkts_nic",
1296 "tx_bytes_nic",
1297 "rx_pkts_nic",
1298 "rx_bytes_nic",
1299 "d_noise_floor",
1300 "d_cycle_count",
1301 "d_phy_error",
1302 "d_rts_bad",
1303 "d_rts_good",
1304 "d_tx_power", /* in .5 dbM I think */
1305 "d_rx_crc_err", /* fcs_bad */
1306 "d_no_beacon",
1307 "d_tx_mpdus_queued",
1308 "d_tx_msdu_queued",
1309 "d_tx_msdu_dropped",
1310 "d_local_enqued",
1311 "d_local_freed",
1312 "d_tx_ppdu_hw_queued",
1313 "d_tx_ppdu_reaped",
1314 "d_tx_fifo_underrun",
1315 "d_tx_ppdu_abort",
1316 "d_tx_mpdu_requed",
1317 "d_tx_excessive_retries",
1318 "d_tx_hw_rate",
1319 "d_tx_dropped_sw_retries",
1320 "d_tx_illegal_rate",
1321 "d_tx_continuous_xretries",
1322 "d_tx_timeout",
1323 "d_tx_mpdu_txop_limit",
1324 "d_pdev_resets",
1325 "d_rx_mid_ppdu_route_change",
1326 "d_rx_status",
1327 "d_rx_extra_frags_ring0",
1328 "d_rx_extra_frags_ring1",
1329 "d_rx_extra_frags_ring2",
1330 "d_rx_extra_frags_ring3",
1331 "d_rx_msdu_htt",
1332 "d_rx_mpdu_htt",
1333 "d_rx_msdu_stack",
1334 "d_rx_mpdu_stack",
1335 "d_rx_phy_err",
1336 "d_rx_phy_err_drops",
1337 "d_rx_mpdu_errors", /* FCS, MIC, ENC */
1338 "d_fw_crash_count",
1339 "d_fw_warm_reset_count",
1340 "d_fw_cold_reset_count",
1341};
1342
1343#define ATH10K_SSTATS_LEN ARRAY_SIZE(ath10k_gstrings_stats)
1344
1345void ath10k_debug_get_et_strings(struct ieee80211_hw *hw,
1346 struct ieee80211_vif *vif,
1347 u32 sset, u8 *data)
1348{
1349 if (sset == ETH_SS_STATS)
1350 memcpy(data, *ath10k_gstrings_stats,
1351 sizeof(ath10k_gstrings_stats));
1352}
1353
1354int ath10k_debug_get_et_sset_count(struct ieee80211_hw *hw,
1355 struct ieee80211_vif *vif, int sset)
1356{
1357 if (sset == ETH_SS_STATS)
1358 return ATH10K_SSTATS_LEN;
1359
1360 return 0;
1361}
1362
1363void ath10k_debug_get_et_stats(struct ieee80211_hw *hw,
1364 struct ieee80211_vif *vif,
1365 struct ethtool_stats *stats, u64 *data)
1366{
1367 struct ath10k *ar = hw->priv;
1368 static const struct ath10k_fw_stats_pdev zero_stats = {};
1369 const struct ath10k_fw_stats_pdev *pdev_stats;
1370 int i = 0, ret;
1371
1372 mutex_lock(&ar->conf_mutex);
1373
1374 if (ar->state == ATH10K_STATE_ON) {
1375 ret = ath10k_debug_fw_stats_request(ar);
1376 if (ret) {
1377 /* just print a warning and try to use older results */
1378 ath10k_warn(ar,
1379 "failed to get fw stats for ethtool: %d\n",
1380 ret);
1381 }
1382 }
1383
1384 pdev_stats = list_first_entry_or_null(&ar->debug.fw_stats.pdevs,
1385 struct ath10k_fw_stats_pdev,
1386 list);
1387 if (!pdev_stats) {
1388 /* no results available so just return zeroes */
1389 pdev_stats = &zero_stats;
1390 }
1391
1392 spin_lock_bh(&ar->data_lock);
1393
1394 data[i++] = pdev_stats->hw_reaped; /* ppdu reaped */
1395 data[i++] = 0; /* tx bytes */
1396 data[i++] = pdev_stats->htt_mpdus;
1397 data[i++] = 0; /* rx bytes */
1398 data[i++] = pdev_stats->ch_noise_floor;
1399 data[i++] = pdev_stats->cycle_count;
1400 data[i++] = pdev_stats->phy_err_count;
1401 data[i++] = pdev_stats->rts_bad;
1402 data[i++] = pdev_stats->rts_good;
1403 data[i++] = pdev_stats->chan_tx_power;
1404 data[i++] = pdev_stats->fcs_bad;
1405 data[i++] = pdev_stats->no_beacons;
1406 data[i++] = pdev_stats->mpdu_enqued;
1407 data[i++] = pdev_stats->msdu_enqued;
1408 data[i++] = pdev_stats->wmm_drop;
1409 data[i++] = pdev_stats->local_enqued;
1410 data[i++] = pdev_stats->local_freed;
1411 data[i++] = pdev_stats->hw_queued;
1412 data[i++] = pdev_stats->hw_reaped;
1413 data[i++] = pdev_stats->underrun;
1414 data[i++] = pdev_stats->tx_abort;
1415 data[i++] = pdev_stats->mpdus_requed;
1416 data[i++] = pdev_stats->tx_ko;
1417 data[i++] = pdev_stats->data_rc;
1418 data[i++] = pdev_stats->sw_retry_failure;
1419 data[i++] = pdev_stats->illgl_rate_phy_err;
1420 data[i++] = pdev_stats->pdev_cont_xretry;
1421 data[i++] = pdev_stats->pdev_tx_timeout;
1422 data[i++] = pdev_stats->txop_ovf;
1423 data[i++] = pdev_stats->pdev_resets;
1424 data[i++] = pdev_stats->mid_ppdu_route_change;
1425 data[i++] = pdev_stats->status_rcvd;
1426 data[i++] = pdev_stats->r0_frags;
1427 data[i++] = pdev_stats->r1_frags;
1428 data[i++] = pdev_stats->r2_frags;
1429 data[i++] = pdev_stats->r3_frags;
1430 data[i++] = pdev_stats->htt_msdus;
1431 data[i++] = pdev_stats->htt_mpdus;
1432 data[i++] = pdev_stats->loc_msdus;
1433 data[i++] = pdev_stats->loc_mpdus;
1434 data[i++] = pdev_stats->phy_errs;
1435 data[i++] = pdev_stats->phy_err_drop;
1436 data[i++] = pdev_stats->mpdu_errs;
1437 data[i++] = ar->stats.fw_crash_counter;
1438 data[i++] = ar->stats.fw_warm_reset_counter;
1439 data[i++] = ar->stats.fw_cold_reset_counter;
1440
1441 spin_unlock_bh(&ar->data_lock);
1442
1443 mutex_unlock(&ar->conf_mutex);
1444
1445 WARN_ON(i != ATH10K_SSTATS_LEN);
1446}
1447
f118a3e5
KV
1448static const struct file_operations fops_fw_dbglog = {
1449 .read = ath10k_read_fw_dbglog,
1450 .write = ath10k_write_fw_dbglog,
1451 .open = simple_open,
1452 .owner = THIS_MODULE,
1453 .llseek = default_llseek,
1454};
1455
f67b107d 1456static int ath10k_debug_cal_data_fetch(struct ath10k *ar)
7869b4fa 1457{
7869b4fa
KV
1458 u32 hi_addr;
1459 __le32 addr;
1460 int ret;
1461
f67b107d 1462 lockdep_assert_held(&ar->conf_mutex);
7869b4fa 1463
f67b107d
MF
1464 if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN))
1465 return -EINVAL;
7869b4fa
KV
1466
1467 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1468
1469 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1470 if (ret) {
f67b107d
MF
1471 ath10k_warn(ar, "failed to read hi_board_data address: %d\n",
1472 ret);
1473 return ret;
7869b4fa
KV
1474 }
1475
f67b107d 1476 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), ar->debug.cal_data,
0b8e3c4c 1477 ar->hw_params.cal_data_len);
7869b4fa
KV
1478 if (ret) {
1479 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
f67b107d 1480 return ret;
7869b4fa
KV
1481 }
1482
f67b107d
MF
1483 return 0;
1484}
7869b4fa 1485
f67b107d
MF
1486static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1487{
1488 struct ath10k *ar = inode->i_private;
7869b4fa 1489
f67b107d 1490 mutex_lock(&ar->conf_mutex);
7869b4fa 1491
f67b107d
MF
1492 if (ar->state == ATH10K_STATE_ON ||
1493 ar->state == ATH10K_STATE_UTF) {
1494 ath10k_debug_cal_data_fetch(ar);
1495 }
7869b4fa 1496
f67b107d 1497 file->private_data = ar;
7869b4fa
KV
1498 mutex_unlock(&ar->conf_mutex);
1499
f67b107d 1500 return 0;
7869b4fa
KV
1501}
1502
1503static ssize_t ath10k_debug_cal_data_read(struct file *file,
1504 char __user *user_buf,
1505 size_t count, loff_t *ppos)
1506{
0b8e3c4c 1507 struct ath10k *ar = file->private_data;
7869b4fa 1508
f67b107d 1509 mutex_lock(&ar->conf_mutex);
7869b4fa 1510
f67b107d
MF
1511 count = simple_read_from_buffer(user_buf, count, ppos,
1512 ar->debug.cal_data,
1513 ar->hw_params.cal_data_len);
7869b4fa 1514
f67b107d
MF
1515 mutex_unlock(&ar->conf_mutex);
1516
1517 return count;
7869b4fa
KV
1518}
1519
b3e71d7a
ARN
1520static ssize_t ath10k_write_ani_enable(struct file *file,
1521 const char __user *user_buf,
1522 size_t count, loff_t *ppos)
1523{
1524 struct ath10k *ar = file->private_data;
1525 int ret;
1526 u8 enable;
1527
1528 if (kstrtou8_from_user(user_buf, count, 0, &enable))
1529 return -EINVAL;
1530
1531 mutex_lock(&ar->conf_mutex);
1532
1533 if (ar->ani_enabled == enable) {
1534 ret = count;
1535 goto exit;
1536 }
1537
1538 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->ani_enable,
1539 enable);
1540 if (ret) {
1541 ath10k_warn(ar, "ani_enable failed from debugfs: %d\n", ret);
1542 goto exit;
1543 }
1544 ar->ani_enabled = enable;
1545
1546 ret = count;
1547
1548exit:
1549 mutex_unlock(&ar->conf_mutex);
1550
1551 return ret;
1552}
1553
1554static ssize_t ath10k_read_ani_enable(struct file *file, char __user *user_buf,
1555 size_t count, loff_t *ppos)
1556{
1557 struct ath10k *ar = file->private_data;
1558 int len = 0;
1559 char buf[32];
1560
1561 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
1562 ar->ani_enabled);
1563
1564 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1565}
1566
1567static const struct file_operations fops_ani_enable = {
1568 .read = ath10k_read_ani_enable,
1569 .write = ath10k_write_ani_enable,
1570 .open = simple_open,
1571 .owner = THIS_MODULE,
1572 .llseek = default_llseek,
1573};
1574
7869b4fa
KV
1575static const struct file_operations fops_cal_data = {
1576 .open = ath10k_debug_cal_data_open,
1577 .read = ath10k_debug_cal_data_read,
7869b4fa
KV
1578 .owner = THIS_MODULE,
1579 .llseek = default_llseek,
1580};
1581
a7bd3e99
PO
1582static ssize_t ath10k_read_nf_cal_period(struct file *file,
1583 char __user *user_buf,
1584 size_t count, loff_t *ppos)
1585{
1586 struct ath10k *ar = file->private_data;
1587 unsigned int len;
1588 char buf[32];
1589
1590 len = scnprintf(buf, sizeof(buf), "%d\n",
1591 ar->debug.nf_cal_period);
1592
1593 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1594}
1595
1596static ssize_t ath10k_write_nf_cal_period(struct file *file,
1597 const char __user *user_buf,
1598 size_t count, loff_t *ppos)
1599{
1600 struct ath10k *ar = file->private_data;
1601 unsigned long period;
1602 int ret;
1603
1604 ret = kstrtoul_from_user(user_buf, count, 0, &period);
1605 if (ret)
1606 return ret;
1607
1608 if (period > WMI_PDEV_PARAM_CAL_PERIOD_MAX)
1609 return -EINVAL;
1610
1611 /* there's no way to switch back to the firmware default */
1612 if (period == 0)
1613 return -EINVAL;
1614
1615 mutex_lock(&ar->conf_mutex);
1616
1617 ar->debug.nf_cal_period = period;
1618
1619 if (ar->state != ATH10K_STATE_ON) {
1620 /* firmware is not running, nothing else to do */
1621 ret = count;
1622 goto exit;
1623 }
1624
1625 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->cal_period,
1626 ar->debug.nf_cal_period);
1627 if (ret) {
1628 ath10k_warn(ar, "cal period cfg failed from debugfs: %d\n",
1629 ret);
1630 goto exit;
1631 }
1632
1633 ret = count;
1634
1635exit:
1636 mutex_unlock(&ar->conf_mutex);
1637
1638 return ret;
1639}
1640
1641static const struct file_operations fops_nf_cal_period = {
1642 .read = ath10k_read_nf_cal_period,
1643 .write = ath10k_write_nf_cal_period,
1644 .open = simple_open,
1645 .owner = THIS_MODULE,
1646 .llseek = default_llseek,
1647};
1648
29542666
MK
1649#define ATH10K_TPC_CONFIG_BUF_SIZE (1024 * 1024)
1650
1651static int ath10k_debug_tpc_stats_request(struct ath10k *ar)
1652{
1653 int ret;
1654 unsigned long time_left;
1655
1656 lockdep_assert_held(&ar->conf_mutex);
1657
1658 reinit_completion(&ar->debug.tpc_complete);
1659
1660 ret = ath10k_wmi_pdev_get_tpc_config(ar, WMI_TPC_CONFIG_PARAM);
1661 if (ret) {
1662 ath10k_warn(ar, "failed to request tpc config: %d\n", ret);
1663 return ret;
1664 }
1665
1666 time_left = wait_for_completion_timeout(&ar->debug.tpc_complete,
1667 1 * HZ);
1668 if (time_left == 0)
1669 return -ETIMEDOUT;
1670
1671 return 0;
1672}
1673
1674void ath10k_debug_tpc_stats_process(struct ath10k *ar,
1675 struct ath10k_tpc_stats *tpc_stats)
1676{
1677 spin_lock_bh(&ar->data_lock);
1678
1679 kfree(ar->debug.tpc_stats);
1680 ar->debug.tpc_stats = tpc_stats;
1681 complete(&ar->debug.tpc_complete);
1682
1683 spin_unlock_bh(&ar->data_lock);
1684}
1685
1686static void ath10k_tpc_stats_print(struct ath10k_tpc_stats *tpc_stats,
1687 unsigned int j, char *buf, unsigned int *len)
1688{
1689 unsigned int i, buf_len;
1690 static const char table_str[][5] = { "CDD",
1691 "STBC",
1692 "TXBF" };
1693 static const char pream_str[][6] = { "CCK",
1694 "OFDM",
1695 "HT20",
1696 "HT40",
1697 "VHT20",
1698 "VHT40",
1699 "VHT80",
1700 "HTCUP" };
1701
1702 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1703 *len += scnprintf(buf + *len, buf_len - *len,
1704 "********************************\n");
1705 *len += scnprintf(buf + *len, buf_len - *len,
1706 "******************* %s POWER TABLE ****************\n",
1707 table_str[j]);
1708 *len += scnprintf(buf + *len, buf_len - *len,
1709 "********************************\n");
1710 *len += scnprintf(buf + *len, buf_len - *len,
1711 "No. Preamble Rate_code tpc_value1 tpc_value2 tpc_value3\n");
1712
1713 for (i = 0; i < tpc_stats->rate_max; i++) {
1714 *len += scnprintf(buf + *len, buf_len - *len,
1715 "%8d %s 0x%2x %s\n", i,
1716 pream_str[tpc_stats->tpc_table[j].pream_idx[i]],
1717 tpc_stats->tpc_table[j].rate_code[i],
1718 tpc_stats->tpc_table[j].tpc_value[i]);
1719 }
1720
1721 *len += scnprintf(buf + *len, buf_len - *len,
1722 "***********************************\n");
1723}
1724
1725static void ath10k_tpc_stats_fill(struct ath10k *ar,
1726 struct ath10k_tpc_stats *tpc_stats,
1727 char *buf)
1728{
1729 unsigned int len, j, buf_len;
1730
1731 len = 0;
1732 buf_len = ATH10K_TPC_CONFIG_BUF_SIZE;
1733
1734 spin_lock_bh(&ar->data_lock);
1735
1736 if (!tpc_stats) {
1737 ath10k_warn(ar, "failed to get tpc stats\n");
1738 goto unlock;
1739 }
1740
1741 len += scnprintf(buf + len, buf_len - len, "\n");
1742 len += scnprintf(buf + len, buf_len - len,
1743 "*************************************\n");
1744 len += scnprintf(buf + len, buf_len - len,
1745 "TPC config for channel %4d mode %d\n",
1746 tpc_stats->chan_freq,
1747 tpc_stats->phy_mode);
1748 len += scnprintf(buf + len, buf_len - len,
1749 "*************************************\n");
1750 len += scnprintf(buf + len, buf_len - len,
1751 "CTL = 0x%2x Reg. Domain = %2d\n",
1752 tpc_stats->ctl,
1753 tpc_stats->reg_domain);
1754 len += scnprintf(buf + len, buf_len - len,
1755 "Antenna Gain = %2d Reg. Max Antenna Gain = %2d\n",
1756 tpc_stats->twice_antenna_gain,
1757 tpc_stats->twice_antenna_reduction);
1758 len += scnprintf(buf + len, buf_len - len,
1759 "Power Limit = %2d Reg. Max Power = %2d\n",
1760 tpc_stats->power_limit,
1761 tpc_stats->twice_max_rd_power / 2);
1762 len += scnprintf(buf + len, buf_len - len,
1763 "Num tx chains = %2d Num supported rates = %2d\n",
1764 tpc_stats->num_tx_chain,
1765 tpc_stats->rate_max);
1766
1767 for (j = 0; j < tpc_stats->num_tx_chain ; j++) {
1768 switch (j) {
1769 case WMI_TPC_TABLE_TYPE_CDD:
1770 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1771 len += scnprintf(buf + len, buf_len - len,
1772 "CDD not supported\n");
1773 break;
1774 }
1775
1776 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1777 break;
1778 case WMI_TPC_TABLE_TYPE_STBC:
1779 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1780 len += scnprintf(buf + len, buf_len - len,
1781 "STBC not supported\n");
1782 break;
1783 }
1784
1785 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1786 break;
1787 case WMI_TPC_TABLE_TYPE_TXBF:
1788 if (tpc_stats->flag[j] == ATH10K_TPC_TABLE_TYPE_FLAG) {
1789 len += scnprintf(buf + len, buf_len - len,
1790 "TXBF not supported\n***************************\n");
1791 break;
1792 }
1793
1794 ath10k_tpc_stats_print(tpc_stats, j, buf, &len);
1795 break;
1796 default:
1797 len += scnprintf(buf + len, buf_len - len,
1798 "Invalid Type\n");
1799 break;
1800 }
1801 }
1802
1803unlock:
1804 spin_unlock_bh(&ar->data_lock);
1805
1806 if (len >= buf_len)
1807 buf[len - 1] = 0;
1808 else
1809 buf[len] = 0;
1810}
1811
1812static int ath10k_tpc_stats_open(struct inode *inode, struct file *file)
1813{
1814 struct ath10k *ar = inode->i_private;
1815 void *buf = NULL;
1816 int ret;
1817
1818 mutex_lock(&ar->conf_mutex);
1819
1820 if (ar->state != ATH10K_STATE_ON) {
1821 ret = -ENETDOWN;
1822 goto err_unlock;
1823 }
1824
1825 buf = vmalloc(ATH10K_TPC_CONFIG_BUF_SIZE);
1826 if (!buf) {
1827 ret = -ENOMEM;
1828 goto err_unlock;
1829 }
1830
1831 ret = ath10k_debug_tpc_stats_request(ar);
1832 if (ret) {
1833 ath10k_warn(ar, "failed to request tpc config stats: %d\n",
1834 ret);
1835 goto err_free;
1836 }
1837
1838 ath10k_tpc_stats_fill(ar, ar->debug.tpc_stats, buf);
1839 file->private_data = buf;
1840
1841 mutex_unlock(&ar->conf_mutex);
1842 return 0;
1843
1844err_free:
1845 vfree(buf);
1846
1847err_unlock:
1848 mutex_unlock(&ar->conf_mutex);
1849 return ret;
1850}
1851
1852static int ath10k_tpc_stats_release(struct inode *inode, struct file *file)
1853{
1854 vfree(file->private_data);
1855
1856 return 0;
1857}
1858
1859static ssize_t ath10k_tpc_stats_read(struct file *file, char __user *user_buf,
1860 size_t count, loff_t *ppos)
1861{
1862 const char *buf = file->private_data;
1863 unsigned int len = strlen(buf);
1864
1865 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1866}
1867
1868static const struct file_operations fops_tpc_stats = {
1869 .open = ath10k_tpc_stats_open,
1870 .release = ath10k_tpc_stats_release,
1871 .read = ath10k_tpc_stats_read,
1872 .owner = THIS_MODULE,
1873 .llseek = default_llseek,
1874};
1875
db66ea04
KV
1876int ath10k_debug_start(struct ath10k *ar)
1877{
a3d135e5
KV
1878 int ret;
1879
60631c5c
KV
1880 lockdep_assert_held(&ar->conf_mutex);
1881
a3d135e5
KV
1882 ret = ath10k_debug_htt_stats_req(ar);
1883 if (ret)
1884 /* continue normally anyway, this isn't serious */
7aa7a72a
MK
1885 ath10k_warn(ar, "failed to start htt stats workqueue: %d\n",
1886 ret);
a3d135e5 1887
f118a3e5 1888 if (ar->debug.fw_dbglog_mask) {
467210a6
SJ
1889 ret = ath10k_wmi_dbglog_cfg(ar, ar->debug.fw_dbglog_mask,
1890 ATH10K_DBGLOG_LEVEL_WARN);
f118a3e5
KV
1891 if (ret)
1892 /* not serious */
7aa7a72a 1893 ath10k_warn(ar, "failed to enable dbglog during start: %d",
f118a3e5
KV
1894 ret);
1895 }
1896
90174455
RM
1897 if (ar->debug.pktlog_filter) {
1898 ret = ath10k_wmi_pdev_pktlog_enable(ar,
1899 ar->debug.pktlog_filter);
1900 if (ret)
1901 /* not serious */
1902 ath10k_warn(ar,
1903 "failed to enable pktlog filter %x: %d\n",
1904 ar->debug.pktlog_filter, ret);
1905 } else {
1906 ret = ath10k_wmi_pdev_pktlog_disable(ar);
1907 if (ret)
1908 /* not serious */
1909 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
1910 }
1911
a7bd3e99
PO
1912 if (ar->debug.nf_cal_period) {
1913 ret = ath10k_wmi_pdev_set_param(ar,
1914 ar->wmi.pdev_param->cal_period,
1915 ar->debug.nf_cal_period);
1916 if (ret)
1917 /* not serious */
1918 ath10k_warn(ar, "cal period cfg failed from debug start: %d\n",
1919 ret);
1920 }
1921
90174455 1922 return ret;
db66ea04
KV
1923}
1924
1925void ath10k_debug_stop(struct ath10k *ar)
1926{
60631c5c
KV
1927 lockdep_assert_held(&ar->conf_mutex);
1928
f67b107d
MF
1929 ath10k_debug_cal_data_fetch(ar);
1930
60631c5c
KV
1931 /* Must not use _sync to avoid deadlock, we do that in
1932 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1933 * warning from del_timer(). */
1934 if (ar->debug.htt_stats_mask != 0)
1935 cancel_delayed_work(&ar->debug.htt_stats_dwork);
d385623a 1936
90174455 1937 ath10k_wmi_pdev_pktlog_disable(ar);
db66ea04
KV
1938}
1939
9702c686
JD
1940static ssize_t ath10k_write_simulate_radar(struct file *file,
1941 const char __user *user_buf,
1942 size_t count, loff_t *ppos)
1943{
1944 struct ath10k *ar = file->private_data;
1945
1946 ieee80211_radar_detected(ar->hw);
1947
1948 return count;
1949}
1950
1951static const struct file_operations fops_simulate_radar = {
1952 .write = ath10k_write_simulate_radar,
1953 .open = simple_open,
1954 .owner = THIS_MODULE,
1955 .llseek = default_llseek,
1956};
1957
1958#define ATH10K_DFS_STAT(s, p) (\
1959 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1960 ar->debug.dfs_stats.p))
1961
1962#define ATH10K_DFS_POOL_STAT(s, p) (\
1963 len += scnprintf(buf + len, size - len, "%-28s : %10u\n", s, \
1964 ar->debug.dfs_pool_stats.p))
1965
1966static ssize_t ath10k_read_dfs_stats(struct file *file, char __user *user_buf,
1967 size_t count, loff_t *ppos)
1968{
1969 int retval = 0, len = 0;
1970 const int size = 8000;
1971 struct ath10k *ar = file->private_data;
1972 char *buf;
1973
1974 buf = kzalloc(size, GFP_KERNEL);
1975 if (buf == NULL)
1976 return -ENOMEM;
1977
1978 if (!ar->dfs_detector) {
1979 len += scnprintf(buf + len, size - len, "DFS not enabled\n");
1980 goto exit;
1981 }
1982
1983 ar->debug.dfs_pool_stats =
1984 ar->dfs_detector->get_stats(ar->dfs_detector);
1985
1986 len += scnprintf(buf + len, size - len, "Pulse detector statistics:\n");
1987
1988 ATH10K_DFS_STAT("reported phy errors", phy_errors);
1989 ATH10K_DFS_STAT("pulse events reported", pulses_total);
1990 ATH10K_DFS_STAT("DFS pulses detected", pulses_detected);
1991 ATH10K_DFS_STAT("DFS pulses discarded", pulses_discarded);
1992 ATH10K_DFS_STAT("Radars detected", radar_detected);
1993
1994 len += scnprintf(buf + len, size - len, "Global Pool statistics:\n");
1995 ATH10K_DFS_POOL_STAT("Pool references", pool_reference);
1996 ATH10K_DFS_POOL_STAT("Pulses allocated", pulse_allocated);
1997 ATH10K_DFS_POOL_STAT("Pulses alloc error", pulse_alloc_error);
1998 ATH10K_DFS_POOL_STAT("Pulses in use", pulse_used);
1999 ATH10K_DFS_POOL_STAT("Seqs. allocated", pseq_allocated);
2000 ATH10K_DFS_POOL_STAT("Seqs. alloc error", pseq_alloc_error);
2001 ATH10K_DFS_POOL_STAT("Seqs. in use", pseq_used);
2002
2003exit:
2004 if (len > size)
2005 len = size;
2006
2007 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2008 kfree(buf);
2009
2010 return retval;
2011}
2012
2013static const struct file_operations fops_dfs_stats = {
2014 .read = ath10k_read_dfs_stats,
2015 .open = simple_open,
2016 .owner = THIS_MODULE,
2017 .llseek = default_llseek,
2018};
2019
90174455
RM
2020static ssize_t ath10k_write_pktlog_filter(struct file *file,
2021 const char __user *ubuf,
2022 size_t count, loff_t *ppos)
2023{
2024 struct ath10k *ar = file->private_data;
2025 u32 filter;
2026 int ret;
2027
2028 if (kstrtouint_from_user(ubuf, count, 0, &filter))
2029 return -EINVAL;
2030
2031 mutex_lock(&ar->conf_mutex);
2032
2033 if (ar->state != ATH10K_STATE_ON) {
2034 ar->debug.pktlog_filter = filter;
2035 ret = count;
2036 goto out;
2037 }
2038
9ddc486a
AK
2039 if (filter == ar->debug.pktlog_filter) {
2040 ret = count;
2041 goto out;
2042 }
2043
2044 if (filter) {
90174455
RM
2045 ret = ath10k_wmi_pdev_pktlog_enable(ar, filter);
2046 if (ret) {
2047 ath10k_warn(ar, "failed to enable pktlog filter %x: %d\n",
2048 ar->debug.pktlog_filter, ret);
2049 goto out;
2050 }
2051 } else {
2052 ret = ath10k_wmi_pdev_pktlog_disable(ar);
2053 if (ret) {
2054 ath10k_warn(ar, "failed to disable pktlog: %d\n", ret);
2055 goto out;
2056 }
2057 }
2058
2059 ar->debug.pktlog_filter = filter;
2060 ret = count;
2061
2062out:
2063 mutex_unlock(&ar->conf_mutex);
2064 return ret;
2065}
2066
2067static ssize_t ath10k_read_pktlog_filter(struct file *file, char __user *ubuf,
2068 size_t count, loff_t *ppos)
2069{
2070 char buf[32];
2071 struct ath10k *ar = file->private_data;
2072 int len = 0;
2073
2074 mutex_lock(&ar->conf_mutex);
2075 len = scnprintf(buf, sizeof(buf) - len, "%08x\n",
2076 ar->debug.pktlog_filter);
2077 mutex_unlock(&ar->conf_mutex);
2078
2079 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2080}
2081
2082static const struct file_operations fops_pktlog_filter = {
2083 .read = ath10k_read_pktlog_filter,
2084 .write = ath10k_write_pktlog_filter,
2085 .open = simple_open
2086};
2087
63fb32df
RM
2088static ssize_t ath10k_write_quiet_period(struct file *file,
2089 const char __user *ubuf,
2090 size_t count, loff_t *ppos)
2091{
2092 struct ath10k *ar = file->private_data;
2093 u32 period;
2094
2095 if (kstrtouint_from_user(ubuf, count, 0, &period))
2096 return -EINVAL;
2097
2098 if (period < ATH10K_QUIET_PERIOD_MIN) {
2099 ath10k_warn(ar, "Quiet period %u can not be lesser than 25ms\n",
2100 period);
2101 return -EINVAL;
2102 }
2103 mutex_lock(&ar->conf_mutex);
2104 ar->thermal.quiet_period = period;
8515b5c7 2105 ath10k_thermal_set_throttling(ar);
63fb32df
RM
2106 mutex_unlock(&ar->conf_mutex);
2107
2108 return count;
2109}
2110
2111static ssize_t ath10k_read_quiet_period(struct file *file, char __user *ubuf,
2112 size_t count, loff_t *ppos)
2113{
2114 char buf[32];
2115 struct ath10k *ar = file->private_data;
2116 int len = 0;
2117
2118 mutex_lock(&ar->conf_mutex);
2119 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2120 ar->thermal.quiet_period);
2121 mutex_unlock(&ar->conf_mutex);
2122
2123 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2124}
2125
2126static const struct file_operations fops_quiet_period = {
2127 .read = ath10k_read_quiet_period,
2128 .write = ath10k_write_quiet_period,
2129 .open = simple_open
2130};
2131
844fa572
YL
2132static ssize_t ath10k_write_btcoex(struct file *file,
2133 const char __user *ubuf,
2134 size_t count, loff_t *ppos)
2135{
2136 struct ath10k *ar = file->private_data;
2137 char buf[32];
2138 size_t buf_size;
87be054a 2139 int ret;
844fa572 2140 bool val;
39136248 2141 u32 pdev_param;
844fa572
YL
2142
2143 buf_size = min(count, (sizeof(buf) - 1));
2144 if (copy_from_user(buf, ubuf, buf_size))
2145 return -EFAULT;
2146
2147 buf[buf_size] = '\0';
2148
2149 if (strtobool(buf, &val) != 0)
2150 return -EINVAL;
2151
2152 mutex_lock(&ar->conf_mutex);
2153
c28e6f06
MSS
2154 if (ar->state != ATH10K_STATE_ON &&
2155 ar->state != ATH10K_STATE_RESTARTED) {
2156 ret = -ENETDOWN;
2157 goto exit;
2158 }
2159
87be054a
MSS
2160 if (!(test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags) ^ val)) {
2161 ret = count;
844fa572 2162 goto exit;
87be054a 2163 }
844fa572 2164
39136248
RM
2165 pdev_param = ar->wmi.pdev_param->enable_btcoex;
2166 if (test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
2167 ar->running_fw->fw_file.fw_features)) {
2168 ret = ath10k_wmi_pdev_set_param(ar, pdev_param, val);
2169 if (ret) {
2170 ath10k_warn(ar, "failed to enable btcoex: %d\n", ret);
2171 ret = count;
2172 goto exit;
2173 }
2174 } else {
2175 ath10k_info(ar, "restarting firmware due to btcoex change");
2176 queue_work(ar->workqueue, &ar->restart_work);
2177 }
2178
844fa572
YL
2179 if (val)
2180 set_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2181 else
2182 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
2183
c28e6f06 2184 ret = count;
844fa572
YL
2185
2186exit:
2187 mutex_unlock(&ar->conf_mutex);
2188
c28e6f06 2189 return ret;
844fa572
YL
2190}
2191
2192static ssize_t ath10k_read_btcoex(struct file *file, char __user *ubuf,
2193 size_t count, loff_t *ppos)
2194{
2195 char buf[32];
2196 struct ath10k *ar = file->private_data;
2197 int len = 0;
2198
2199 mutex_lock(&ar->conf_mutex);
2200 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2201 test_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags));
2202 mutex_unlock(&ar->conf_mutex);
2203
2204 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2205}
2206
2207static const struct file_operations fops_btcoex = {
2208 .read = ath10k_read_btcoex,
2209 .write = ath10k_write_btcoex,
2210 .open = simple_open
2211};
2212
cc61a1bb
MSS
2213static ssize_t ath10k_write_peer_stats(struct file *file,
2214 const char __user *ubuf,
2215 size_t count, loff_t *ppos)
2216{
2217 struct ath10k *ar = file->private_data;
2218 char buf[32];
2219 size_t buf_size;
87be054a 2220 int ret;
cc61a1bb
MSS
2221 bool val;
2222
2223 buf_size = min(count, (sizeof(buf) - 1));
2224 if (copy_from_user(buf, ubuf, buf_size))
2225 return -EFAULT;
2226
2227 buf[buf_size] = '\0';
2228
2229 if (strtobool(buf, &val) != 0)
2230 return -EINVAL;
2231
2232 mutex_lock(&ar->conf_mutex);
2233
2234 if (ar->state != ATH10K_STATE_ON &&
2235 ar->state != ATH10K_STATE_RESTARTED) {
2236 ret = -ENETDOWN;
2237 goto exit;
2238 }
2239
87be054a
MSS
2240 if (!(test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags) ^ val)) {
2241 ret = count;
cc61a1bb 2242 goto exit;
87be054a 2243 }
cc61a1bb
MSS
2244
2245 if (val)
2246 set_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2247 else
2248 clear_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags);
2249
2250 ath10k_info(ar, "restarting firmware due to Peer stats change");
2251
2252 queue_work(ar->workqueue, &ar->restart_work);
2253 ret = count;
2254
2255exit:
2256 mutex_unlock(&ar->conf_mutex);
2257 return ret;
2258}
2259
2260static ssize_t ath10k_read_peer_stats(struct file *file, char __user *ubuf,
2261 size_t count, loff_t *ppos)
2262
2263{
2264 char buf[32];
2265 struct ath10k *ar = file->private_data;
2266 int len = 0;
2267
2268 mutex_lock(&ar->conf_mutex);
2269 len = scnprintf(buf, sizeof(buf) - len, "%d\n",
2270 test_bit(ATH10K_FLAG_PEER_STATS, &ar->dev_flags));
2271 mutex_unlock(&ar->conf_mutex);
2272
2273 return simple_read_from_buffer(ubuf, count, ppos, buf, len);
2274}
2275
2276static const struct file_operations fops_peer_stats = {
2277 .read = ath10k_read_peer_stats,
2278 .write = ath10k_write_peer_stats,
2279 .open = simple_open
2280};
2281
9e100c4d
KV
2282static ssize_t ath10k_debug_fw_checksums_read(struct file *file,
2283 char __user *user_buf,
2284 size_t count, loff_t *ppos)
2285{
2286 struct ath10k *ar = file->private_data;
2287 unsigned int len = 0, buf_len = 4096;
2288 ssize_t ret_cnt;
2289 char *buf;
2290
2291 buf = kzalloc(buf_len, GFP_KERNEL);
2292 if (!buf)
2293 return -ENOMEM;
2294
2295 mutex_lock(&ar->conf_mutex);
2296
9e100c4d
KV
2297 len += scnprintf(buf + len, buf_len - len,
2298 "firmware-N.bin\t\t%08x\n",
7ebf721d
KV
2299 crc32_le(0, ar->normal_mode_fw.fw_file.firmware->data,
2300 ar->normal_mode_fw.fw_file.firmware->size));
9e100c4d
KV
2301 len += scnprintf(buf + len, buf_len - len,
2302 "athwlan\t\t\t%08x\n",
7ebf721d
KV
2303 crc32_le(0, ar->normal_mode_fw.fw_file.firmware_data,
2304 ar->normal_mode_fw.fw_file.firmware_len));
9e100c4d
KV
2305 len += scnprintf(buf + len, buf_len - len,
2306 "otp\t\t\t%08x\n",
7ebf721d
KV
2307 crc32_le(0, ar->normal_mode_fw.fw_file.otp_data,
2308 ar->normal_mode_fw.fw_file.otp_len));
9e100c4d
KV
2309 len += scnprintf(buf + len, buf_len - len,
2310 "codeswap\t\t%08x\n",
7ebf721d
KV
2311 crc32_le(0, ar->normal_mode_fw.fw_file.codeswap_data,
2312 ar->normal_mode_fw.fw_file.codeswap_len));
9e100c4d
KV
2313 len += scnprintf(buf + len, buf_len - len,
2314 "board-N.bin\t\t%08x\n",
7ebf721d
KV
2315 crc32_le(0, ar->normal_mode_fw.board->data,
2316 ar->normal_mode_fw.board->size));
9e100c4d
KV
2317 len += scnprintf(buf + len, buf_len - len,
2318 "board\t\t\t%08x\n",
7ebf721d
KV
2319 crc32_le(0, ar->normal_mode_fw.board_data,
2320 ar->normal_mode_fw.board_len));
9e100c4d
KV
2321
2322 ret_cnt = simple_read_from_buffer(user_buf, count, ppos, buf, len);
2323
2324 mutex_unlock(&ar->conf_mutex);
2325
2326 kfree(buf);
2327 return ret_cnt;
2328}
2329
2330static const struct file_operations fops_fw_checksums = {
2331 .read = ath10k_debug_fw_checksums_read,
2332 .open = simple_open,
2333 .owner = THIS_MODULE,
2334 .llseek = default_llseek,
2335};
2336
5e3dd157
KV
2337int ath10k_debug_create(struct ath10k *ar)
2338{
384914b2 2339 ar->debug.fw_crash_data = vzalloc(sizeof(*ar->debug.fw_crash_data));
e13cf7a3
MK
2340 if (!ar->debug.fw_crash_data)
2341 return -ENOMEM;
384914b2 2342
f67b107d
MF
2343 ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN);
2344 if (!ar->debug.cal_data)
2345 return -ENOMEM;
2346
5326849a 2347 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
7b6b153a 2348 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
5326849a 2349 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
4a49ae94 2350 INIT_LIST_HEAD(&ar->debug.fw_stats.peers_extd);
5326849a 2351
e13cf7a3
MK
2352 return 0;
2353}
2354
2355void ath10k_debug_destroy(struct ath10k *ar)
2356{
2357 vfree(ar->debug.fw_crash_data);
2358 ar->debug.fw_crash_data = NULL;
5326849a 2359
f67b107d
MF
2360 vfree(ar->debug.cal_data);
2361 ar->debug.cal_data = NULL;
2362
5326849a 2363 ath10k_debug_fw_stats_reset(ar);
29542666
MK
2364
2365 kfree(ar->debug.tpc_stats);
e13cf7a3
MK
2366}
2367
2368int ath10k_debug_register(struct ath10k *ar)
2369{
5e3dd157
KV
2370 ar->debug.debugfs_phy = debugfs_create_dir("ath10k",
2371 ar->hw->wiphy->debugfsdir);
adb43b24
MK
2372 if (IS_ERR_OR_NULL(ar->debug.debugfs_phy)) {
2373 if (IS_ERR(ar->debug.debugfs_phy))
2374 return PTR_ERR(ar->debug.debugfs_phy);
d8bb26b9
KV
2375
2376 return -ENOMEM;
adb43b24 2377 }
5e3dd157 2378
a3d135e5
KV
2379 INIT_DELAYED_WORK(&ar->debug.htt_stats_dwork,
2380 ath10k_debug_htt_stats_dwork);
2381
29542666 2382 init_completion(&ar->debug.tpc_complete);
60ef401a 2383 init_completion(&ar->debug.fw_stats_complete);
5e3dd157
KV
2384
2385 debugfs_create_file("fw_stats", S_IRUSR, ar->debug.debugfs_phy, ar,
2386 &fops_fw_stats);
2387
f51dbe73
BG
2388 debugfs_create_file("fw_reset_stats", S_IRUSR, ar->debug.debugfs_phy,
2389 ar, &fops_fw_reset_stats);
2390
5e3dd157
KV
2391 debugfs_create_file("wmi_services", S_IRUSR, ar->debug.debugfs_phy, ar,
2392 &fops_wmi_services);
2393
8bf1ba1c
MSS
2394 debugfs_create_file("simulate_fw_crash", S_IRUSR | S_IWUSR,
2395 ar->debug.debugfs_phy, ar, &fops_simulate_fw_crash);
278c4a85 2396
384914b2
BG
2397 debugfs_create_file("fw_crash_dump", S_IRUSR, ar->debug.debugfs_phy,
2398 ar, &fops_fw_crash_dump);
2399
077a3804
YL
2400 debugfs_create_file("reg_addr", S_IRUSR | S_IWUSR,
2401 ar->debug.debugfs_phy, ar, &fops_reg_addr);
2402
2403 debugfs_create_file("reg_value", S_IRUSR | S_IWUSR,
2404 ar->debug.debugfs_phy, ar, &fops_reg_value);
2405
9f65ad25
YL
2406 debugfs_create_file("mem_value", S_IRUSR | S_IWUSR,
2407 ar->debug.debugfs_phy, ar, &fops_mem_value);
2408
763b8cd3
KV
2409 debugfs_create_file("chip_id", S_IRUSR, ar->debug.debugfs_phy,
2410 ar, &fops_chip_id);
2411
8bf1ba1c
MSS
2412 debugfs_create_file("htt_stats_mask", S_IRUSR | S_IWUSR,
2413 ar->debug.debugfs_phy, ar, &fops_htt_stats_mask);
a3d135e5 2414
d385623a
JD
2415 debugfs_create_file("htt_max_amsdu_ampdu", S_IRUSR | S_IWUSR,
2416 ar->debug.debugfs_phy, ar,
2417 &fops_htt_max_amsdu_ampdu);
2418
8bf1ba1c
MSS
2419 debugfs_create_file("fw_dbglog", S_IRUSR | S_IWUSR,
2420 ar->debug.debugfs_phy, ar, &fops_fw_dbglog);
f118a3e5 2421
7869b4fa
KV
2422 debugfs_create_file("cal_data", S_IRUSR, ar->debug.debugfs_phy,
2423 ar, &fops_cal_data);
2424
b3e71d7a
ARN
2425 debugfs_create_file("ani_enable", S_IRUSR | S_IWUSR,
2426 ar->debug.debugfs_phy, ar, &fops_ani_enable);
2427
a7bd3e99
PO
2428 debugfs_create_file("nf_cal_period", S_IRUSR | S_IWUSR,
2429 ar->debug.debugfs_phy, ar, &fops_nf_cal_period);
2430
97f2645f 2431 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
9702c686
JD
2432 debugfs_create_file("dfs_simulate_radar", S_IWUSR,
2433 ar->debug.debugfs_phy, ar,
2434 &fops_simulate_radar);
2435
7d9b40b4
MP
2436 debugfs_create_bool("dfs_block_radar_events", S_IWUSR,
2437 ar->debug.debugfs_phy,
2438 &ar->dfs_block_radar_events);
2439
9702c686
JD
2440 debugfs_create_file("dfs_stats", S_IRUSR,
2441 ar->debug.debugfs_phy, ar,
2442 &fops_dfs_stats);
2443 }
2444
90174455
RM
2445 debugfs_create_file("pktlog_filter", S_IRUGO | S_IWUSR,
2446 ar->debug.debugfs_phy, ar, &fops_pktlog_filter);
2447
63fb32df
RM
2448 debugfs_create_file("quiet_period", S_IRUGO | S_IWUSR,
2449 ar->debug.debugfs_phy, ar, &fops_quiet_period);
2450
29542666
MK
2451 debugfs_create_file("tpc_stats", S_IRUSR,
2452 ar->debug.debugfs_phy, ar, &fops_tpc_stats);
2453
844fa572
YL
2454 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map))
2455 debugfs_create_file("btcoex", S_IRUGO | S_IWUSR,
2456 ar->debug.debugfs_phy, ar, &fops_btcoex);
2457
cc61a1bb
MSS
2458 if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map))
2459 debugfs_create_file("peer_stats", S_IRUGO | S_IWUSR,
2460 ar->debug.debugfs_phy, ar,
2461 &fops_peer_stats);
2462
9e100c4d
KV
2463 debugfs_create_file("fw_checksums", S_IRUSR,
2464 ar->debug.debugfs_phy, ar, &fops_fw_checksums);
2465
5e3dd157
KV
2466 return 0;
2467}
db66ea04 2468
e13cf7a3 2469void ath10k_debug_unregister(struct ath10k *ar)
60631c5c
KV
2470{
2471 cancel_delayed_work_sync(&ar->debug.htt_stats_dwork);
2472}
2473
5e3dd157
KV
2474#endif /* CONFIG_ATH10K_DEBUGFS */
2475
2476#ifdef CONFIG_ATH10K_DEBUG
7aa7a72a
MK
2477void ath10k_dbg(struct ath10k *ar, enum ath10k_debug_mask mask,
2478 const char *fmt, ...)
5e3dd157
KV
2479{
2480 struct va_format vaf;
2481 va_list args;
2482
2483 va_start(args, fmt);
2484
2485 vaf.fmt = fmt;
2486 vaf.va = &args;
2487
2488 if (ath10k_debug_mask & mask)
7aa7a72a 2489 dev_printk(KERN_DEBUG, ar->dev, "%pV", &vaf);
5e3dd157 2490
d35a6c18 2491 trace_ath10k_log_dbg(ar, mask, &vaf);
5e3dd157
KV
2492
2493 va_end(args);
2494}
2495EXPORT_SYMBOL(ath10k_dbg);
2496
7aa7a72a
MK
2497void ath10k_dbg_dump(struct ath10k *ar,
2498 enum ath10k_debug_mask mask,
5e3dd157
KV
2499 const char *msg, const char *prefix,
2500 const void *buf, size_t len)
2501{
45724a8a
MK
2502 char linebuf[256];
2503 unsigned int linebuflen;
2504 const void *ptr;
2505
5e3dd157
KV
2506 if (ath10k_debug_mask & mask) {
2507 if (msg)
7aa7a72a 2508 ath10k_dbg(ar, mask, "%s\n", msg);
5e3dd157 2509
45724a8a
MK
2510 for (ptr = buf; (ptr - buf) < len; ptr += 16) {
2511 linebuflen = 0;
2512 linebuflen += scnprintf(linebuf + linebuflen,
2513 sizeof(linebuf) - linebuflen,
2514 "%s%08x: ",
2515 (prefix ? prefix : ""),
2516 (unsigned int)(ptr - buf));
2517 hex_dump_to_buffer(ptr, len - (ptr - buf), 16, 1,
2518 linebuf + linebuflen,
2519 sizeof(linebuf) - linebuflen, true);
2520 dev_printk(KERN_DEBUG, ar->dev, "%s\n", linebuf);
2521 }
5e3dd157
KV
2522 }
2523
2524 /* tracing code doesn't like null strings :/ */
d35a6c18 2525 trace_ath10k_log_dbg_dump(ar, msg ? msg : "", prefix ? prefix : "",
5e3dd157
KV
2526 buf, len);
2527}
2528EXPORT_SYMBOL(ath10k_dbg_dump);
2529
2530#endif /* CONFIG_ATH10K_DEBUG */