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