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