1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2012-2014, 2018-2023 Intel Corporation 4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 5 * Copyright (C) 2016-2017 Intel Deutschland GmbH 6 */ 7 #include <linux/vmalloc.h> 8 #include <linux/err.h> 9 #include <linux/ieee80211.h> 10 #include <linux/netdevice.h> 11 #include <linux/dmi.h> 12 13 #include "mvm.h" 14 #include "sta.h" 15 #include "iwl-io.h" 16 #include "debugfs.h" 17 #include "iwl-modparams.h" 18 #include "iwl-drv.h" 19 #include "fw/error-dump.h" 20 #include "fw/api/phy-ctxt.h" 21 22 static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file, 23 char __user *user_buf, 24 size_t count, loff_t *ppos) 25 { 26 struct iwl_mvm *mvm = file->private_data; 27 char buf[16]; 28 int pos, budget; 29 30 if (!iwl_mvm_is_ctdp_supported(mvm)) 31 return -EOPNOTSUPP; 32 33 if (!iwl_mvm_firmware_running(mvm) || 34 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 35 return -EIO; 36 37 mutex_lock(&mvm->mutex); 38 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0); 39 mutex_unlock(&mvm->mutex); 40 41 if (budget < 0) 42 return budget; 43 44 pos = scnprintf(buf, sizeof(buf), "%d\n", budget); 45 46 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 47 } 48 49 static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf, 50 size_t count, loff_t *ppos) 51 { 52 int ret; 53 bool force; 54 55 if (!kstrtobool(buf, &force)) 56 IWL_DEBUG_INFO(mvm, 57 "force start is %d [0=disabled, 1=enabled]\n", 58 force); 59 60 /* we allow skipping cap support check and force stop ctdp 61 * statistics collection and with guerantee that it is 62 * safe to use. 63 */ 64 if (!force && !iwl_mvm_is_ctdp_supported(mvm)) 65 return -EOPNOTSUPP; 66 67 if (!iwl_mvm_firmware_running(mvm) || 68 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 69 return -EIO; 70 71 mutex_lock(&mvm->mutex); 72 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0); 73 mutex_unlock(&mvm->mutex); 74 75 return ret ?: count; 76 } 77 78 static ssize_t iwl_dbgfs_start_ctdp_write(struct iwl_mvm *mvm, 79 char *buf, size_t count, 80 loff_t *ppos) 81 { 82 int ret; 83 bool force; 84 85 if (!kstrtobool(buf, &force)) 86 IWL_DEBUG_INFO(mvm, 87 "force start is %d [0=disabled, 1=enabled]\n", 88 force); 89 90 /* we allow skipping cap support check and force enable ctdp 91 * for statistics collection and with guerantee that it is 92 * safe to use. 93 */ 94 if (!force && !iwl_mvm_is_ctdp_supported(mvm)) 95 return -EOPNOTSUPP; 96 97 if (!iwl_mvm_firmware_running(mvm) || 98 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 99 return -EIO; 100 101 mutex_lock(&mvm->mutex); 102 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START, 0); 103 mutex_unlock(&mvm->mutex); 104 105 return ret ?: count; 106 } 107 108 static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf, 109 size_t count, loff_t *ppos) 110 { 111 if (!iwl_mvm_firmware_running(mvm) || 112 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 113 return -EIO; 114 115 iwl_mvm_enter_ctkill(mvm); 116 117 return count; 118 } 119 120 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf, 121 size_t count, loff_t *ppos) 122 { 123 int ret; 124 u32 flush_arg; 125 126 if (!iwl_mvm_firmware_running(mvm) || 127 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 128 return -EIO; 129 130 if (kstrtou32(buf, 0, &flush_arg)) 131 return -EINVAL; 132 133 if (iwl_mvm_has_new_tx_api(mvm)) { 134 IWL_DEBUG_TX_QUEUES(mvm, 135 "FLUSHING all tids queues on sta_id = %d\n", 136 flush_arg); 137 mutex_lock(&mvm->mutex); 138 ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFFFF) 139 ? : count; 140 mutex_unlock(&mvm->mutex); 141 return ret; 142 } 143 144 IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n", 145 flush_arg); 146 147 mutex_lock(&mvm->mutex); 148 ret = iwl_mvm_flush_tx_path(mvm, flush_arg) ? : count; 149 mutex_unlock(&mvm->mutex); 150 151 return ret; 152 } 153 154 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf, 155 size_t count, loff_t *ppos) 156 { 157 struct iwl_mvm_sta *mvmsta; 158 int sta_id, drain, ret; 159 160 if (!iwl_mvm_firmware_running(mvm) || 161 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR) 162 return -EIO; 163 164 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2) 165 return -EINVAL; 166 if (sta_id < 0 || sta_id >= mvm->fw->ucode_capa.num_stations) 167 return -EINVAL; 168 if (drain < 0 || drain > 1) 169 return -EINVAL; 170 171 mutex_lock(&mvm->mutex); 172 173 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); 174 175 if (!mvmsta) 176 ret = -ENOENT; 177 else 178 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count; 179 180 mutex_unlock(&mvm->mutex); 181 182 return ret; 183 } 184 185 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, 186 size_t count, loff_t *ppos) 187 { 188 struct iwl_mvm *mvm = file->private_data; 189 const struct fw_img *img; 190 unsigned int ofs, len; 191 size_t ret; 192 u8 *ptr; 193 194 if (!iwl_mvm_firmware_running(mvm)) 195 return -EINVAL; 196 197 /* default is to dump the entire data segment */ 198 img = &mvm->fw->img[mvm->fwrt.cur_fw_img]; 199 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; 200 len = img->sec[IWL_UCODE_SECTION_DATA].len; 201 202 if (mvm->dbgfs_sram_len) { 203 ofs = mvm->dbgfs_sram_offset; 204 len = mvm->dbgfs_sram_len; 205 } 206 207 ptr = kzalloc(len, GFP_KERNEL); 208 if (!ptr) 209 return -ENOMEM; 210 211 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); 212 213 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len); 214 215 kfree(ptr); 216 217 return ret; 218 } 219 220 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf, 221 size_t count, loff_t *ppos) 222 { 223 const struct fw_img *img; 224 u32 offset, len; 225 u32 img_offset, img_len; 226 227 if (!iwl_mvm_firmware_running(mvm)) 228 return -EINVAL; 229 230 img = &mvm->fw->img[mvm->fwrt.cur_fw_img]; 231 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset; 232 img_len = img->sec[IWL_UCODE_SECTION_DATA].len; 233 234 if (sscanf(buf, "%x,%x", &offset, &len) == 2) { 235 if ((offset & 0x3) || (len & 0x3)) 236 return -EINVAL; 237 238 if (offset + len > img_offset + img_len) 239 return -EINVAL; 240 241 mvm->dbgfs_sram_offset = offset; 242 mvm->dbgfs_sram_len = len; 243 } else { 244 mvm->dbgfs_sram_offset = 0; 245 mvm->dbgfs_sram_len = 0; 246 } 247 248 return count; 249 } 250 251 static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file, 252 char __user *user_buf, 253 size_t count, loff_t *ppos) 254 { 255 struct iwl_mvm *mvm = file->private_data; 256 char buf[16]; 257 int pos; 258 259 if (!mvm->temperature_test) 260 pos = scnprintf(buf, sizeof(buf), "disabled\n"); 261 else 262 pos = scnprintf(buf, sizeof(buf), "%d\n", mvm->temperature); 263 264 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 265 } 266 267 /* 268 * Set NIC Temperature 269 * Cause the driver to ignore the actual NIC temperature reported by the FW 270 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN - 271 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX 272 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE 273 */ 274 static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm, 275 char *buf, size_t count, 276 loff_t *ppos) 277 { 278 int temperature; 279 280 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test) 281 return -EIO; 282 283 if (kstrtoint(buf, 10, &temperature)) 284 return -EINVAL; 285 /* not a legal temperature */ 286 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX && 287 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) || 288 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN) 289 return -EINVAL; 290 291 mutex_lock(&mvm->mutex); 292 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) { 293 if (!mvm->temperature_test) 294 goto out; 295 296 mvm->temperature_test = false; 297 /* Since we can't read the temp while awake, just set 298 * it to zero until we get the next RX stats from the 299 * firmware. 300 */ 301 mvm->temperature = 0; 302 } else { 303 mvm->temperature_test = true; 304 mvm->temperature = temperature; 305 } 306 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n", 307 mvm->temperature_test ? "En" : "Dis", 308 mvm->temperature); 309 /* handle the temperature change */ 310 iwl_mvm_tt_handler(mvm); 311 312 out: 313 mutex_unlock(&mvm->mutex); 314 315 return count; 316 } 317 318 static ssize_t iwl_dbgfs_nic_temp_read(struct file *file, 319 char __user *user_buf, 320 size_t count, loff_t *ppos) 321 { 322 struct iwl_mvm *mvm = file->private_data; 323 char buf[16]; 324 int pos, ret; 325 s32 temp; 326 327 if (!iwl_mvm_firmware_running(mvm)) 328 return -EIO; 329 330 mutex_lock(&mvm->mutex); 331 ret = iwl_mvm_get_temp(mvm, &temp); 332 mutex_unlock(&mvm->mutex); 333 334 if (ret) 335 return -EIO; 336 337 pos = scnprintf(buf, sizeof(buf), "%d\n", temp); 338 339 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 340 } 341 342 #ifdef CONFIG_ACPI 343 static ssize_t iwl_dbgfs_sar_geo_profile_read(struct file *file, 344 char __user *user_buf, 345 size_t count, loff_t *ppos) 346 { 347 struct iwl_mvm *mvm = file->private_data; 348 char buf[256]; 349 int pos = 0; 350 int bufsz = sizeof(buf); 351 int tbl_idx; 352 353 if (!iwl_mvm_firmware_running(mvm)) 354 return -EIO; 355 356 mutex_lock(&mvm->mutex); 357 tbl_idx = iwl_mvm_get_sar_geo_profile(mvm); 358 if (tbl_idx < 0) { 359 mutex_unlock(&mvm->mutex); 360 return tbl_idx; 361 } 362 363 if (!tbl_idx) { 364 pos = scnprintf(buf, bufsz, 365 "SAR geographic profile disabled\n"); 366 } else { 367 pos += scnprintf(buf + pos, bufsz - pos, 368 "Use geographic profile %d\n", tbl_idx); 369 pos += scnprintf(buf + pos, bufsz - pos, 370 "2.4GHz:\n\tChain A offset: %u dBm\n\tChain B offset: %u dBm\n\tmax tx power: %u dBm\n", 371 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].chains[0], 372 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].chains[1], 373 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[0].max); 374 pos += scnprintf(buf + pos, bufsz - pos, 375 "5.2GHz:\n\tChain A offset: %u dBm\n\tChain B offset: %u dBm\n\tmax tx power: %u dBm\n", 376 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].chains[0], 377 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].chains[1], 378 mvm->fwrt.geo_profiles[tbl_idx - 1].bands[1].max); 379 } 380 mutex_unlock(&mvm->mutex); 381 382 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 383 } 384 385 static ssize_t iwl_dbgfs_wifi_6e_enable_read(struct file *file, 386 char __user *user_buf, 387 size_t count, loff_t *ppos) 388 { 389 struct iwl_mvm *mvm = file->private_data; 390 int err, pos; 391 char buf[12]; 392 u32 value; 393 394 err = iwl_bios_get_dsm(&mvm->fwrt, DSM_FUNC_ENABLE_6E, &value); 395 if (err) 396 return err; 397 398 pos = sprintf(buf, "0x%08x\n", value); 399 400 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 401 } 402 #endif 403 404 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, 405 size_t count, loff_t *ppos) 406 { 407 struct iwl_mvm *mvm = file->private_data; 408 struct ieee80211_sta *sta; 409 char buf[400]; 410 int i, pos = 0, bufsz = sizeof(buf); 411 412 mutex_lock(&mvm->mutex); 413 414 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 415 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); 416 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 417 lockdep_is_held(&mvm->mutex)); 418 if (!sta) 419 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); 420 else if (IS_ERR(sta)) 421 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", 422 PTR_ERR(sta)); 423 else 424 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", 425 sta->addr); 426 } 427 428 mutex_unlock(&mvm->mutex); 429 430 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 431 } 432 433 static ssize_t iwl_dbgfs_rs_data_read(struct ieee80211_link_sta *link_sta, 434 struct iwl_mvm_sta *mvmsta, 435 struct iwl_mvm *mvm, 436 struct iwl_mvm_link_sta *mvm_link_sta, 437 char __user *user_buf, 438 size_t count, loff_t *ppos) 439 { 440 struct iwl_lq_sta_rs_fw *lq_sta = &mvm_link_sta->lq_sta.rs_fw; 441 static const size_t bufsz = 2048; 442 char *buff; 443 int desc = 0; 444 ssize_t ret; 445 446 buff = kmalloc(bufsz, GFP_KERNEL); 447 if (!buff) 448 return -ENOMEM; 449 450 desc += scnprintf(buff + desc, bufsz - desc, "sta_id %d\n", 451 lq_sta->pers.sta_id); 452 desc += scnprintf(buff + desc, bufsz - desc, 453 "fixed rate 0x%X\n", 454 lq_sta->pers.dbg_fixed_rate); 455 desc += scnprintf(buff + desc, bufsz - desc, 456 "A-MPDU size limit %d\n", 457 lq_sta->pers.dbg_agg_frame_count_lim); 458 desc += scnprintf(buff + desc, bufsz - desc, 459 "valid_tx_ant %s%s\n", 460 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_A) ? "ANT_A," : "", 461 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_B) ? "ANT_B," : ""); 462 desc += scnprintf(buff + desc, bufsz - desc, 463 "last tx rate=0x%X ", 464 lq_sta->last_rate_n_flags); 465 466 desc += rs_pretty_print_rate(buff + desc, bufsz - desc, 467 lq_sta->last_rate_n_flags); 468 if (desc < bufsz - 1) 469 buff[desc++] = '\n'; 470 471 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); 472 kfree(buff); 473 return ret; 474 } 475 476 static ssize_t iwl_dbgfs_amsdu_len_write(struct ieee80211_link_sta *link_sta, 477 struct iwl_mvm_sta *mvmsta, 478 struct iwl_mvm *mvm, 479 struct iwl_mvm_link_sta *mvm_link_sta, 480 char *buf, size_t count, 481 loff_t *ppos) 482 { 483 int i; 484 u16 amsdu_len; 485 486 if (kstrtou16(buf, 0, &amsdu_len)) 487 return -EINVAL; 488 489 /* only change from debug set <-> debug unset */ 490 if (amsdu_len && mvm_link_sta->orig_amsdu_len) 491 return -EBUSY; 492 493 if (amsdu_len) { 494 mvm_link_sta->orig_amsdu_len = link_sta->agg.max_amsdu_len; 495 link_sta->agg.max_amsdu_len = amsdu_len; 496 link_sta->agg.max_amsdu_len = amsdu_len; 497 for (i = 0; i < ARRAY_SIZE(link_sta->agg.max_tid_amsdu_len); i++) 498 link_sta->agg.max_tid_amsdu_len[i] = amsdu_len; 499 } else { 500 link_sta->agg.max_amsdu_len = mvm_link_sta->orig_amsdu_len; 501 mvm_link_sta->orig_amsdu_len = 0; 502 } 503 504 ieee80211_sta_recalc_aggregates(link_sta->sta); 505 506 return count; 507 } 508 509 static ssize_t iwl_dbgfs_amsdu_len_read(struct ieee80211_link_sta *link_sta, 510 struct iwl_mvm_sta *mvmsta, 511 struct iwl_mvm *mvm, 512 struct iwl_mvm_link_sta *mvm_link_sta, 513 char __user *user_buf, 514 size_t count, loff_t *ppos) 515 { 516 char buf[32]; 517 int pos; 518 519 pos = scnprintf(buf, sizeof(buf), "current %d ", 520 link_sta->agg.max_amsdu_len); 521 pos += scnprintf(buf + pos, sizeof(buf) - pos, "stored %d\n", 522 mvm_link_sta->orig_amsdu_len); 523 524 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 525 } 526 527 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file, 528 char __user *user_buf, 529 size_t count, loff_t *ppos) 530 { 531 struct iwl_mvm *mvm = file->private_data; 532 char buf[64]; 533 int bufsz = sizeof(buf); 534 int pos = 0; 535 536 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n", 537 mvm->disable_power_off); 538 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n", 539 mvm->disable_power_off_d3); 540 541 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 542 } 543 544 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf, 545 size_t count, loff_t *ppos) 546 { 547 int ret, val; 548 549 if (!iwl_mvm_firmware_running(mvm)) 550 return -EIO; 551 552 if (!strncmp("disable_power_off_d0=", buf, 21)) { 553 if (sscanf(buf + 21, "%d", &val) != 1) 554 return -EINVAL; 555 mvm->disable_power_off = val; 556 } else if (!strncmp("disable_power_off_d3=", buf, 21)) { 557 if (sscanf(buf + 21, "%d", &val) != 1) 558 return -EINVAL; 559 mvm->disable_power_off_d3 = val; 560 } else { 561 return -EINVAL; 562 } 563 564 mutex_lock(&mvm->mutex); 565 ret = iwl_mvm_power_update_device(mvm); 566 mutex_unlock(&mvm->mutex); 567 568 return ret ?: count; 569 } 570 571 static 572 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf, 573 int pos, int bufsz) 574 { 575 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); 576 577 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); 578 BT_MBOX_PRINT(0, LE_PROF1, false); 579 BT_MBOX_PRINT(0, LE_PROF2, false); 580 BT_MBOX_PRINT(0, LE_PROF_OTHER, false); 581 BT_MBOX_PRINT(0, CHL_SEQ_N, false); 582 BT_MBOX_PRINT(0, INBAND_S, false); 583 BT_MBOX_PRINT(0, LE_MIN_RSSI, false); 584 BT_MBOX_PRINT(0, LE_SCAN, false); 585 BT_MBOX_PRINT(0, LE_ADV, false); 586 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); 587 BT_MBOX_PRINT(0, OPEN_CON_1, true); 588 589 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); 590 591 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); 592 BT_MBOX_PRINT(1, IP_SR, false); 593 BT_MBOX_PRINT(1, LE_MSTR, false); 594 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); 595 BT_MBOX_PRINT(1, MSG_TYPE, false); 596 BT_MBOX_PRINT(1, SSN, true); 597 598 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); 599 600 BT_MBOX_PRINT(2, SNIFF_ACT, false); 601 BT_MBOX_PRINT(2, PAG, false); 602 BT_MBOX_PRINT(2, INQUIRY, false); 603 BT_MBOX_PRINT(2, CONN, false); 604 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); 605 BT_MBOX_PRINT(2, DISC, false); 606 BT_MBOX_PRINT(2, SCO_TX_ACT, false); 607 BT_MBOX_PRINT(2, SCO_RX_ACT, false); 608 BT_MBOX_PRINT(2, ESCO_RE_TX, false); 609 BT_MBOX_PRINT(2, SCO_DURATION, true); 610 611 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); 612 613 BT_MBOX_PRINT(3, SCO_STATE, false); 614 BT_MBOX_PRINT(3, SNIFF_STATE, false); 615 BT_MBOX_PRINT(3, A2DP_STATE, false); 616 BT_MBOX_PRINT(3, A2DP_SRC, false); 617 BT_MBOX_PRINT(3, ACL_STATE, false); 618 BT_MBOX_PRINT(3, MSTR_STATE, false); 619 BT_MBOX_PRINT(3, OBX_STATE, false); 620 BT_MBOX_PRINT(3, OPEN_CON_2, false); 621 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); 622 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); 623 BT_MBOX_PRINT(3, INBAND_P, false); 624 BT_MBOX_PRINT(3, MSG_TYPE_2, false); 625 BT_MBOX_PRINT(3, SSN_2, false); 626 BT_MBOX_PRINT(3, UPDATE_REQUEST, true); 627 628 return pos; 629 } 630 631 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, 632 size_t count, loff_t *ppos) 633 { 634 struct iwl_mvm *mvm = file->private_data; 635 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; 636 char *buf; 637 int ret, pos = 0, bufsz = sizeof(char) * 1024; 638 639 buf = kmalloc(bufsz, GFP_KERNEL); 640 if (!buf) 641 return -ENOMEM; 642 643 mutex_lock(&mvm->mutex); 644 645 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz); 646 647 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n", 648 notif->bt_ci_compliance); 649 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n", 650 le32_to_cpu(notif->primary_ch_lut)); 651 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n", 652 le32_to_cpu(notif->secondary_ch_lut)); 653 pos += scnprintf(buf + pos, 654 bufsz - pos, "bt_activity_grading = %d\n", 655 le32_to_cpu(notif->bt_activity_grading)); 656 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n", 657 notif->rrc_status & 0xF); 658 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n", 659 notif->ttc_status & 0xF); 660 661 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n", 662 IWL_MVM_BT_COEX_SYNC2SCO); 663 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n", 664 IWL_MVM_BT_COEX_MPLUT); 665 666 mutex_unlock(&mvm->mutex); 667 668 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 669 kfree(buf); 670 671 return ret; 672 } 673 #undef BT_MBOX_PRINT 674 675 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf, 676 size_t count, loff_t *ppos) 677 { 678 struct iwl_mvm *mvm = file->private_data; 679 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd; 680 char buf[256]; 681 int bufsz = sizeof(buf); 682 int pos = 0; 683 684 mutex_lock(&mvm->mutex); 685 686 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n"); 687 pos += scnprintf(buf + pos, bufsz - pos, 688 "\tPrimary Channel Bitmap 0x%016llx\n", 689 le64_to_cpu(cmd->bt_primary_ci)); 690 pos += scnprintf(buf + pos, bufsz - pos, 691 "\tSecondary Channel Bitmap 0x%016llx\n", 692 le64_to_cpu(cmd->bt_secondary_ci)); 693 694 mutex_unlock(&mvm->mutex); 695 696 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 697 } 698 699 static ssize_t 700 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf, 701 size_t count, loff_t *ppos) 702 { 703 u32 bt_tx_prio; 704 705 if (sscanf(buf, "%u", &bt_tx_prio) != 1) 706 return -EINVAL; 707 if (bt_tx_prio > 4) 708 return -EINVAL; 709 710 mvm->bt_tx_prio = bt_tx_prio; 711 712 return count; 713 } 714 715 static ssize_t 716 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf, 717 size_t count, loff_t *ppos) 718 { 719 static const char * const modes_str[BT_FORCE_ANT_MAX] = { 720 [BT_FORCE_ANT_DIS] = "dis", 721 [BT_FORCE_ANT_AUTO] = "auto", 722 [BT_FORCE_ANT_BT] = "bt", 723 [BT_FORCE_ANT_WIFI] = "wifi", 724 }; 725 int ret, bt_force_ant_mode; 726 727 ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf); 728 if (ret < 0) 729 return ret; 730 731 bt_force_ant_mode = ret; 732 ret = 0; 733 mutex_lock(&mvm->mutex); 734 if (mvm->bt_force_ant_mode == bt_force_ant_mode) 735 goto out; 736 737 mvm->bt_force_ant_mode = bt_force_ant_mode; 738 IWL_DEBUG_COEX(mvm, "Force mode: %s\n", 739 modes_str[mvm->bt_force_ant_mode]); 740 741 if (iwl_mvm_firmware_running(mvm)) 742 ret = iwl_mvm_send_bt_init_conf(mvm); 743 else 744 ret = 0; 745 746 out: 747 mutex_unlock(&mvm->mutex); 748 return ret ?: count; 749 } 750 751 static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf, 752 size_t count, loff_t *ppos) 753 { 754 struct iwl_mvm *mvm = file->private_data; 755 char *buff, *pos, *endpos; 756 static const size_t bufsz = 1024; 757 int ret; 758 759 buff = kmalloc(bufsz, GFP_KERNEL); 760 if (!buff) 761 return -ENOMEM; 762 763 pos = buff; 764 endpos = pos + bufsz; 765 766 pos += scnprintf(pos, endpos - pos, "FW id: %s\n", 767 mvm->fwrt.fw->fw_version); 768 pos += scnprintf(pos, endpos - pos, "FW: %s\n", 769 mvm->fwrt.fw->human_readable); 770 pos += scnprintf(pos, endpos - pos, "Device: %s\n", 771 mvm->fwrt.trans->name); 772 pos += scnprintf(pos, endpos - pos, "Bus: %s\n", 773 mvm->fwrt.dev->bus->name); 774 775 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); 776 kfree(buff); 777 778 return ret; 779 } 780 781 static ssize_t iwl_dbgfs_tas_get_status_read(struct file *file, 782 char __user *user_buf, 783 size_t count, loff_t *ppos) 784 { 785 struct iwl_mvm *mvm = file->private_data; 786 struct iwl_mvm_tas_status_resp tas_rsp; 787 struct iwl_mvm_tas_status_resp *rsp = &tas_rsp; 788 static const size_t bufsz = 1024; 789 char *buff, *pos, *endpos; 790 const char * const tas_dis_reason[TAS_DISABLED_REASON_MAX] = { 791 [TAS_DISABLED_DUE_TO_BIOS] = 792 "Due To BIOS", 793 [TAS_DISABLED_DUE_TO_SAR_6DBM] = 794 "Due To SAR Limit Less Than 6 dBm", 795 [TAS_DISABLED_REASON_INVALID] = 796 "N/A", 797 }; 798 const char * const tas_current_status[TAS_DYNA_STATUS_MAX] = { 799 [TAS_DYNA_INACTIVE] = "INACTIVE", 800 [TAS_DYNA_INACTIVE_MVM_MODE] = 801 "inactive due to mvm mode", 802 [TAS_DYNA_INACTIVE_TRIGGER_MODE] = 803 "inactive due to trigger mode", 804 [TAS_DYNA_INACTIVE_BLOCK_LISTED] = 805 "inactive due to block listed", 806 [TAS_DYNA_INACTIVE_UHB_NON_US] = 807 "inactive due to uhb non US", 808 [TAS_DYNA_ACTIVE] = "ACTIVE", 809 }; 810 struct iwl_host_cmd hcmd = { 811 .id = WIDE_ID(DEBUG_GROUP, GET_TAS_STATUS), 812 .flags = CMD_WANT_SKB, 813 .len = { 0, }, 814 .data = { NULL, }, 815 }; 816 int ret, i, tmp; 817 bool tas_enabled = false; 818 unsigned long dyn_status; 819 820 if (!iwl_mvm_firmware_running(mvm)) 821 return -ENODEV; 822 823 mutex_lock(&mvm->mutex); 824 ret = iwl_mvm_send_cmd(mvm, &hcmd); 825 mutex_unlock(&mvm->mutex); 826 if (ret < 0) 827 return ret; 828 829 buff = kzalloc(bufsz, GFP_KERNEL); 830 if (!buff) 831 return -ENOMEM; 832 pos = buff; 833 endpos = pos + bufsz; 834 835 rsp = (void *)hcmd.resp_pkt->data; 836 837 pos += scnprintf(pos, endpos - pos, "TAS Conclusion:\n"); 838 for (i = 0; i < rsp->in_dual_radio + 1; i++) { 839 if (rsp->tas_status_mac[i].band != TAS_LMAC_BAND_INVALID && 840 rsp->tas_status_mac[i].dynamic_status & BIT(TAS_DYNA_ACTIVE)) { 841 pos += scnprintf(pos, endpos - pos, "\tON for "); 842 switch (rsp->tas_status_mac[i].band) { 843 case TAS_LMAC_BAND_HB: 844 pos += scnprintf(pos, endpos - pos, "HB\n"); 845 break; 846 case TAS_LMAC_BAND_LB: 847 pos += scnprintf(pos, endpos - pos, "LB\n"); 848 break; 849 case TAS_LMAC_BAND_UHB: 850 pos += scnprintf(pos, endpos - pos, "UHB\n"); 851 break; 852 case TAS_LMAC_BAND_INVALID: 853 pos += scnprintf(pos, endpos - pos, 854 "INVALID BAND\n"); 855 break; 856 default: 857 pos += scnprintf(pos, endpos - pos, 858 "Unsupported band (%d)\n", 859 rsp->tas_status_mac[i].band); 860 goto out; 861 } 862 tas_enabled = true; 863 } 864 } 865 if (!tas_enabled) 866 pos += scnprintf(pos, endpos - pos, "\tOFF\n"); 867 868 pos += scnprintf(pos, endpos - pos, "TAS Report\n"); 869 pos += scnprintf(pos, endpos - pos, "TAS FW version: %d\n", 870 rsp->tas_fw_version); 871 pos += scnprintf(pos, endpos - pos, "Is UHB enabled for USA?: %s\n", 872 rsp->is_uhb_for_usa_enable ? "True" : "False"); 873 pos += scnprintf(pos, endpos - pos, "Current MCC: 0x%x\n", 874 le16_to_cpu(rsp->curr_mcc)); 875 876 pos += scnprintf(pos, endpos - pos, "Block list entries:"); 877 for (i = 0; i < IWL_WTAS_BLACK_LIST_MAX; i++) 878 pos += scnprintf(pos, endpos - pos, " 0x%x", 879 le16_to_cpu(rsp->block_list[i])); 880 881 pos += scnprintf(pos, endpos - pos, "\nOEM name: %s\n", 882 dmi_get_system_info(DMI_SYS_VENDOR) ?: "<unknown>"); 883 pos += scnprintf(pos, endpos - pos, "\tVendor In Approved List: %s\n", 884 iwl_is_tas_approved() ? "YES" : "NO"); 885 pos += scnprintf(pos, endpos - pos, 886 "\tDo TAS Support Dual Radio?: %s\n", 887 rsp->in_dual_radio ? "TRUE" : "FALSE"); 888 889 for (i = 0; i < rsp->in_dual_radio + 1; i++) { 890 if (rsp->tas_status_mac[i].static_status == 0) { 891 pos += scnprintf(pos, endpos - pos, 892 "Static status: disabled\n"); 893 pos += scnprintf(pos, endpos - pos, 894 "Static disabled reason: %s (0)\n", 895 tas_dis_reason[0]); 896 goto out; 897 } 898 899 pos += scnprintf(pos, endpos - pos, "TAS status for "); 900 switch (rsp->tas_status_mac[i].band) { 901 case TAS_LMAC_BAND_HB: 902 pos += scnprintf(pos, endpos - pos, "High band\n"); 903 break; 904 case TAS_LMAC_BAND_LB: 905 pos += scnprintf(pos, endpos - pos, "Low band\n"); 906 break; 907 case TAS_LMAC_BAND_UHB: 908 pos += scnprintf(pos, endpos - pos, 909 "Ultra high band\n"); 910 break; 911 case TAS_LMAC_BAND_INVALID: 912 pos += scnprintf(pos, endpos - pos, 913 "INVALID band\n"); 914 break; 915 default: 916 pos += scnprintf(pos, endpos - pos, 917 "Unsupported band (%d)\n", 918 rsp->tas_status_mac[i].band); 919 goto out; 920 } 921 pos += scnprintf(pos, endpos - pos, "Static status: %sabled\n", 922 rsp->tas_status_mac[i].static_status ? 923 "En" : "Dis"); 924 pos += scnprintf(pos, endpos - pos, 925 "\tStatic Disabled Reason: "); 926 if (rsp->tas_status_mac[i].static_dis_reason < TAS_DISABLED_REASON_MAX) 927 pos += scnprintf(pos, endpos - pos, "%s (%d)\n", 928 tas_dis_reason[rsp->tas_status_mac[i].static_dis_reason], 929 rsp->tas_status_mac[i].static_dis_reason); 930 else 931 pos += scnprintf(pos, endpos - pos, 932 "unsupported value (%d)\n", 933 rsp->tas_status_mac[i].static_dis_reason); 934 935 pos += scnprintf(pos, endpos - pos, "Dynamic status:\n"); 936 dyn_status = (rsp->tas_status_mac[i].dynamic_status); 937 for_each_set_bit(tmp, &dyn_status, sizeof(dyn_status)) { 938 if (tmp >= 0 && tmp < TAS_DYNA_STATUS_MAX) 939 pos += scnprintf(pos, endpos - pos, 940 "\t%s (%d)\n", 941 tas_current_status[tmp], tmp); 942 } 943 944 pos += scnprintf(pos, endpos - pos, 945 "Is near disconnection?: %s\n", 946 rsp->tas_status_mac[i].near_disconnection ? 947 "True" : "False"); 948 tmp = le16_to_cpu(rsp->tas_status_mac[i].max_reg_pwr_limit); 949 pos += scnprintf(pos, endpos - pos, 950 "Max. regulatory pwr limit (dBm): %d.%03d\n", 951 tmp / 8, 125 * (tmp % 8)); 952 tmp = le16_to_cpu(rsp->tas_status_mac[i].sar_limit); 953 pos += scnprintf(pos, endpos - pos, 954 "SAR limit (dBm): %d.%03d\n", 955 tmp / 8, 125 * (tmp % 8)); 956 } 957 958 out: 959 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); 960 kfree(buff); 961 iwl_free_resp(&hcmd); 962 return ret; 963 } 964 965 static ssize_t iwl_dbgfs_phy_integration_ver_read(struct file *file, 966 char __user *user_buf, 967 size_t count, loff_t *ppos) 968 { 969 struct iwl_mvm *mvm = file->private_data; 970 char *buf; 971 size_t bufsz; 972 int pos; 973 ssize_t ret; 974 975 bufsz = mvm->fw->phy_integration_ver_len + 2; 976 buf = kmalloc(bufsz, GFP_KERNEL); 977 if (!buf) 978 return -ENOMEM; 979 980 pos = scnprintf(buf, bufsz, "%.*s\n", mvm->fw->phy_integration_ver_len, 981 mvm->fw->phy_integration_ver); 982 983 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 984 985 kfree(buf); 986 return ret; 987 } 988 989 #define PRINT_STATS_LE32(_struct, _memb) \ 990 pos += scnprintf(buf + pos, bufsz - pos, \ 991 fmt_table, #_memb, \ 992 le32_to_cpu(_struct->_memb)) 993 994 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file, 995 char __user *user_buf, size_t count, 996 loff_t *ppos) 997 { 998 struct iwl_mvm *mvm = file->private_data; 999 static const char *fmt_table = "\t%-30s %10u\n"; 1000 static const char *fmt_header = "%-32s\n"; 1001 int pos = 0; 1002 char *buf; 1003 int ret; 1004 size_t bufsz; 1005 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, 1006 WIDE_ID(SYSTEM_GROUP, 1007 SYSTEM_STATISTICS_CMD), 1008 IWL_FW_CMD_VER_UNKNOWN); 1009 1010 if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN) 1011 return -EOPNOTSUPP; 1012 1013 if (iwl_mvm_has_new_rx_stats_api(mvm)) 1014 bufsz = ((sizeof(struct mvm_statistics_rx) / 1015 sizeof(__le32)) * 43) + (4 * 33) + 1; 1016 else 1017 /* 43 = size of each data line; 33 = size of each header */ 1018 bufsz = ((sizeof(struct mvm_statistics_rx_v3) / 1019 sizeof(__le32)) * 43) + (4 * 33) + 1; 1020 1021 buf = kzalloc(bufsz, GFP_KERNEL); 1022 if (!buf) 1023 return -ENOMEM; 1024 1025 mutex_lock(&mvm->mutex); 1026 1027 if (iwl_mvm_firmware_running(mvm)) 1028 iwl_mvm_request_statistics(mvm, false); 1029 1030 pos += scnprintf(buf + pos, bufsz - pos, fmt_header, 1031 "Statistics_Rx - OFDM"); 1032 if (!iwl_mvm_has_new_rx_stats_api(mvm)) { 1033 struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm; 1034 1035 PRINT_STATS_LE32(ofdm, ina_cnt); 1036 PRINT_STATS_LE32(ofdm, fina_cnt); 1037 PRINT_STATS_LE32(ofdm, plcp_err); 1038 PRINT_STATS_LE32(ofdm, crc32_err); 1039 PRINT_STATS_LE32(ofdm, overrun_err); 1040 PRINT_STATS_LE32(ofdm, early_overrun_err); 1041 PRINT_STATS_LE32(ofdm, crc32_good); 1042 PRINT_STATS_LE32(ofdm, false_alarm_cnt); 1043 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt); 1044 PRINT_STATS_LE32(ofdm, sfd_timeout); 1045 PRINT_STATS_LE32(ofdm, fina_timeout); 1046 PRINT_STATS_LE32(ofdm, unresponded_rts); 1047 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun); 1048 PRINT_STATS_LE32(ofdm, sent_ack_cnt); 1049 PRINT_STATS_LE32(ofdm, sent_cts_cnt); 1050 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt); 1051 PRINT_STATS_LE32(ofdm, dsp_self_kill); 1052 PRINT_STATS_LE32(ofdm, mh_format_err); 1053 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum); 1054 PRINT_STATS_LE32(ofdm, reserved); 1055 } else { 1056 struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm; 1057 1058 PRINT_STATS_LE32(ofdm, unresponded_rts); 1059 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun); 1060 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt); 1061 PRINT_STATS_LE32(ofdm, dsp_self_kill); 1062 PRINT_STATS_LE32(ofdm, reserved); 1063 } 1064 1065 pos += scnprintf(buf + pos, bufsz - pos, fmt_header, 1066 "Statistics_Rx - CCK"); 1067 if (!iwl_mvm_has_new_rx_stats_api(mvm)) { 1068 struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck; 1069 1070 PRINT_STATS_LE32(cck, ina_cnt); 1071 PRINT_STATS_LE32(cck, fina_cnt); 1072 PRINT_STATS_LE32(cck, plcp_err); 1073 PRINT_STATS_LE32(cck, crc32_err); 1074 PRINT_STATS_LE32(cck, overrun_err); 1075 PRINT_STATS_LE32(cck, early_overrun_err); 1076 PRINT_STATS_LE32(cck, crc32_good); 1077 PRINT_STATS_LE32(cck, false_alarm_cnt); 1078 PRINT_STATS_LE32(cck, fina_sync_err_cnt); 1079 PRINT_STATS_LE32(cck, sfd_timeout); 1080 PRINT_STATS_LE32(cck, fina_timeout); 1081 PRINT_STATS_LE32(cck, unresponded_rts); 1082 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun); 1083 PRINT_STATS_LE32(cck, sent_ack_cnt); 1084 PRINT_STATS_LE32(cck, sent_cts_cnt); 1085 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt); 1086 PRINT_STATS_LE32(cck, dsp_self_kill); 1087 PRINT_STATS_LE32(cck, mh_format_err); 1088 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum); 1089 PRINT_STATS_LE32(cck, reserved); 1090 } else { 1091 struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck; 1092 1093 PRINT_STATS_LE32(cck, unresponded_rts); 1094 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun); 1095 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt); 1096 PRINT_STATS_LE32(cck, dsp_self_kill); 1097 PRINT_STATS_LE32(cck, reserved); 1098 } 1099 1100 pos += scnprintf(buf + pos, bufsz - pos, fmt_header, 1101 "Statistics_Rx - GENERAL"); 1102 if (!iwl_mvm_has_new_rx_stats_api(mvm)) { 1103 struct mvm_statistics_rx_non_phy_v3 *general = 1104 &mvm->rx_stats_v3.general; 1105 1106 PRINT_STATS_LE32(general, bogus_cts); 1107 PRINT_STATS_LE32(general, bogus_ack); 1108 PRINT_STATS_LE32(general, non_bssid_frames); 1109 PRINT_STATS_LE32(general, filtered_frames); 1110 PRINT_STATS_LE32(general, non_channel_beacons); 1111 PRINT_STATS_LE32(general, channel_beacons); 1112 PRINT_STATS_LE32(general, num_missed_bcon); 1113 PRINT_STATS_LE32(general, adc_rx_saturation_time); 1114 PRINT_STATS_LE32(general, ina_detection_search_time); 1115 PRINT_STATS_LE32(general, beacon_silence_rssi_a); 1116 PRINT_STATS_LE32(general, beacon_silence_rssi_b); 1117 PRINT_STATS_LE32(general, beacon_silence_rssi_c); 1118 PRINT_STATS_LE32(general, interference_data_flag); 1119 PRINT_STATS_LE32(general, channel_load); 1120 PRINT_STATS_LE32(general, dsp_false_alarms); 1121 PRINT_STATS_LE32(general, beacon_rssi_a); 1122 PRINT_STATS_LE32(general, beacon_rssi_b); 1123 PRINT_STATS_LE32(general, beacon_rssi_c); 1124 PRINT_STATS_LE32(general, beacon_energy_a); 1125 PRINT_STATS_LE32(general, beacon_energy_b); 1126 PRINT_STATS_LE32(general, beacon_energy_c); 1127 PRINT_STATS_LE32(general, num_bt_kills); 1128 PRINT_STATS_LE32(general, mac_id); 1129 PRINT_STATS_LE32(general, directed_data_mpdu); 1130 } else { 1131 struct mvm_statistics_rx_non_phy *general = 1132 &mvm->rx_stats.general; 1133 1134 PRINT_STATS_LE32(general, bogus_cts); 1135 PRINT_STATS_LE32(general, bogus_ack); 1136 PRINT_STATS_LE32(general, non_channel_beacons); 1137 PRINT_STATS_LE32(general, channel_beacons); 1138 PRINT_STATS_LE32(general, num_missed_bcon); 1139 PRINT_STATS_LE32(general, adc_rx_saturation_time); 1140 PRINT_STATS_LE32(general, ina_detection_search_time); 1141 PRINT_STATS_LE32(general, beacon_silence_rssi_a); 1142 PRINT_STATS_LE32(general, beacon_silence_rssi_b); 1143 PRINT_STATS_LE32(general, beacon_silence_rssi_c); 1144 PRINT_STATS_LE32(general, interference_data_flag); 1145 PRINT_STATS_LE32(general, channel_load); 1146 PRINT_STATS_LE32(general, beacon_rssi_a); 1147 PRINT_STATS_LE32(general, beacon_rssi_b); 1148 PRINT_STATS_LE32(general, beacon_rssi_c); 1149 PRINT_STATS_LE32(general, beacon_energy_a); 1150 PRINT_STATS_LE32(general, beacon_energy_b); 1151 PRINT_STATS_LE32(general, beacon_energy_c); 1152 PRINT_STATS_LE32(general, num_bt_kills); 1153 PRINT_STATS_LE32(general, mac_id); 1154 } 1155 1156 pos += scnprintf(buf + pos, bufsz - pos, fmt_header, 1157 "Statistics_Rx - HT"); 1158 if (!iwl_mvm_has_new_rx_stats_api(mvm)) { 1159 struct mvm_statistics_rx_ht_phy_v1 *ht = 1160 &mvm->rx_stats_v3.ofdm_ht; 1161 1162 PRINT_STATS_LE32(ht, plcp_err); 1163 PRINT_STATS_LE32(ht, overrun_err); 1164 PRINT_STATS_LE32(ht, early_overrun_err); 1165 PRINT_STATS_LE32(ht, crc32_good); 1166 PRINT_STATS_LE32(ht, crc32_err); 1167 PRINT_STATS_LE32(ht, mh_format_err); 1168 PRINT_STATS_LE32(ht, agg_crc32_good); 1169 PRINT_STATS_LE32(ht, agg_mpdu_cnt); 1170 PRINT_STATS_LE32(ht, agg_cnt); 1171 PRINT_STATS_LE32(ht, unsupport_mcs); 1172 } else { 1173 struct mvm_statistics_rx_ht_phy *ht = 1174 &mvm->rx_stats.ofdm_ht; 1175 1176 PRINT_STATS_LE32(ht, mh_format_err); 1177 PRINT_STATS_LE32(ht, agg_mpdu_cnt); 1178 PRINT_STATS_LE32(ht, agg_cnt); 1179 PRINT_STATS_LE32(ht, unsupport_mcs); 1180 } 1181 1182 mutex_unlock(&mvm->mutex); 1183 1184 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1185 kfree(buf); 1186 1187 return ret; 1188 } 1189 #undef PRINT_STAT_LE32 1190 1191 static ssize_t iwl_dbgfs_fw_system_stats_read(struct file *file, 1192 char __user *user_buf, 1193 size_t count, loff_t *ppos) 1194 { 1195 char *buff, *pos, *endpos; 1196 int ret; 1197 size_t bufsz; 1198 int i; 1199 struct iwl_mvm_vif *mvmvif; 1200 struct ieee80211_vif *vif; 1201 struct iwl_mvm *mvm = file->private_data; 1202 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, 1203 WIDE_ID(SYSTEM_GROUP, 1204 SYSTEM_STATISTICS_CMD), 1205 IWL_FW_CMD_VER_UNKNOWN); 1206 1207 /* in case of a wrong cmd version, allocate buffer only for error msg */ 1208 bufsz = (cmd_ver == 1) ? 4096 : 64; 1209 1210 buff = kzalloc(bufsz, GFP_KERNEL); 1211 if (!buff) 1212 return -ENOMEM; 1213 1214 pos = buff; 1215 endpos = pos + bufsz; 1216 1217 if (cmd_ver != 1) { 1218 pos += scnprintf(pos, endpos - pos, 1219 "System stats not supported:%d\n", cmd_ver); 1220 goto send_out; 1221 } 1222 1223 mutex_lock(&mvm->mutex); 1224 if (iwl_mvm_firmware_running(mvm)) 1225 iwl_mvm_request_statistics(mvm, false); 1226 1227 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) { 1228 vif = iwl_mvm_rcu_dereference_vif_id(mvm, i, false); 1229 if (!vif) 1230 continue; 1231 1232 if (vif->type == NL80211_IFTYPE_STATION) 1233 break; 1234 } 1235 1236 if (i == NUM_MAC_INDEX_DRIVER || !vif) { 1237 pos += scnprintf(pos, endpos - pos, "vif is NULL\n"); 1238 goto release_send_out; 1239 } 1240 1241 mvmvif = iwl_mvm_vif_from_mac80211(vif); 1242 if (!mvmvif) { 1243 pos += scnprintf(pos, endpos - pos, "mvmvif is NULL\n"); 1244 goto release_send_out; 1245 } 1246 1247 for_each_mvm_vif_valid_link(mvmvif, i) { 1248 struct iwl_mvm_vif_link_info *link_info = mvmvif->link[i]; 1249 1250 pos += scnprintf(pos, endpos - pos, 1251 "link_id %d", i); 1252 pos += scnprintf(pos, endpos - pos, 1253 " num_beacons %d", 1254 link_info->beacon_stats.num_beacons); 1255 pos += scnprintf(pos, endpos - pos, 1256 " accu_num_beacons %d", 1257 link_info->beacon_stats.accu_num_beacons); 1258 pos += scnprintf(pos, endpos - pos, 1259 " avg_signal %d\n", 1260 link_info->beacon_stats.avg_signal); 1261 } 1262 1263 pos += scnprintf(pos, endpos - pos, 1264 "radio_stats.rx_time %lld\n", 1265 mvm->radio_stats.rx_time); 1266 pos += scnprintf(pos, endpos - pos, 1267 "radio_stats.tx_time %lld\n", 1268 mvm->radio_stats.tx_time); 1269 pos += scnprintf(pos, endpos - pos, 1270 "accu_radio_stats.rx_time %lld\n", 1271 mvm->accu_radio_stats.rx_time); 1272 pos += scnprintf(pos, endpos - pos, 1273 "accu_radio_stats.tx_time %lld\n", 1274 mvm->accu_radio_stats.tx_time); 1275 1276 release_send_out: 1277 mutex_unlock(&mvm->mutex); 1278 1279 send_out: 1280 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); 1281 kfree(buff); 1282 1283 return ret; 1284 } 1285 1286 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm, 1287 char __user *user_buf, size_t count, 1288 loff_t *ppos, 1289 struct iwl_mvm_frame_stats *stats) 1290 { 1291 char *buff, *pos, *endpos; 1292 int idx, i; 1293 int ret; 1294 static const size_t bufsz = 1024; 1295 1296 buff = kmalloc(bufsz, GFP_KERNEL); 1297 if (!buff) 1298 return -ENOMEM; 1299 1300 spin_lock_bh(&mvm->drv_stats_lock); 1301 1302 pos = buff; 1303 endpos = pos + bufsz; 1304 1305 pos += scnprintf(pos, endpos - pos, 1306 "Legacy/HT/VHT\t:\t%d/%d/%d\n", 1307 stats->legacy_frames, 1308 stats->ht_frames, 1309 stats->vht_frames); 1310 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n", 1311 stats->bw_20_frames, 1312 stats->bw_40_frames, 1313 stats->bw_80_frames); 1314 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n", 1315 stats->ngi_frames, 1316 stats->sgi_frames); 1317 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n", 1318 stats->siso_frames, 1319 stats->mimo2_frames); 1320 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n", 1321 stats->fail_frames, 1322 stats->success_frames); 1323 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n", 1324 stats->agg_frames); 1325 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n", 1326 stats->ampdu_count); 1327 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n", 1328 stats->ampdu_count > 0 ? 1329 (stats->agg_frames / stats->ampdu_count) : 0); 1330 1331 pos += scnprintf(pos, endpos - pos, "Last Rates\n"); 1332 1333 idx = stats->last_frame_idx - 1; 1334 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) { 1335 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates); 1336 if (stats->last_rates[idx] == 0) 1337 continue; 1338 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ", 1339 (int)(ARRAY_SIZE(stats->last_rates) - i)); 1340 pos += rs_pretty_print_rate_v1(pos, endpos - pos, 1341 stats->last_rates[idx]); 1342 if (pos < endpos - 1) 1343 *pos++ = '\n'; 1344 } 1345 spin_unlock_bh(&mvm->drv_stats_lock); 1346 1347 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); 1348 kfree(buff); 1349 1350 return ret; 1351 } 1352 1353 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file, 1354 char __user *user_buf, size_t count, 1355 loff_t *ppos) 1356 { 1357 struct iwl_mvm *mvm = file->private_data; 1358 1359 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos, 1360 &mvm->drv_rx_stats); 1361 } 1362 1363 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf, 1364 size_t count, loff_t *ppos) 1365 { 1366 int __maybe_unused ret; 1367 1368 if (!iwl_mvm_firmware_running(mvm)) 1369 return -EIO; 1370 1371 mutex_lock(&mvm->mutex); 1372 1373 /* allow one more restart that we're provoking here */ 1374 if (mvm->fw_restart >= 0) 1375 mvm->fw_restart++; 1376 1377 if (count == 6 && !strcmp(buf, "nolog\n")) { 1378 set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status); 1379 set_bit(STATUS_SUPPRESS_CMD_ERROR_ONCE, &mvm->trans->status); 1380 } 1381 1382 /* take the return value to make compiler happy - it will fail anyway */ 1383 ret = iwl_mvm_send_cmd_pdu(mvm, 1384 WIDE_ID(LONG_GROUP, REPLY_ERROR), 1385 0, 0, NULL); 1386 1387 mutex_unlock(&mvm->mutex); 1388 1389 return count; 1390 } 1391 1392 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf, 1393 size_t count, loff_t *ppos) 1394 { 1395 if (!iwl_mvm_firmware_running(mvm)) 1396 return -EIO; 1397 1398 IWL_ERR(mvm, "Triggering an NMI from debugfs\n"); 1399 1400 if (count == 6 && !strcmp(buf, "nolog\n")) 1401 set_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE, &mvm->status); 1402 1403 iwl_force_nmi(mvm->trans); 1404 1405 return count; 1406 } 1407 1408 static ssize_t 1409 iwl_dbgfs_scan_ant_rxchain_read(struct file *file, 1410 char __user *user_buf, 1411 size_t count, loff_t *ppos) 1412 { 1413 struct iwl_mvm *mvm = file->private_data; 1414 int pos = 0; 1415 char buf[32]; 1416 const size_t bufsz = sizeof(buf); 1417 1418 /* print which antennas were set for the scan command by the user */ 1419 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: "); 1420 if (mvm->scan_rx_ant & ANT_A) 1421 pos += scnprintf(buf + pos, bufsz - pos, "A"); 1422 if (mvm->scan_rx_ant & ANT_B) 1423 pos += scnprintf(buf + pos, bufsz - pos, "B"); 1424 pos += scnprintf(buf + pos, bufsz - pos, " (%x)\n", mvm->scan_rx_ant); 1425 1426 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1427 } 1428 1429 static ssize_t 1430 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf, 1431 size_t count, loff_t *ppos) 1432 { 1433 u8 scan_rx_ant; 1434 1435 if (!iwl_mvm_firmware_running(mvm)) 1436 return -EIO; 1437 1438 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1) 1439 return -EINVAL; 1440 if (scan_rx_ant > ANT_ABC) 1441 return -EINVAL; 1442 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm))) 1443 return -EINVAL; 1444 1445 if (mvm->scan_rx_ant != scan_rx_ant) { 1446 mvm->scan_rx_ant = scan_rx_ant; 1447 if (fw_has_capa(&mvm->fw->ucode_capa, 1448 IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 1449 iwl_mvm_config_scan(mvm); 1450 } 1451 1452 return count; 1453 } 1454 1455 static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm, 1456 char *buf, size_t count, 1457 loff_t *ppos) 1458 { 1459 struct iwl_rss_config_cmd cmd = { 1460 .flags = cpu_to_le32(IWL_RSS_ENABLE), 1461 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP | 1462 IWL_RSS_HASH_TYPE_IPV4_UDP | 1463 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD | 1464 IWL_RSS_HASH_TYPE_IPV6_TCP | 1465 IWL_RSS_HASH_TYPE_IPV6_UDP | 1466 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD, 1467 }; 1468 int ret, i, num_repeats, nbytes = count / 2; 1469 1470 ret = hex2bin(cmd.indirection_table, buf, nbytes); 1471 if (ret) 1472 return ret; 1473 1474 /* 1475 * The input is the redirection table, partial or full. 1476 * Repeat the pattern if needed. 1477 * For example, input of 01020F will be repeated 42 times, 1478 * indirecting RSS hash results to queues 1, 2, 15 (skipping 1479 * queues 3 - 14). 1480 */ 1481 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes; 1482 for (i = 1; i < num_repeats; i++) 1483 memcpy(&cmd.indirection_table[i * nbytes], 1484 cmd.indirection_table, nbytes); 1485 /* handle cut in the middle pattern for the last places */ 1486 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table, 1487 ARRAY_SIZE(cmd.indirection_table) % nbytes); 1488 1489 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key)); 1490 1491 mutex_lock(&mvm->mutex); 1492 if (iwl_mvm_firmware_running(mvm)) 1493 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, 1494 sizeof(cmd), &cmd); 1495 else 1496 ret = 0; 1497 mutex_unlock(&mvm->mutex); 1498 1499 return ret ?: count; 1500 } 1501 1502 static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm, 1503 char *buf, size_t count, 1504 loff_t *ppos) 1505 { 1506 struct iwl_op_mode *opmode = container_of((void *)mvm, 1507 struct iwl_op_mode, 1508 op_mode_specific); 1509 struct iwl_rx_cmd_buffer rxb = { 1510 ._rx_page_order = 0, 1511 .truesize = 0, /* not used */ 1512 ._offset = 0, 1513 }; 1514 struct iwl_rx_packet *pkt; 1515 int bin_len = count / 2; 1516 int ret = -EINVAL; 1517 1518 if (!iwl_mvm_firmware_running(mvm)) 1519 return -EIO; 1520 1521 /* supporting only MQ RX */ 1522 if (!mvm->trans->trans_cfg->mq_rx_supported) 1523 return -EOPNOTSUPP; 1524 1525 rxb._page = alloc_pages(GFP_ATOMIC, 0); 1526 if (!rxb._page) 1527 return -ENOMEM; 1528 pkt = rxb_addr(&rxb); 1529 1530 ret = hex2bin(page_address(rxb._page), buf, bin_len); 1531 if (ret) 1532 goto out; 1533 1534 /* avoid invalid memory access and malformed packet */ 1535 if (bin_len < sizeof(*pkt) || 1536 bin_len != sizeof(*pkt) + iwl_rx_packet_payload_len(pkt)) 1537 goto out; 1538 1539 local_bh_disable(); 1540 iwl_mvm_rx_mq(opmode, NULL, &rxb); 1541 local_bh_enable(); 1542 ret = 0; 1543 1544 out: 1545 iwl_free_rxb(&rxb); 1546 1547 return ret ?: count; 1548 } 1549 1550 static int _iwl_dbgfs_inject_beacon_ie(struct iwl_mvm *mvm, char *bin, int len) 1551 { 1552 struct ieee80211_vif *vif; 1553 struct iwl_mvm_vif *mvmvif; 1554 struct sk_buff *beacon; 1555 struct ieee80211_tx_info *info; 1556 struct iwl_mac_beacon_cmd beacon_cmd = {}; 1557 unsigned int link_id; 1558 u8 rate; 1559 int i; 1560 1561 len /= 2; 1562 1563 /* Element len should be represented by u8 */ 1564 if (len >= U8_MAX) 1565 return -EINVAL; 1566 1567 if (!iwl_mvm_firmware_running(mvm)) 1568 return -EIO; 1569 1570 if (!iwl_mvm_has_new_tx_api(mvm) && 1571 !fw_has_api(&mvm->fw->ucode_capa, 1572 IWL_UCODE_TLV_API_NEW_BEACON_TEMPLATE)) 1573 return -EINVAL; 1574 1575 mutex_lock(&mvm->mutex); 1576 1577 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) { 1578 vif = iwl_mvm_rcu_dereference_vif_id(mvm, i, false); 1579 if (!vif) 1580 continue; 1581 1582 if (vif->type == NL80211_IFTYPE_AP) 1583 break; 1584 } 1585 1586 if (i == NUM_MAC_INDEX_DRIVER || !vif) 1587 goto out_err; 1588 1589 mvm->hw->extra_beacon_tailroom = len; 1590 1591 beacon = ieee80211_beacon_get_template(mvm->hw, vif, NULL, 0); 1592 if (!beacon) 1593 goto out_err; 1594 1595 if (len && hex2bin(skb_put_zero(beacon, len), bin, len)) { 1596 dev_kfree_skb(beacon); 1597 goto out_err; 1598 } 1599 1600 mvm->beacon_inject_active = true; 1601 1602 mvmvif = iwl_mvm_vif_from_mac80211(vif); 1603 info = IEEE80211_SKB_CB(beacon); 1604 rate = iwl_mvm_mac_ctxt_get_beacon_rate(mvm, info, vif); 1605 1606 for_each_mvm_vif_valid_link(mvmvif, link_id) { 1607 beacon_cmd.flags = 1608 cpu_to_le16(iwl_mvm_mac_ctxt_get_beacon_flags(mvm->fw, 1609 rate)); 1610 beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len); 1611 if (iwl_fw_lookup_cmd_ver(mvm->fw, BEACON_TEMPLATE_CMD, 0) > 12) 1612 beacon_cmd.link_id = 1613 cpu_to_le32(mvmvif->link[link_id]->fw_link_id); 1614 else 1615 beacon_cmd.link_id = cpu_to_le32((u32)mvmvif->id); 1616 1617 iwl_mvm_mac_ctxt_set_tim(mvm, &beacon_cmd.tim_idx, 1618 &beacon_cmd.tim_size, 1619 beacon->data, beacon->len); 1620 1621 if (iwl_fw_lookup_cmd_ver(mvm->fw, 1622 BEACON_TEMPLATE_CMD, 0) >= 14) { 1623 u32 offset = iwl_mvm_find_ie_offset(beacon->data, 1624 WLAN_EID_S1G_TWT, 1625 beacon->len); 1626 1627 beacon_cmd.btwt_offset = cpu_to_le32(offset); 1628 } 1629 1630 iwl_mvm_mac_ctxt_send_beacon_cmd(mvm, beacon, &beacon_cmd, 1631 sizeof(beacon_cmd)); 1632 } 1633 mutex_unlock(&mvm->mutex); 1634 1635 dev_kfree_skb(beacon); 1636 1637 return 0; 1638 1639 out_err: 1640 mutex_unlock(&mvm->mutex); 1641 return -EINVAL; 1642 } 1643 1644 static ssize_t iwl_dbgfs_inject_beacon_ie_write(struct iwl_mvm *mvm, 1645 char *buf, size_t count, 1646 loff_t *ppos) 1647 { 1648 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, buf, count); 1649 1650 mvm->hw->extra_beacon_tailroom = 0; 1651 return ret ?: count; 1652 } 1653 1654 static ssize_t iwl_dbgfs_inject_beacon_ie_restore_write(struct iwl_mvm *mvm, 1655 char *buf, 1656 size_t count, 1657 loff_t *ppos) 1658 { 1659 int ret = _iwl_dbgfs_inject_beacon_ie(mvm, NULL, 0); 1660 1661 mvm->hw->extra_beacon_tailroom = 0; 1662 mvm->beacon_inject_active = false; 1663 return ret ?: count; 1664 } 1665 1666 static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file, 1667 char __user *user_buf, 1668 size_t count, loff_t *ppos) 1669 { 1670 struct iwl_mvm *mvm = file->private_data; 1671 int conf; 1672 char buf[8]; 1673 const size_t bufsz = sizeof(buf); 1674 int pos = 0; 1675 1676 mutex_lock(&mvm->mutex); 1677 conf = mvm->fwrt.dump.conf; 1678 mutex_unlock(&mvm->mutex); 1679 1680 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf); 1681 1682 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1683 } 1684 1685 static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm, 1686 char *buf, size_t count, 1687 loff_t *ppos) 1688 { 1689 unsigned int conf_id; 1690 int ret; 1691 1692 if (!iwl_mvm_firmware_running(mvm)) 1693 return -EIO; 1694 1695 ret = kstrtouint(buf, 0, &conf_id); 1696 if (ret) 1697 return ret; 1698 1699 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX)) 1700 return -EINVAL; 1701 1702 mutex_lock(&mvm->mutex); 1703 ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id); 1704 mutex_unlock(&mvm->mutex); 1705 1706 return ret ?: count; 1707 } 1708 1709 static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm, 1710 char *buf, size_t count, 1711 loff_t *ppos) 1712 { 1713 if (count == 0) 1714 return 0; 1715 1716 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_USER_TRIGGER, 1717 NULL); 1718 1719 iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf, 1720 (count - 1), NULL); 1721 1722 return count; 1723 } 1724 1725 static ssize_t iwl_dbgfs_fw_dbg_clear_write(struct iwl_mvm *mvm, 1726 char *buf, size_t count, 1727 loff_t *ppos) 1728 { 1729 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_9000) 1730 return -EOPNOTSUPP; 1731 1732 mutex_lock(&mvm->mutex); 1733 iwl_fw_dbg_clear_monitor_buf(&mvm->fwrt); 1734 mutex_unlock(&mvm->mutex); 1735 1736 return count; 1737 } 1738 1739 static ssize_t iwl_dbgfs_dbg_time_point_write(struct iwl_mvm *mvm, 1740 char *buf, size_t count, 1741 loff_t *ppos) 1742 { 1743 u32 timepoint; 1744 1745 if (kstrtou32(buf, 0, &timepoint)) 1746 return -EINVAL; 1747 1748 if (timepoint == IWL_FW_INI_TIME_POINT_INVALID || 1749 timepoint >= IWL_FW_INI_TIME_POINT_NUM) 1750 return -EINVAL; 1751 1752 iwl_dbg_tlv_time_point(&mvm->fwrt, timepoint, NULL); 1753 1754 return count; 1755 } 1756 1757 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \ 1758 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) 1759 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \ 1760 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) 1761 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \ 1762 debugfs_create_file(alias, mode, parent, mvm, \ 1763 &iwl_dbgfs_##name##_ops); \ 1764 } while (0) 1765 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \ 1766 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode) 1767 1768 static ssize_t 1769 _iwl_dbgfs_link_sta_wrap_write(ssize_t (*real)(struct ieee80211_link_sta *, 1770 struct iwl_mvm_sta *, 1771 struct iwl_mvm *, 1772 struct iwl_mvm_link_sta *, 1773 char *, 1774 size_t, loff_t *), 1775 struct file *file, 1776 char *buf, size_t buf_size, loff_t *ppos) 1777 { 1778 struct ieee80211_link_sta *link_sta = file->private_data; 1779 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(link_sta->sta); 1780 struct iwl_mvm *mvm = iwl_mvm_vif_from_mac80211(mvmsta->vif)->mvm; 1781 struct iwl_mvm_link_sta *mvm_link_sta; 1782 ssize_t ret; 1783 1784 mutex_lock(&mvm->mutex); 1785 1786 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_sta->link_id], 1787 lockdep_is_held(&mvm->mutex)); 1788 if (WARN_ON(!mvm_link_sta)) { 1789 mutex_unlock(&mvm->mutex); 1790 return -ENODEV; 1791 } 1792 1793 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, buf, buf_size, ppos); 1794 1795 mutex_unlock(&mvm->mutex); 1796 1797 return ret; 1798 } 1799 1800 static ssize_t 1801 _iwl_dbgfs_link_sta_wrap_read(ssize_t (*real)(struct ieee80211_link_sta *, 1802 struct iwl_mvm_sta *, 1803 struct iwl_mvm *, 1804 struct iwl_mvm_link_sta *, 1805 char __user *, 1806 size_t, loff_t *), 1807 struct file *file, 1808 char __user *user_buf, size_t count, loff_t *ppos) 1809 { 1810 struct ieee80211_link_sta *link_sta = file->private_data; 1811 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(link_sta->sta); 1812 struct iwl_mvm *mvm = iwl_mvm_vif_from_mac80211(mvmsta->vif)->mvm; 1813 struct iwl_mvm_link_sta *mvm_link_sta; 1814 ssize_t ret; 1815 1816 mutex_lock(&mvm->mutex); 1817 1818 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_sta->link_id], 1819 lockdep_is_held(&mvm->mutex)); 1820 if (WARN_ON(!mvm_link_sta)) { 1821 mutex_unlock(&mvm->mutex); 1822 return -ENODEV; 1823 } 1824 1825 ret = real(link_sta, mvmsta, mvm, mvm_link_sta, user_buf, count, ppos); 1826 1827 mutex_unlock(&mvm->mutex); 1828 1829 return ret; 1830 } 1831 1832 #define MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, buflen) \ 1833 static ssize_t _iwl_dbgfs_link_sta_##name##_write(struct file *file, \ 1834 const char __user *user_buf, \ 1835 size_t count, loff_t *ppos) \ 1836 { \ 1837 char buf[buflen] = {}; \ 1838 size_t buf_size = min(count, sizeof(buf) - 1); \ 1839 \ 1840 if (copy_from_user(buf, user_buf, buf_size)) \ 1841 return -EFAULT; \ 1842 \ 1843 return _iwl_dbgfs_link_sta_wrap_write(iwl_dbgfs_##name##_write, \ 1844 file, \ 1845 buf, buf_size, ppos); \ 1846 } \ 1847 1848 #define MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \ 1849 static ssize_t _iwl_dbgfs_link_sta_##name##_read(struct file *file, \ 1850 char __user *user_buf, \ 1851 size_t count, loff_t *ppos) \ 1852 { \ 1853 return _iwl_dbgfs_link_sta_wrap_read(iwl_dbgfs_##name##_read, \ 1854 file, \ 1855 user_buf, count, ppos); \ 1856 } \ 1857 1858 #define MVM_DEBUGFS_WRITE_LINK_STA_FILE_OPS(name, bufsz) \ 1859 MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, bufsz) \ 1860 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \ 1861 .write = _iwl_dbgfs_link_sta_##name##_write, \ 1862 .open = simple_open, \ 1863 .llseek = generic_file_llseek, \ 1864 } 1865 1866 #define MVM_DEBUGFS_READ_LINK_STA_FILE_OPS(name) \ 1867 MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \ 1868 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \ 1869 .read = _iwl_dbgfs_link_sta_##name##_read, \ 1870 .open = simple_open, \ 1871 .llseek = generic_file_llseek, \ 1872 } 1873 1874 #define MVM_DEBUGFS_READ_WRITE_LINK_STA_FILE_OPS(name, bufsz) \ 1875 MVM_DEBUGFS_LINK_STA_READ_WRAPPER(name) \ 1876 MVM_DEBUGFS_LINK_STA_WRITE_WRAPPER(name, bufsz) \ 1877 static const struct file_operations iwl_dbgfs_link_sta_##name##_ops = { \ 1878 .read = _iwl_dbgfs_link_sta_##name##_read, \ 1879 .write = _iwl_dbgfs_link_sta_##name##_write, \ 1880 .open = simple_open, \ 1881 .llseek = generic_file_llseek, \ 1882 } 1883 1884 #define MVM_DEBUGFS_ADD_LINK_STA_FILE_ALIAS(alias, name, parent, mode) \ 1885 debugfs_create_file(alias, mode, parent, link_sta, \ 1886 &iwl_dbgfs_link_sta_##name##_ops) 1887 #define MVM_DEBUGFS_ADD_LINK_STA_FILE(name, parent, mode) \ 1888 MVM_DEBUGFS_ADD_LINK_STA_FILE_ALIAS(#name, name, parent, mode) 1889 1890 static ssize_t 1891 iwl_dbgfs_prph_reg_read(struct file *file, 1892 char __user *user_buf, 1893 size_t count, loff_t *ppos) 1894 { 1895 struct iwl_mvm *mvm = file->private_data; 1896 int pos = 0; 1897 char buf[32]; 1898 const size_t bufsz = sizeof(buf); 1899 1900 if (!mvm->dbgfs_prph_reg_addr) 1901 return -EINVAL; 1902 1903 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n", 1904 mvm->dbgfs_prph_reg_addr, 1905 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr)); 1906 1907 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1908 } 1909 1910 static ssize_t 1911 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf, 1912 size_t count, loff_t *ppos) 1913 { 1914 u8 args; 1915 u32 value; 1916 1917 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value); 1918 /* if we only want to set the reg address - nothing more to do */ 1919 if (args == 1) 1920 goto out; 1921 1922 /* otherwise, make sure we have both address and value */ 1923 if (args != 2) 1924 return -EINVAL; 1925 1926 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value); 1927 1928 out: 1929 return count; 1930 } 1931 1932 static ssize_t 1933 iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf, 1934 size_t count, loff_t *ppos) 1935 { 1936 int ret; 1937 1938 if (!iwl_mvm_firmware_running(mvm)) 1939 return -EIO; 1940 1941 mutex_lock(&mvm->mutex); 1942 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1943 mutex_unlock(&mvm->mutex); 1944 1945 return ret ?: count; 1946 } 1947 1948 struct iwl_mvm_sniffer_apply { 1949 struct iwl_mvm *mvm; 1950 u8 *bssid; 1951 u16 aid; 1952 }; 1953 1954 static bool iwl_mvm_sniffer_apply(struct iwl_notif_wait_data *notif_data, 1955 struct iwl_rx_packet *pkt, void *data) 1956 { 1957 struct iwl_mvm_sniffer_apply *apply = data; 1958 1959 apply->mvm->cur_aid = cpu_to_le16(apply->aid); 1960 memcpy(apply->mvm->cur_bssid, apply->bssid, 1961 sizeof(apply->mvm->cur_bssid)); 1962 1963 return true; 1964 } 1965 1966 static ssize_t 1967 iwl_dbgfs_he_sniffer_params_write(struct iwl_mvm *mvm, char *buf, 1968 size_t count, loff_t *ppos) 1969 { 1970 struct iwl_notification_wait wait; 1971 struct iwl_he_monitor_cmd he_mon_cmd = {}; 1972 struct iwl_mvm_sniffer_apply apply = { 1973 .mvm = mvm, 1974 }; 1975 u16 wait_cmds[] = { 1976 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD), 1977 }; 1978 u32 aid; 1979 int ret; 1980 1981 if (!iwl_mvm_firmware_running(mvm)) 1982 return -EIO; 1983 1984 ret = sscanf(buf, "%x %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", &aid, 1985 &he_mon_cmd.bssid[0], &he_mon_cmd.bssid[1], 1986 &he_mon_cmd.bssid[2], &he_mon_cmd.bssid[3], 1987 &he_mon_cmd.bssid[4], &he_mon_cmd.bssid[5]); 1988 if (ret != 7) 1989 return -EINVAL; 1990 1991 he_mon_cmd.aid = cpu_to_le16(aid); 1992 1993 apply.aid = aid; 1994 apply.bssid = (void *)he_mon_cmd.bssid; 1995 1996 mutex_lock(&mvm->mutex); 1997 1998 /* 1999 * Use the notification waiter to get our function triggered 2000 * in sequence with other RX. This ensures that frames we get 2001 * on the RX queue _before_ the new configuration is applied 2002 * still have mvm->cur_aid pointing to the old AID, and that 2003 * frames on the RX queue _after_ the firmware processed the 2004 * new configuration (and sent the response, synchronously) 2005 * get mvm->cur_aid correctly set to the new AID. 2006 */ 2007 iwl_init_notification_wait(&mvm->notif_wait, &wait, 2008 wait_cmds, ARRAY_SIZE(wait_cmds), 2009 iwl_mvm_sniffer_apply, &apply); 2010 2011 ret = iwl_mvm_send_cmd_pdu(mvm, 2012 WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD), 2013 0, 2014 sizeof(he_mon_cmd), &he_mon_cmd); 2015 2016 /* no need to really wait, we already did anyway */ 2017 iwl_remove_notification(&mvm->notif_wait, &wait); 2018 2019 mutex_unlock(&mvm->mutex); 2020 2021 return ret ?: count; 2022 } 2023 2024 static ssize_t 2025 iwl_dbgfs_he_sniffer_params_read(struct file *file, char __user *user_buf, 2026 size_t count, loff_t *ppos) 2027 { 2028 struct iwl_mvm *mvm = file->private_data; 2029 u8 buf[32]; 2030 int len; 2031 2032 len = scnprintf(buf, sizeof(buf), 2033 "%d %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", 2034 le16_to_cpu(mvm->cur_aid), mvm->cur_bssid[0], 2035 mvm->cur_bssid[1], mvm->cur_bssid[2], mvm->cur_bssid[3], 2036 mvm->cur_bssid[4], mvm->cur_bssid[5]); 2037 2038 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 2039 } 2040 2041 static ssize_t 2042 iwl_dbgfs_uapsd_noagg_bssids_read(struct file *file, char __user *user_buf, 2043 size_t count, loff_t *ppos) 2044 { 2045 struct iwl_mvm *mvm = file->private_data; 2046 u8 buf[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM * ETH_ALEN * 3 + 1]; 2047 unsigned int pos = 0; 2048 size_t bufsz = sizeof(buf); 2049 int i; 2050 2051 mutex_lock(&mvm->mutex); 2052 2053 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) 2054 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", 2055 mvm->uapsd_noagg_bssids[i].addr); 2056 2057 mutex_unlock(&mvm->mutex); 2058 2059 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2060 } 2061 2062 static ssize_t 2063 iwl_dbgfs_ltr_config_write(struct iwl_mvm *mvm, 2064 char *buf, size_t count, loff_t *ppos) 2065 { 2066 int ret; 2067 struct iwl_ltr_config_cmd ltr_config = {0}; 2068 2069 if (!iwl_mvm_firmware_running(mvm)) 2070 return -EIO; 2071 2072 if (sscanf(buf, "%x,%x,%x,%x,%x,%x,%x", 2073 <r_config.flags, 2074 <r_config.static_long, 2075 <r_config.static_short, 2076 <r_config.ltr_cfg_values[0], 2077 <r_config.ltr_cfg_values[1], 2078 <r_config.ltr_cfg_values[2], 2079 <r_config.ltr_cfg_values[3]) != 7) { 2080 return -EINVAL; 2081 } 2082 2083 mutex_lock(&mvm->mutex); 2084 ret = iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, sizeof(ltr_config), 2085 <r_config); 2086 mutex_unlock(&mvm->mutex); 2087 2088 if (ret) 2089 IWL_ERR(mvm, "failed to send ltr configuration cmd\n"); 2090 2091 return ret ?: count; 2092 } 2093 2094 static ssize_t iwl_dbgfs_rfi_freq_table_write(struct iwl_mvm *mvm, char *buf, 2095 size_t count, loff_t *ppos) 2096 { 2097 int ret = 0; 2098 u16 op_id; 2099 2100 if (kstrtou16(buf, 10, &op_id)) 2101 return -EINVAL; 2102 2103 /* value zero triggers re-sending the default table to the device */ 2104 if (!op_id) { 2105 mutex_lock(&mvm->mutex); 2106 ret = iwl_rfi_send_config_cmd(mvm, NULL); 2107 mutex_unlock(&mvm->mutex); 2108 } else { 2109 ret = -EOPNOTSUPP; /* in the future a new table will be added */ 2110 } 2111 2112 return ret ?: count; 2113 } 2114 2115 /* The size computation is as follows: 2116 * each number needs at most 3 characters, number of rows is the size of 2117 * the table; So, need 5 chars for the "freq: " part and each tuple afterwards 2118 * needs 6 characters for numbers and 5 for the punctuation around. 2119 */ 2120 #define IWL_RFI_BUF_SIZE (IWL_RFI_LUT_INSTALLED_SIZE *\ 2121 (5 + IWL_RFI_LUT_ENTRY_CHANNELS_NUM * (6 + 5))) 2122 2123 static ssize_t iwl_dbgfs_rfi_freq_table_read(struct file *file, 2124 char __user *user_buf, 2125 size_t count, loff_t *ppos) 2126 { 2127 struct iwl_mvm *mvm = file->private_data; 2128 struct iwl_rfi_freq_table_resp_cmd *resp; 2129 u32 status; 2130 char buf[IWL_RFI_BUF_SIZE]; 2131 int i, j, pos = 0; 2132 2133 resp = iwl_rfi_get_freq_table(mvm); 2134 if (IS_ERR(resp)) 2135 return PTR_ERR(resp); 2136 2137 status = le32_to_cpu(resp->status); 2138 if (status != RFI_FREQ_TABLE_OK) { 2139 scnprintf(buf, IWL_RFI_BUF_SIZE, "status = %d\n", status); 2140 goto out; 2141 } 2142 2143 for (i = 0; i < ARRAY_SIZE(resp->table); i++) { 2144 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, "%d: ", 2145 resp->table[i].freq); 2146 2147 for (j = 0; j < ARRAY_SIZE(resp->table[i].channels); j++) 2148 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, 2149 "(%d, %d) ", 2150 resp->table[i].channels[j], 2151 resp->table[i].bands[j]); 2152 pos += scnprintf(buf + pos, IWL_RFI_BUF_SIZE - pos, "\n"); 2153 } 2154 2155 out: 2156 kfree(resp); 2157 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2158 } 2159 2160 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64); 2161 2162 /* Device wide debugfs entries */ 2163 MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget); 2164 MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8); 2165 MVM_DEBUGFS_WRITE_FILE_OPS(start_ctdp, 8); 2166 MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8); 2167 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16); 2168 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8); 2169 MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8); 2170 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64); 2171 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64); 2172 MVM_DEBUGFS_READ_FILE_OPS(nic_temp); 2173 MVM_DEBUGFS_READ_FILE_OPS(stations); 2174 MVM_DEBUGFS_READ_LINK_STA_FILE_OPS(rs_data); 2175 MVM_DEBUGFS_READ_FILE_OPS(bt_notif); 2176 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd); 2177 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64); 2178 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats); 2179 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats); 2180 MVM_DEBUGFS_READ_FILE_OPS(fw_system_stats); 2181 MVM_DEBUGFS_READ_FILE_OPS(fw_ver); 2182 MVM_DEBUGFS_READ_FILE_OPS(phy_integration_ver); 2183 MVM_DEBUGFS_READ_FILE_OPS(tas_get_status); 2184 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10); 2185 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10); 2186 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10); 2187 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10); 2188 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8); 2189 MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8); 2190 MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64); 2191 MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_clear, 64); 2192 MVM_DEBUGFS_WRITE_FILE_OPS(dbg_time_point, 64); 2193 MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl, 2194 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2)); 2195 MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512); 2196 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie, 512); 2197 MVM_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie_restore, 512); 2198 2199 MVM_DEBUGFS_READ_FILE_OPS(uapsd_noagg_bssids); 2200 2201 #ifdef CONFIG_ACPI 2202 MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile); 2203 MVM_DEBUGFS_READ_FILE_OPS(wifi_6e_enable); 2204 #endif 2205 2206 MVM_DEBUGFS_READ_WRITE_LINK_STA_FILE_OPS(amsdu_len, 16); 2207 2208 MVM_DEBUGFS_READ_WRITE_FILE_OPS(he_sniffer_params, 32); 2209 2210 MVM_DEBUGFS_WRITE_FILE_OPS(ltr_config, 512); 2211 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rfi_freq_table, 16); 2212 2213 static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf, 2214 size_t count, loff_t *ppos) 2215 { 2216 struct iwl_mvm *mvm = file->private_data; 2217 struct iwl_dbg_mem_access_cmd cmd = {}; 2218 struct iwl_dbg_mem_access_rsp *rsp; 2219 struct iwl_host_cmd hcmd = { 2220 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL, 2221 .data = { &cmd, }, 2222 .len = { sizeof(cmd) }, 2223 }; 2224 size_t delta; 2225 ssize_t ret, len; 2226 2227 if (!iwl_mvm_firmware_running(mvm)) 2228 return -EIO; 2229 2230 hcmd.id = WIDE_ID(DEBUG_GROUP, *ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR); 2231 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ); 2232 2233 /* Take care of alignment of both the position and the length */ 2234 delta = *ppos & 0x3; 2235 cmd.addr = cpu_to_le32(*ppos - delta); 2236 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4, 2237 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS)); 2238 2239 mutex_lock(&mvm->mutex); 2240 ret = iwl_mvm_send_cmd(mvm, &hcmd); 2241 mutex_unlock(&mvm->mutex); 2242 2243 if (ret < 0) 2244 return ret; 2245 2246 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) { 2247 ret = -EIO; 2248 goto out; 2249 } 2250 2251 rsp = (void *)hcmd.resp_pkt->data; 2252 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) { 2253 ret = -ENXIO; 2254 goto out; 2255 } 2256 2257 len = min((size_t)le32_to_cpu(rsp->len) << 2, 2258 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp)); 2259 len = min(len - delta, count); 2260 if (len < 0) { 2261 ret = -EFAULT; 2262 goto out; 2263 } 2264 2265 ret = len - copy_to_user(user_buf, (u8 *)rsp->data + delta, len); 2266 *ppos += ret; 2267 2268 out: 2269 iwl_free_resp(&hcmd); 2270 return ret; 2271 } 2272 2273 static ssize_t iwl_dbgfs_mem_write(struct file *file, 2274 const char __user *user_buf, size_t count, 2275 loff_t *ppos) 2276 { 2277 struct iwl_mvm *mvm = file->private_data; 2278 struct iwl_dbg_mem_access_cmd *cmd; 2279 struct iwl_dbg_mem_access_rsp *rsp; 2280 struct iwl_host_cmd hcmd = {}; 2281 size_t cmd_size; 2282 size_t data_size; 2283 u32 op, len; 2284 ssize_t ret; 2285 2286 if (!iwl_mvm_firmware_running(mvm)) 2287 return -EIO; 2288 2289 hcmd.id = WIDE_ID(DEBUG_GROUP, *ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR); 2290 2291 if (*ppos & 0x3 || count < 4) { 2292 op = DEBUG_MEM_OP_WRITE_BYTES; 2293 len = min(count, (size_t)(4 - (*ppos & 0x3))); 2294 data_size = len; 2295 } else { 2296 op = DEBUG_MEM_OP_WRITE; 2297 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS); 2298 data_size = len << 2; 2299 } 2300 2301 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4); 2302 cmd = kzalloc(cmd_size, GFP_KERNEL); 2303 if (!cmd) 2304 return -ENOMEM; 2305 2306 cmd->op = cpu_to_le32(op); 2307 cmd->len = cpu_to_le32(len); 2308 cmd->addr = cpu_to_le32(*ppos); 2309 if (copy_from_user((void *)cmd->data, user_buf, data_size)) { 2310 kfree(cmd); 2311 return -EFAULT; 2312 } 2313 2314 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL, 2315 hcmd.data[0] = (void *)cmd; 2316 hcmd.len[0] = cmd_size; 2317 2318 mutex_lock(&mvm->mutex); 2319 ret = iwl_mvm_send_cmd(mvm, &hcmd); 2320 mutex_unlock(&mvm->mutex); 2321 2322 kfree(cmd); 2323 2324 if (ret < 0) 2325 return ret; 2326 2327 if (iwl_rx_packet_payload_len(hcmd.resp_pkt) < sizeof(*rsp)) { 2328 ret = -EIO; 2329 goto out; 2330 } 2331 2332 rsp = (void *)hcmd.resp_pkt->data; 2333 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) { 2334 ret = -ENXIO; 2335 goto out; 2336 } 2337 2338 ret = data_size; 2339 *ppos += ret; 2340 2341 out: 2342 iwl_free_resp(&hcmd); 2343 return ret; 2344 } 2345 2346 static const struct file_operations iwl_dbgfs_mem_ops = { 2347 .read = iwl_dbgfs_mem_read, 2348 .write = iwl_dbgfs_mem_write, 2349 .open = simple_open, 2350 .llseek = default_llseek, 2351 }; 2352 2353 void iwl_mvm_link_sta_add_debugfs(struct ieee80211_hw *hw, 2354 struct ieee80211_vif *vif, 2355 struct ieee80211_link_sta *link_sta, 2356 struct dentry *dir) 2357 { 2358 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2359 2360 if (iwl_mvm_has_tlc_offload(mvm)) { 2361 MVM_DEBUGFS_ADD_LINK_STA_FILE(rs_data, dir, 0400); 2362 } 2363 2364 MVM_DEBUGFS_ADD_LINK_STA_FILE(amsdu_len, dir, 0600); 2365 } 2366 2367 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm) 2368 { 2369 struct dentry *bcast_dir __maybe_unused; 2370 2371 spin_lock_init(&mvm->drv_stats_lock); 2372 2373 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, 0200); 2374 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, 0200); 2375 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, 0600); 2376 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, 0600); 2377 MVM_DEBUGFS_ADD_FILE(nic_temp, mvm->debugfs_dir, 0400); 2378 MVM_DEBUGFS_ADD_FILE(ctdp_budget, mvm->debugfs_dir, 0400); 2379 MVM_DEBUGFS_ADD_FILE(stop_ctdp, mvm->debugfs_dir, 0200); 2380 MVM_DEBUGFS_ADD_FILE(start_ctdp, mvm->debugfs_dir, 0200); 2381 MVM_DEBUGFS_ADD_FILE(force_ctkill, mvm->debugfs_dir, 0200); 2382 MVM_DEBUGFS_ADD_FILE(stations, mvm->debugfs_dir, 0400); 2383 MVM_DEBUGFS_ADD_FILE(bt_notif, mvm->debugfs_dir, 0400); 2384 MVM_DEBUGFS_ADD_FILE(bt_cmd, mvm->debugfs_dir, 0400); 2385 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, 0600); 2386 MVM_DEBUGFS_ADD_FILE(fw_ver, mvm->debugfs_dir, 0400); 2387 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, 0400); 2388 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, 0400); 2389 MVM_DEBUGFS_ADD_FILE(fw_system_stats, mvm->debugfs_dir, 0400); 2390 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, 0200); 2391 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, 0200); 2392 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, 0200); 2393 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, 0200); 2394 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, 0600); 2395 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, 0600); 2396 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, 0600); 2397 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, 0200); 2398 MVM_DEBUGFS_ADD_FILE(fw_dbg_clear, mvm->debugfs_dir, 0200); 2399 MVM_DEBUGFS_ADD_FILE(dbg_time_point, mvm->debugfs_dir, 0200); 2400 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, 0200); 2401 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, 0200); 2402 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, 0200); 2403 MVM_DEBUGFS_ADD_FILE(inject_beacon_ie, mvm->debugfs_dir, 0200); 2404 MVM_DEBUGFS_ADD_FILE(inject_beacon_ie_restore, mvm->debugfs_dir, 0200); 2405 MVM_DEBUGFS_ADD_FILE(rfi_freq_table, mvm->debugfs_dir, 0600); 2406 2407 if (mvm->fw->phy_integration_ver) 2408 MVM_DEBUGFS_ADD_FILE(phy_integration_ver, mvm->debugfs_dir, 0400); 2409 MVM_DEBUGFS_ADD_FILE(tas_get_status, mvm->debugfs_dir, 0400); 2410 #ifdef CONFIG_ACPI 2411 MVM_DEBUGFS_ADD_FILE(sar_geo_profile, mvm->debugfs_dir, 0400); 2412 MVM_DEBUGFS_ADD_FILE(wifi_6e_enable, mvm->debugfs_dir, 0400); 2413 #endif 2414 MVM_DEBUGFS_ADD_FILE(he_sniffer_params, mvm->debugfs_dir, 0600); 2415 2416 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2)) 2417 MVM_DEBUGFS_ADD_FILE(ltr_config, mvm->debugfs_dir, 0200); 2418 2419 debugfs_create_bool("enable_scan_iteration_notif", 0600, 2420 mvm->debugfs_dir, &mvm->scan_iter_notif_enabled); 2421 debugfs_create_bool("drop_bcn_ap_mode", 0600, mvm->debugfs_dir, 2422 &mvm->drop_bcn_ap_mode); 2423 2424 MVM_DEBUGFS_ADD_FILE(uapsd_noagg_bssids, mvm->debugfs_dir, S_IRUSR); 2425 2426 #ifdef CONFIG_PM_SLEEP 2427 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, 0400); 2428 debugfs_create_bool("d3_wake_sysassert", 0600, mvm->debugfs_dir, 2429 &mvm->d3_wake_sysassert); 2430 debugfs_create_u32("last_netdetect_scans", 0400, mvm->debugfs_dir, 2431 &mvm->last_netdetect_scans); 2432 #endif 2433 2434 debugfs_create_u8("ps_disabled", 0400, mvm->debugfs_dir, 2435 &mvm->ps_disabled); 2436 debugfs_create_blob("nvm_hw", 0400, mvm->debugfs_dir, 2437 &mvm->nvm_hw_blob); 2438 debugfs_create_blob("nvm_sw", 0400, mvm->debugfs_dir, 2439 &mvm->nvm_sw_blob); 2440 debugfs_create_blob("nvm_calib", 0400, mvm->debugfs_dir, 2441 &mvm->nvm_calib_blob); 2442 debugfs_create_blob("nvm_prod", 0400, mvm->debugfs_dir, 2443 &mvm->nvm_prod_blob); 2444 debugfs_create_blob("nvm_phy_sku", 0400, mvm->debugfs_dir, 2445 &mvm->nvm_phy_sku_blob); 2446 debugfs_create_blob("nvm_reg", S_IRUSR, 2447 mvm->debugfs_dir, &mvm->nvm_reg_blob); 2448 2449 debugfs_create_file("mem", 0600, mvm->debugfs_dir, mvm, 2450 &iwl_dbgfs_mem_ops); 2451 2452 debugfs_create_bool("rx_ts_ptp", 0600, mvm->debugfs_dir, 2453 &mvm->rx_ts_ptp); 2454 2455 /* 2456 * Create a symlink with mac80211. It will be removed when mac80211 2457 * exists (before the opmode exists which removes the target.) 2458 */ 2459 if (!IS_ERR(mvm->debugfs_dir)) { 2460 char buf[100]; 2461 2462 snprintf(buf, 100, "../../%pd2", mvm->debugfs_dir->d_parent); 2463 debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, 2464 buf); 2465 } 2466 } 2467