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