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