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