1 /****************************************************************************** 2 * 3 * GPL LICENSE SUMMARY 4 * 5 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of version 2 of the GNU General Public License as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 19 * USA 20 * 21 * The full GNU General Public License is included in this distribution 22 * in the file called COPYING. 23 * 24 * Contact Information: 25 * Intel Linux Wireless <linuxwifi@intel.com> 26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 27 *****************************************************************************/ 28 29 #include <linux/slab.h> 30 #include <linux/kernel.h> 31 #include <linux/module.h> 32 #include <linux/debugfs.h> 33 #include <linux/ieee80211.h> 34 #include <net/mac80211.h> 35 36 #include "iwl-debug.h" 37 #include "iwl-trans.h" 38 #include "iwl-io.h" 39 #include "dev.h" 40 #include "agn.h" 41 42 /* create and remove of files */ 43 #define DEBUGFS_ADD_FILE(name, parent, mode) do { \ 44 if (!debugfs_create_file(#name, mode, parent, priv, \ 45 &iwl_dbgfs_##name##_ops)) \ 46 goto err; \ 47 } while (0) 48 49 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \ 50 struct dentry *__tmp; \ 51 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \ 52 parent, ptr); \ 53 if (IS_ERR(__tmp) || !__tmp) \ 54 goto err; \ 55 } while (0) 56 57 #define DEBUGFS_ADD_X32(name, parent, ptr) do { \ 58 struct dentry *__tmp; \ 59 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \ 60 parent, ptr); \ 61 if (IS_ERR(__tmp) || !__tmp) \ 62 goto err; \ 63 } while (0) 64 65 #define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \ 66 struct dentry *__tmp; \ 67 __tmp = debugfs_create_u32(#name, mode, \ 68 parent, ptr); \ 69 if (IS_ERR(__tmp) || !__tmp) \ 70 goto err; \ 71 } while (0) 72 73 /* file operation */ 74 #define DEBUGFS_READ_FILE_OPS(name) \ 75 static const struct file_operations iwl_dbgfs_##name##_ops = { \ 76 .read = iwl_dbgfs_##name##_read, \ 77 .open = simple_open, \ 78 .llseek = generic_file_llseek, \ 79 }; 80 81 #define DEBUGFS_WRITE_FILE_OPS(name) \ 82 static const struct file_operations iwl_dbgfs_##name##_ops = { \ 83 .write = iwl_dbgfs_##name##_write, \ 84 .open = simple_open, \ 85 .llseek = generic_file_llseek, \ 86 }; 87 88 89 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \ 90 static const struct file_operations iwl_dbgfs_##name##_ops = { \ 91 .write = iwl_dbgfs_##name##_write, \ 92 .read = iwl_dbgfs_##name##_read, \ 93 .open = simple_open, \ 94 .llseek = generic_file_llseek, \ 95 }; 96 97 static ssize_t iwl_dbgfs_sram_read(struct file *file, 98 char __user *user_buf, 99 size_t count, loff_t *ppos) 100 { 101 u32 val = 0; 102 char *buf; 103 ssize_t ret; 104 int i = 0; 105 bool device_format = false; 106 int offset = 0; 107 int len = 0; 108 int pos = 0; 109 int sram; 110 struct iwl_priv *priv = file->private_data; 111 const struct fw_img *img; 112 size_t bufsz; 113 114 if (!iwl_is_ready_rf(priv)) 115 return -EAGAIN; 116 117 /* default is to dump the entire data segment */ 118 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { 119 priv->dbgfs_sram_offset = 0x800000; 120 if (!priv->ucode_loaded) 121 return -EINVAL; 122 img = &priv->fw->img[priv->cur_ucode]; 123 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len; 124 } 125 len = priv->dbgfs_sram_len; 126 127 if (len == -4) { 128 device_format = true; 129 len = 4; 130 } 131 132 bufsz = 50 + len * 4; 133 buf = kmalloc(bufsz, GFP_KERNEL); 134 if (!buf) 135 return -ENOMEM; 136 137 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", 138 len); 139 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", 140 priv->dbgfs_sram_offset); 141 142 /* adjust sram address since reads are only on even u32 boundaries */ 143 offset = priv->dbgfs_sram_offset & 0x3; 144 sram = priv->dbgfs_sram_offset & ~0x3; 145 146 /* read the first u32 from sram */ 147 val = iwl_trans_read_mem32(priv->trans, sram); 148 149 for (; len; len--) { 150 /* put the address at the start of every line */ 151 if (i == 0) 152 pos += scnprintf(buf + pos, bufsz - pos, 153 "%08X: ", sram + offset); 154 155 if (device_format) 156 pos += scnprintf(buf + pos, bufsz - pos, 157 "%02x", (val >> (8 * (3 - offset))) & 0xff); 158 else 159 pos += scnprintf(buf + pos, bufsz - pos, 160 "%02x ", (val >> (8 * offset)) & 0xff); 161 162 /* if all bytes processed, read the next u32 from sram */ 163 if (++offset == 4) { 164 sram += 4; 165 offset = 0; 166 val = iwl_trans_read_mem32(priv->trans, sram); 167 } 168 169 /* put in extra spaces and split lines for human readability */ 170 if (++i == 16) { 171 i = 0; 172 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 173 } else if (!(i & 7)) { 174 pos += scnprintf(buf + pos, bufsz - pos, " "); 175 } else if (!(i & 3)) { 176 pos += scnprintf(buf + pos, bufsz - pos, " "); 177 } 178 } 179 if (i) 180 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 181 182 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 183 kfree(buf); 184 return ret; 185 } 186 187 static ssize_t iwl_dbgfs_sram_write(struct file *file, 188 const char __user *user_buf, 189 size_t count, loff_t *ppos) 190 { 191 struct iwl_priv *priv = file->private_data; 192 char buf[64]; 193 int buf_size; 194 u32 offset, len; 195 196 memset(buf, 0, sizeof(buf)); 197 buf_size = min(count, sizeof(buf) - 1); 198 if (copy_from_user(buf, user_buf, buf_size)) 199 return -EFAULT; 200 201 if (sscanf(buf, "%x,%x", &offset, &len) == 2) { 202 priv->dbgfs_sram_offset = offset; 203 priv->dbgfs_sram_len = len; 204 } else if (sscanf(buf, "%x", &offset) == 1) { 205 priv->dbgfs_sram_offset = offset; 206 priv->dbgfs_sram_len = -4; 207 } else { 208 priv->dbgfs_sram_offset = 0; 209 priv->dbgfs_sram_len = 0; 210 } 211 212 return count; 213 } 214 215 static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file, 216 char __user *user_buf, 217 size_t count, loff_t *ppos) 218 { 219 struct iwl_priv *priv = file->private_data; 220 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN]; 221 222 if (!priv->wowlan_sram) 223 return -ENODATA; 224 225 return simple_read_from_buffer(user_buf, count, ppos, 226 priv->wowlan_sram, 227 img->sec[IWL_UCODE_SECTION_DATA].len); 228 } 229 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, 230 size_t count, loff_t *ppos) 231 { 232 struct iwl_priv *priv = file->private_data; 233 struct iwl_station_entry *station; 234 struct iwl_tid_data *tid_data; 235 char *buf; 236 int i, j, pos = 0; 237 ssize_t ret; 238 /* Add 30 for initial string */ 239 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations); 240 241 buf = kmalloc(bufsz, GFP_KERNEL); 242 if (!buf) 243 return -ENOMEM; 244 245 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n", 246 priv->num_stations); 247 248 for (i = 0; i < IWLAGN_STATION_COUNT; i++) { 249 station = &priv->stations[i]; 250 if (!station->used) 251 continue; 252 pos += scnprintf(buf + pos, bufsz - pos, 253 "station %d - addr: %pM, flags: %#x\n", 254 i, station->sta.sta.addr, 255 station->sta.station_flags_msk); 256 pos += scnprintf(buf + pos, bufsz - pos, 257 "TID seqno next_rclmd " 258 "rate_n_flags state txq\n"); 259 260 for (j = 0; j < IWL_MAX_TID_COUNT; j++) { 261 tid_data = &priv->tid_data[i][j]; 262 pos += scnprintf(buf + pos, bufsz - pos, 263 "%d: 0x%.4x 0x%.4x 0x%.8x " 264 "%d %.2d", 265 j, tid_data->seq_number, 266 tid_data->next_reclaimed, 267 tid_data->agg.rate_n_flags, 268 tid_data->agg.state, 269 tid_data->agg.txq_id); 270 271 if (tid_data->agg.wait_for_ba) 272 pos += scnprintf(buf + pos, bufsz - pos, 273 " - waitforba"); 274 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 275 } 276 277 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 278 } 279 280 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 281 kfree(buf); 282 return ret; 283 } 284 285 static ssize_t iwl_dbgfs_nvm_read(struct file *file, 286 char __user *user_buf, 287 size_t count, 288 loff_t *ppos) 289 { 290 ssize_t ret; 291 struct iwl_priv *priv = file->private_data; 292 int pos = 0, ofs = 0, buf_size = 0; 293 const u8 *ptr; 294 char *buf; 295 u16 nvm_ver; 296 size_t eeprom_len = priv->eeprom_blob_size; 297 buf_size = 4 * eeprom_len + 256; 298 299 if (eeprom_len % 16) 300 return -ENODATA; 301 302 ptr = priv->eeprom_blob; 303 if (!ptr) 304 return -ENOMEM; 305 306 /* 4 characters for byte 0xYY */ 307 buf = kzalloc(buf_size, GFP_KERNEL); 308 if (!buf) 309 return -ENOMEM; 310 311 nvm_ver = priv->nvm_data->nvm_version; 312 pos += scnprintf(buf + pos, buf_size - pos, 313 "NVM version: 0x%x\n", nvm_ver); 314 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) { 315 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n", 316 ofs, ptr + ofs); 317 } 318 319 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 320 kfree(buf); 321 return ret; 322 } 323 324 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf, 325 size_t count, loff_t *ppos) 326 { 327 struct iwl_priv *priv = file->private_data; 328 struct ieee80211_channel *channels = NULL; 329 const struct ieee80211_supported_band *supp_band = NULL; 330 int pos = 0, i, bufsz = PAGE_SIZE; 331 char *buf; 332 ssize_t ret; 333 334 buf = kzalloc(bufsz, GFP_KERNEL); 335 if (!buf) 336 return -ENOMEM; 337 338 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_2GHZ); 339 if (supp_band) { 340 channels = supp_band->channels; 341 342 pos += scnprintf(buf + pos, bufsz - pos, 343 "Displaying %d channels in 2.4GHz band 802.11bg):\n", 344 supp_band->n_channels); 345 346 for (i = 0; i < supp_band->n_channels; i++) 347 pos += scnprintf(buf + pos, bufsz - pos, 348 "%d: %ddBm: BSS%s%s, %s.\n", 349 channels[i].hw_value, 350 channels[i].max_power, 351 channels[i].flags & IEEE80211_CHAN_RADAR ? 352 " (IEEE 802.11h required)" : "", 353 ((channels[i].flags & IEEE80211_CHAN_NO_IR) 354 || (channels[i].flags & 355 IEEE80211_CHAN_RADAR)) ? "" : 356 ", IBSS", 357 channels[i].flags & 358 IEEE80211_CHAN_NO_IR ? 359 "passive only" : "active/passive"); 360 } 361 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_5GHZ); 362 if (supp_band) { 363 channels = supp_band->channels; 364 365 pos += scnprintf(buf + pos, bufsz - pos, 366 "Displaying %d channels in 5.2GHz band (802.11a)\n", 367 supp_band->n_channels); 368 369 for (i = 0; i < supp_band->n_channels; i++) 370 pos += scnprintf(buf + pos, bufsz - pos, 371 "%d: %ddBm: BSS%s%s, %s.\n", 372 channels[i].hw_value, 373 channels[i].max_power, 374 channels[i].flags & IEEE80211_CHAN_RADAR ? 375 " (IEEE 802.11h required)" : "", 376 ((channels[i].flags & IEEE80211_CHAN_NO_IR) 377 || (channels[i].flags & 378 IEEE80211_CHAN_RADAR)) ? "" : 379 ", IBSS", 380 channels[i].flags & 381 IEEE80211_CHAN_NO_IR ? 382 "passive only" : "active/passive"); 383 } 384 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 385 kfree(buf); 386 return ret; 387 } 388 389 static ssize_t iwl_dbgfs_status_read(struct file *file, 390 char __user *user_buf, 391 size_t count, loff_t *ppos) { 392 393 struct iwl_priv *priv = file->private_data; 394 char buf[512]; 395 int pos = 0; 396 const size_t bufsz = sizeof(buf); 397 398 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n", 399 test_bit(STATUS_RF_KILL_HW, &priv->status)); 400 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n", 401 test_bit(STATUS_CT_KILL, &priv->status)); 402 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n", 403 test_bit(STATUS_ALIVE, &priv->status)); 404 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n", 405 test_bit(STATUS_READY, &priv->status)); 406 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", 407 test_bit(STATUS_EXIT_PENDING, &priv->status)); 408 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", 409 test_bit(STATUS_STATISTICS, &priv->status)); 410 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n", 411 test_bit(STATUS_SCANNING, &priv->status)); 412 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n", 413 test_bit(STATUS_SCAN_ABORTING, &priv->status)); 414 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n", 415 test_bit(STATUS_SCAN_HW, &priv->status)); 416 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n", 417 test_bit(STATUS_POWER_PMI, &priv->status)); 418 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n", 419 test_bit(STATUS_FW_ERROR, &priv->status)); 420 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 421 } 422 423 static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file, 424 char __user *user_buf, 425 size_t count, loff_t *ppos) { 426 427 struct iwl_priv *priv = file->private_data; 428 429 int pos = 0; 430 int cnt = 0; 431 char *buf; 432 int bufsz = 24 * 64; /* 24 items * 64 char per item */ 433 ssize_t ret; 434 435 buf = kzalloc(bufsz, GFP_KERNEL); 436 if (!buf) 437 return -ENOMEM; 438 439 for (cnt = 0; cnt < REPLY_MAX; cnt++) { 440 if (priv->rx_handlers_stats[cnt] > 0) 441 pos += scnprintf(buf + pos, bufsz - pos, 442 "\tRx handler[%36s]:\t\t %u\n", 443 iwl_get_cmd_string(priv->trans, (u32)cnt), 444 priv->rx_handlers_stats[cnt]); 445 } 446 447 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 448 kfree(buf); 449 return ret; 450 } 451 452 static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file, 453 const char __user *user_buf, 454 size_t count, loff_t *ppos) 455 { 456 struct iwl_priv *priv = file->private_data; 457 458 char buf[8]; 459 int buf_size; 460 u32 reset_flag; 461 462 memset(buf, 0, sizeof(buf)); 463 buf_size = min(count, sizeof(buf) - 1); 464 if (copy_from_user(buf, user_buf, buf_size)) 465 return -EFAULT; 466 if (sscanf(buf, "%x", &reset_flag) != 1) 467 return -EFAULT; 468 if (reset_flag == 0) 469 memset(&priv->rx_handlers_stats[0], 0, 470 sizeof(priv->rx_handlers_stats)); 471 472 return count; 473 } 474 475 static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf, 476 size_t count, loff_t *ppos) 477 { 478 struct iwl_priv *priv = file->private_data; 479 struct iwl_rxon_context *ctx; 480 int pos = 0, i; 481 char buf[256 * NUM_IWL_RXON_CTX]; 482 const size_t bufsz = sizeof(buf); 483 484 for_each_context(priv, ctx) { 485 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n", 486 ctx->ctxid); 487 for (i = 0; i < AC_NUM; i++) { 488 pos += scnprintf(buf + pos, bufsz - pos, 489 "\tcw_min\tcw_max\taifsn\ttxop\n"); 490 pos += scnprintf(buf + pos, bufsz - pos, 491 "AC[%d]\t%u\t%u\t%u\t%u\n", i, 492 ctx->qos_data.def_qos_parm.ac[i].cw_min, 493 ctx->qos_data.def_qos_parm.ac[i].cw_max, 494 ctx->qos_data.def_qos_parm.ac[i].aifsn, 495 ctx->qos_data.def_qos_parm.ac[i].edca_txop); 496 } 497 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 498 } 499 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 500 } 501 502 static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file, 503 char __user *user_buf, 504 size_t count, loff_t *ppos) 505 { 506 struct iwl_priv *priv = file->private_data; 507 struct iwl_tt_mgmt *tt = &priv->thermal_throttle; 508 struct iwl_tt_restriction *restriction; 509 char buf[100]; 510 int pos = 0; 511 const size_t bufsz = sizeof(buf); 512 513 pos += scnprintf(buf + pos, bufsz - pos, 514 "Thermal Throttling Mode: %s\n", 515 tt->advanced_tt ? "Advance" : "Legacy"); 516 pos += scnprintf(buf + pos, bufsz - pos, 517 "Thermal Throttling State: %d\n", 518 tt->state); 519 if (tt->advanced_tt) { 520 restriction = tt->restriction + tt->state; 521 pos += scnprintf(buf + pos, bufsz - pos, 522 "Tx mode: %d\n", 523 restriction->tx_stream); 524 pos += scnprintf(buf + pos, bufsz - pos, 525 "Rx mode: %d\n", 526 restriction->rx_stream); 527 pos += scnprintf(buf + pos, bufsz - pos, 528 "HT mode: %d\n", 529 restriction->is_ht); 530 } 531 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 532 } 533 534 static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file, 535 const char __user *user_buf, 536 size_t count, loff_t *ppos) 537 { 538 struct iwl_priv *priv = file->private_data; 539 char buf[8]; 540 int buf_size; 541 int ht40; 542 543 memset(buf, 0, sizeof(buf)); 544 buf_size = min(count, sizeof(buf) - 1); 545 if (copy_from_user(buf, user_buf, buf_size)) 546 return -EFAULT; 547 if (sscanf(buf, "%d", &ht40) != 1) 548 return -EFAULT; 549 if (!iwl_is_any_associated(priv)) 550 priv->disable_ht40 = ht40 ? true : false; 551 else 552 return -EINVAL; 553 554 return count; 555 } 556 557 static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file, 558 char __user *user_buf, 559 size_t count, loff_t *ppos) 560 { 561 struct iwl_priv *priv = file->private_data; 562 char buf[100]; 563 int pos = 0; 564 const size_t bufsz = sizeof(buf); 565 566 pos += scnprintf(buf + pos, bufsz - pos, 567 "11n 40MHz Mode: %s\n", 568 priv->disable_ht40 ? "Disabled" : "Enabled"); 569 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 570 } 571 572 static ssize_t iwl_dbgfs_temperature_read(struct file *file, 573 char __user *user_buf, 574 size_t count, loff_t *ppos) 575 { 576 struct iwl_priv *priv = file->private_data; 577 char buf[8]; 578 int pos = 0; 579 const size_t bufsz = sizeof(buf); 580 581 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature); 582 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 583 } 584 585 586 static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file, 587 const char __user *user_buf, 588 size_t count, loff_t *ppos) 589 { 590 struct iwl_priv *priv = file->private_data; 591 char buf[8]; 592 int buf_size; 593 int value; 594 595 memset(buf, 0, sizeof(buf)); 596 buf_size = min(count, sizeof(buf) - 1); 597 if (copy_from_user(buf, user_buf, buf_size)) 598 return -EFAULT; 599 600 if (sscanf(buf, "%d", &value) != 1) 601 return -EINVAL; 602 603 /* 604 * Our users expect 0 to be "CAM", but 0 isn't actually 605 * valid here. However, let's not confuse them and present 606 * IWL_POWER_INDEX_1 as "1", not "0". 607 */ 608 if (value == 0) 609 return -EINVAL; 610 else if (value > 0) 611 value -= 1; 612 613 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM)) 614 return -EINVAL; 615 616 if (!iwl_is_ready_rf(priv)) 617 return -EAGAIN; 618 619 priv->power_data.debug_sleep_level_override = value; 620 621 mutex_lock(&priv->mutex); 622 iwl_power_update_mode(priv, true); 623 mutex_unlock(&priv->mutex); 624 625 return count; 626 } 627 628 static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file, 629 char __user *user_buf, 630 size_t count, loff_t *ppos) 631 { 632 struct iwl_priv *priv = file->private_data; 633 char buf[10]; 634 int pos, value; 635 const size_t bufsz = sizeof(buf); 636 637 /* see the write function */ 638 value = priv->power_data.debug_sleep_level_override; 639 if (value >= 0) 640 value += 1; 641 642 pos = scnprintf(buf, bufsz, "%d\n", value); 643 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 644 } 645 646 static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file, 647 char __user *user_buf, 648 size_t count, loff_t *ppos) 649 { 650 struct iwl_priv *priv = file->private_data; 651 char buf[200]; 652 int pos = 0, i; 653 const size_t bufsz = sizeof(buf); 654 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd; 655 656 pos += scnprintf(buf + pos, bufsz - pos, 657 "flags: %#.2x\n", le16_to_cpu(cmd->flags)); 658 pos += scnprintf(buf + pos, bufsz - pos, 659 "RX/TX timeout: %d/%d usec\n", 660 le32_to_cpu(cmd->rx_data_timeout), 661 le32_to_cpu(cmd->tx_data_timeout)); 662 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) 663 pos += scnprintf(buf + pos, bufsz - pos, 664 "sleep_interval[%d]: %d\n", i, 665 le32_to_cpu(cmd->sleep_interval[i])); 666 667 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 668 } 669 670 DEBUGFS_READ_WRITE_FILE_OPS(sram); 671 DEBUGFS_READ_FILE_OPS(wowlan_sram); 672 DEBUGFS_READ_FILE_OPS(nvm); 673 DEBUGFS_READ_FILE_OPS(stations); 674 DEBUGFS_READ_FILE_OPS(channels); 675 DEBUGFS_READ_FILE_OPS(status); 676 DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers); 677 DEBUGFS_READ_FILE_OPS(qos); 678 DEBUGFS_READ_FILE_OPS(thermal_throttling); 679 DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40); 680 DEBUGFS_READ_FILE_OPS(temperature); 681 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override); 682 DEBUGFS_READ_FILE_OPS(current_sleep_command); 683 684 static const char *fmt_value = " %-30s %10u\n"; 685 static const char *fmt_hex = " %-30s 0x%02X\n"; 686 static const char *fmt_table = " %-30s %10u %10u %10u %10u\n"; 687 static const char *fmt_header = 688 "%-32s current cumulative delta max\n"; 689 690 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz) 691 { 692 int p = 0; 693 u32 flag; 694 695 lockdep_assert_held(&priv->statistics.lock); 696 697 flag = le32_to_cpu(priv->statistics.flag); 698 699 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag); 700 if (flag & UCODE_STATISTICS_CLEAR_MSK) 701 p += scnprintf(buf + p, bufsz - p, 702 "\tStatistics have been cleared\n"); 703 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n", 704 (flag & UCODE_STATISTICS_FREQUENCY_MSK) 705 ? "2.4 GHz" : "5.2 GHz"); 706 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n", 707 (flag & UCODE_STATISTICS_NARROW_BAND_MSK) 708 ? "enabled" : "disabled"); 709 710 return p; 711 } 712 713 static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file, 714 char __user *user_buf, 715 size_t count, loff_t *ppos) 716 { 717 struct iwl_priv *priv = file->private_data; 718 int pos = 0; 719 char *buf; 720 int bufsz = sizeof(struct statistics_rx_phy) * 40 + 721 sizeof(struct statistics_rx_non_phy) * 40 + 722 sizeof(struct statistics_rx_ht_phy) * 40 + 400; 723 ssize_t ret; 724 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm; 725 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck; 726 struct statistics_rx_non_phy *general, *accum_general; 727 struct statistics_rx_non_phy *delta_general, *max_general; 728 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht; 729 730 if (!iwl_is_alive(priv)) 731 return -EAGAIN; 732 733 buf = kzalloc(bufsz, GFP_KERNEL); 734 if (!buf) 735 return -ENOMEM; 736 737 /* 738 * the statistic information display here is based on 739 * the last statistics notification from uCode 740 * might not reflect the current uCode activity 741 */ 742 spin_lock_bh(&priv->statistics.lock); 743 ofdm = &priv->statistics.rx_ofdm; 744 cck = &priv->statistics.rx_cck; 745 general = &priv->statistics.rx_non_phy; 746 ht = &priv->statistics.rx_ofdm_ht; 747 accum_ofdm = &priv->accum_stats.rx_ofdm; 748 accum_cck = &priv->accum_stats.rx_cck; 749 accum_general = &priv->accum_stats.rx_non_phy; 750 accum_ht = &priv->accum_stats.rx_ofdm_ht; 751 delta_ofdm = &priv->delta_stats.rx_ofdm; 752 delta_cck = &priv->delta_stats.rx_cck; 753 delta_general = &priv->delta_stats.rx_non_phy; 754 delta_ht = &priv->delta_stats.rx_ofdm_ht; 755 max_ofdm = &priv->max_delta_stats.rx_ofdm; 756 max_cck = &priv->max_delta_stats.rx_cck; 757 max_general = &priv->max_delta_stats.rx_non_phy; 758 max_ht = &priv->max_delta_stats.rx_ofdm_ht; 759 760 pos += iwl_statistics_flag(priv, buf, bufsz); 761 pos += scnprintf(buf + pos, bufsz - pos, 762 fmt_header, "Statistics_Rx - OFDM:"); 763 pos += scnprintf(buf + pos, bufsz - pos, 764 fmt_table, "ina_cnt:", 765 le32_to_cpu(ofdm->ina_cnt), 766 accum_ofdm->ina_cnt, 767 delta_ofdm->ina_cnt, max_ofdm->ina_cnt); 768 pos += scnprintf(buf + pos, bufsz - pos, 769 fmt_table, "fina_cnt:", 770 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt, 771 delta_ofdm->fina_cnt, max_ofdm->fina_cnt); 772 pos += scnprintf(buf + pos, bufsz - pos, 773 fmt_table, "plcp_err:", 774 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err, 775 delta_ofdm->plcp_err, max_ofdm->plcp_err); 776 pos += scnprintf(buf + pos, bufsz - pos, 777 fmt_table, "crc32_err:", 778 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err, 779 delta_ofdm->crc32_err, max_ofdm->crc32_err); 780 pos += scnprintf(buf + pos, bufsz - pos, 781 fmt_table, "overrun_err:", 782 le32_to_cpu(ofdm->overrun_err), 783 accum_ofdm->overrun_err, delta_ofdm->overrun_err, 784 max_ofdm->overrun_err); 785 pos += scnprintf(buf + pos, bufsz - pos, 786 fmt_table, "early_overrun_err:", 787 le32_to_cpu(ofdm->early_overrun_err), 788 accum_ofdm->early_overrun_err, 789 delta_ofdm->early_overrun_err, 790 max_ofdm->early_overrun_err); 791 pos += scnprintf(buf + pos, bufsz - pos, 792 fmt_table, "crc32_good:", 793 le32_to_cpu(ofdm->crc32_good), 794 accum_ofdm->crc32_good, delta_ofdm->crc32_good, 795 max_ofdm->crc32_good); 796 pos += scnprintf(buf + pos, bufsz - pos, 797 fmt_table, "false_alarm_cnt:", 798 le32_to_cpu(ofdm->false_alarm_cnt), 799 accum_ofdm->false_alarm_cnt, 800 delta_ofdm->false_alarm_cnt, 801 max_ofdm->false_alarm_cnt); 802 pos += scnprintf(buf + pos, bufsz - pos, 803 fmt_table, "fina_sync_err_cnt:", 804 le32_to_cpu(ofdm->fina_sync_err_cnt), 805 accum_ofdm->fina_sync_err_cnt, 806 delta_ofdm->fina_sync_err_cnt, 807 max_ofdm->fina_sync_err_cnt); 808 pos += scnprintf(buf + pos, bufsz - pos, 809 fmt_table, "sfd_timeout:", 810 le32_to_cpu(ofdm->sfd_timeout), 811 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout, 812 max_ofdm->sfd_timeout); 813 pos += scnprintf(buf + pos, bufsz - pos, 814 fmt_table, "fina_timeout:", 815 le32_to_cpu(ofdm->fina_timeout), 816 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout, 817 max_ofdm->fina_timeout); 818 pos += scnprintf(buf + pos, bufsz - pos, 819 fmt_table, "unresponded_rts:", 820 le32_to_cpu(ofdm->unresponded_rts), 821 accum_ofdm->unresponded_rts, 822 delta_ofdm->unresponded_rts, 823 max_ofdm->unresponded_rts); 824 pos += scnprintf(buf + pos, bufsz - pos, 825 fmt_table, "rxe_frame_lmt_ovrun:", 826 le32_to_cpu(ofdm->rxe_frame_limit_overrun), 827 accum_ofdm->rxe_frame_limit_overrun, 828 delta_ofdm->rxe_frame_limit_overrun, 829 max_ofdm->rxe_frame_limit_overrun); 830 pos += scnprintf(buf + pos, bufsz - pos, 831 fmt_table, "sent_ack_cnt:", 832 le32_to_cpu(ofdm->sent_ack_cnt), 833 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt, 834 max_ofdm->sent_ack_cnt); 835 pos += scnprintf(buf + pos, bufsz - pos, 836 fmt_table, "sent_cts_cnt:", 837 le32_to_cpu(ofdm->sent_cts_cnt), 838 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt, 839 max_ofdm->sent_cts_cnt); 840 pos += scnprintf(buf + pos, bufsz - pos, 841 fmt_table, "sent_ba_rsp_cnt:", 842 le32_to_cpu(ofdm->sent_ba_rsp_cnt), 843 accum_ofdm->sent_ba_rsp_cnt, 844 delta_ofdm->sent_ba_rsp_cnt, 845 max_ofdm->sent_ba_rsp_cnt); 846 pos += scnprintf(buf + pos, bufsz - pos, 847 fmt_table, "dsp_self_kill:", 848 le32_to_cpu(ofdm->dsp_self_kill), 849 accum_ofdm->dsp_self_kill, 850 delta_ofdm->dsp_self_kill, 851 max_ofdm->dsp_self_kill); 852 pos += scnprintf(buf + pos, bufsz - pos, 853 fmt_table, "mh_format_err:", 854 le32_to_cpu(ofdm->mh_format_err), 855 accum_ofdm->mh_format_err, 856 delta_ofdm->mh_format_err, 857 max_ofdm->mh_format_err); 858 pos += scnprintf(buf + pos, bufsz - pos, 859 fmt_table, "re_acq_main_rssi_sum:", 860 le32_to_cpu(ofdm->re_acq_main_rssi_sum), 861 accum_ofdm->re_acq_main_rssi_sum, 862 delta_ofdm->re_acq_main_rssi_sum, 863 max_ofdm->re_acq_main_rssi_sum); 864 865 pos += scnprintf(buf + pos, bufsz - pos, 866 fmt_header, "Statistics_Rx - CCK:"); 867 pos += scnprintf(buf + pos, bufsz - pos, 868 fmt_table, "ina_cnt:", 869 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt, 870 delta_cck->ina_cnt, max_cck->ina_cnt); 871 pos += scnprintf(buf + pos, bufsz - pos, 872 fmt_table, "fina_cnt:", 873 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt, 874 delta_cck->fina_cnt, max_cck->fina_cnt); 875 pos += scnprintf(buf + pos, bufsz - pos, 876 fmt_table, "plcp_err:", 877 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err, 878 delta_cck->plcp_err, max_cck->plcp_err); 879 pos += scnprintf(buf + pos, bufsz - pos, 880 fmt_table, "crc32_err:", 881 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err, 882 delta_cck->crc32_err, max_cck->crc32_err); 883 pos += scnprintf(buf + pos, bufsz - pos, 884 fmt_table, "overrun_err:", 885 le32_to_cpu(cck->overrun_err), 886 accum_cck->overrun_err, delta_cck->overrun_err, 887 max_cck->overrun_err); 888 pos += scnprintf(buf + pos, bufsz - pos, 889 fmt_table, "early_overrun_err:", 890 le32_to_cpu(cck->early_overrun_err), 891 accum_cck->early_overrun_err, 892 delta_cck->early_overrun_err, 893 max_cck->early_overrun_err); 894 pos += scnprintf(buf + pos, bufsz - pos, 895 fmt_table, "crc32_good:", 896 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good, 897 delta_cck->crc32_good, max_cck->crc32_good); 898 pos += scnprintf(buf + pos, bufsz - pos, 899 fmt_table, "false_alarm_cnt:", 900 le32_to_cpu(cck->false_alarm_cnt), 901 accum_cck->false_alarm_cnt, 902 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt); 903 pos += scnprintf(buf + pos, bufsz - pos, 904 fmt_table, "fina_sync_err_cnt:", 905 le32_to_cpu(cck->fina_sync_err_cnt), 906 accum_cck->fina_sync_err_cnt, 907 delta_cck->fina_sync_err_cnt, 908 max_cck->fina_sync_err_cnt); 909 pos += scnprintf(buf + pos, bufsz - pos, 910 fmt_table, "sfd_timeout:", 911 le32_to_cpu(cck->sfd_timeout), 912 accum_cck->sfd_timeout, delta_cck->sfd_timeout, 913 max_cck->sfd_timeout); 914 pos += scnprintf(buf + pos, bufsz - pos, 915 fmt_table, "fina_timeout:", 916 le32_to_cpu(cck->fina_timeout), 917 accum_cck->fina_timeout, delta_cck->fina_timeout, 918 max_cck->fina_timeout); 919 pos += scnprintf(buf + pos, bufsz - pos, 920 fmt_table, "unresponded_rts:", 921 le32_to_cpu(cck->unresponded_rts), 922 accum_cck->unresponded_rts, delta_cck->unresponded_rts, 923 max_cck->unresponded_rts); 924 pos += scnprintf(buf + pos, bufsz - pos, 925 fmt_table, "rxe_frame_lmt_ovrun:", 926 le32_to_cpu(cck->rxe_frame_limit_overrun), 927 accum_cck->rxe_frame_limit_overrun, 928 delta_cck->rxe_frame_limit_overrun, 929 max_cck->rxe_frame_limit_overrun); 930 pos += scnprintf(buf + pos, bufsz - pos, 931 fmt_table, "sent_ack_cnt:", 932 le32_to_cpu(cck->sent_ack_cnt), 933 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt, 934 max_cck->sent_ack_cnt); 935 pos += scnprintf(buf + pos, bufsz - pos, 936 fmt_table, "sent_cts_cnt:", 937 le32_to_cpu(cck->sent_cts_cnt), 938 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt, 939 max_cck->sent_cts_cnt); 940 pos += scnprintf(buf + pos, bufsz - pos, 941 fmt_table, "sent_ba_rsp_cnt:", 942 le32_to_cpu(cck->sent_ba_rsp_cnt), 943 accum_cck->sent_ba_rsp_cnt, 944 delta_cck->sent_ba_rsp_cnt, 945 max_cck->sent_ba_rsp_cnt); 946 pos += scnprintf(buf + pos, bufsz - pos, 947 fmt_table, "dsp_self_kill:", 948 le32_to_cpu(cck->dsp_self_kill), 949 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill, 950 max_cck->dsp_self_kill); 951 pos += scnprintf(buf + pos, bufsz - pos, 952 fmt_table, "mh_format_err:", 953 le32_to_cpu(cck->mh_format_err), 954 accum_cck->mh_format_err, delta_cck->mh_format_err, 955 max_cck->mh_format_err); 956 pos += scnprintf(buf + pos, bufsz - pos, 957 fmt_table, "re_acq_main_rssi_sum:", 958 le32_to_cpu(cck->re_acq_main_rssi_sum), 959 accum_cck->re_acq_main_rssi_sum, 960 delta_cck->re_acq_main_rssi_sum, 961 max_cck->re_acq_main_rssi_sum); 962 963 pos += scnprintf(buf + pos, bufsz - pos, 964 fmt_header, "Statistics_Rx - GENERAL:"); 965 pos += scnprintf(buf + pos, bufsz - pos, 966 fmt_table, "bogus_cts:", 967 le32_to_cpu(general->bogus_cts), 968 accum_general->bogus_cts, delta_general->bogus_cts, 969 max_general->bogus_cts); 970 pos += scnprintf(buf + pos, bufsz - pos, 971 fmt_table, "bogus_ack:", 972 le32_to_cpu(general->bogus_ack), 973 accum_general->bogus_ack, delta_general->bogus_ack, 974 max_general->bogus_ack); 975 pos += scnprintf(buf + pos, bufsz - pos, 976 fmt_table, "non_bssid_frames:", 977 le32_to_cpu(general->non_bssid_frames), 978 accum_general->non_bssid_frames, 979 delta_general->non_bssid_frames, 980 max_general->non_bssid_frames); 981 pos += scnprintf(buf + pos, bufsz - pos, 982 fmt_table, "filtered_frames:", 983 le32_to_cpu(general->filtered_frames), 984 accum_general->filtered_frames, 985 delta_general->filtered_frames, 986 max_general->filtered_frames); 987 pos += scnprintf(buf + pos, bufsz - pos, 988 fmt_table, "non_channel_beacons:", 989 le32_to_cpu(general->non_channel_beacons), 990 accum_general->non_channel_beacons, 991 delta_general->non_channel_beacons, 992 max_general->non_channel_beacons); 993 pos += scnprintf(buf + pos, bufsz - pos, 994 fmt_table, "channel_beacons:", 995 le32_to_cpu(general->channel_beacons), 996 accum_general->channel_beacons, 997 delta_general->channel_beacons, 998 max_general->channel_beacons); 999 pos += scnprintf(buf + pos, bufsz - pos, 1000 fmt_table, "num_missed_bcon:", 1001 le32_to_cpu(general->num_missed_bcon), 1002 accum_general->num_missed_bcon, 1003 delta_general->num_missed_bcon, 1004 max_general->num_missed_bcon); 1005 pos += scnprintf(buf + pos, bufsz - pos, 1006 fmt_table, "adc_rx_saturation_time:", 1007 le32_to_cpu(general->adc_rx_saturation_time), 1008 accum_general->adc_rx_saturation_time, 1009 delta_general->adc_rx_saturation_time, 1010 max_general->adc_rx_saturation_time); 1011 pos += scnprintf(buf + pos, bufsz - pos, 1012 fmt_table, "ina_detect_search_tm:", 1013 le32_to_cpu(general->ina_detection_search_time), 1014 accum_general->ina_detection_search_time, 1015 delta_general->ina_detection_search_time, 1016 max_general->ina_detection_search_time); 1017 pos += scnprintf(buf + pos, bufsz - pos, 1018 fmt_table, "beacon_silence_rssi_a:", 1019 le32_to_cpu(general->beacon_silence_rssi_a), 1020 accum_general->beacon_silence_rssi_a, 1021 delta_general->beacon_silence_rssi_a, 1022 max_general->beacon_silence_rssi_a); 1023 pos += scnprintf(buf + pos, bufsz - pos, 1024 fmt_table, "beacon_silence_rssi_b:", 1025 le32_to_cpu(general->beacon_silence_rssi_b), 1026 accum_general->beacon_silence_rssi_b, 1027 delta_general->beacon_silence_rssi_b, 1028 max_general->beacon_silence_rssi_b); 1029 pos += scnprintf(buf + pos, bufsz - pos, 1030 fmt_table, "beacon_silence_rssi_c:", 1031 le32_to_cpu(general->beacon_silence_rssi_c), 1032 accum_general->beacon_silence_rssi_c, 1033 delta_general->beacon_silence_rssi_c, 1034 max_general->beacon_silence_rssi_c); 1035 pos += scnprintf(buf + pos, bufsz - pos, 1036 fmt_table, "interference_data_flag:", 1037 le32_to_cpu(general->interference_data_flag), 1038 accum_general->interference_data_flag, 1039 delta_general->interference_data_flag, 1040 max_general->interference_data_flag); 1041 pos += scnprintf(buf + pos, bufsz - pos, 1042 fmt_table, "channel_load:", 1043 le32_to_cpu(general->channel_load), 1044 accum_general->channel_load, 1045 delta_general->channel_load, 1046 max_general->channel_load); 1047 pos += scnprintf(buf + pos, bufsz - pos, 1048 fmt_table, "dsp_false_alarms:", 1049 le32_to_cpu(general->dsp_false_alarms), 1050 accum_general->dsp_false_alarms, 1051 delta_general->dsp_false_alarms, 1052 max_general->dsp_false_alarms); 1053 pos += scnprintf(buf + pos, bufsz - pos, 1054 fmt_table, "beacon_rssi_a:", 1055 le32_to_cpu(general->beacon_rssi_a), 1056 accum_general->beacon_rssi_a, 1057 delta_general->beacon_rssi_a, 1058 max_general->beacon_rssi_a); 1059 pos += scnprintf(buf + pos, bufsz - pos, 1060 fmt_table, "beacon_rssi_b:", 1061 le32_to_cpu(general->beacon_rssi_b), 1062 accum_general->beacon_rssi_b, 1063 delta_general->beacon_rssi_b, 1064 max_general->beacon_rssi_b); 1065 pos += scnprintf(buf + pos, bufsz - pos, 1066 fmt_table, "beacon_rssi_c:", 1067 le32_to_cpu(general->beacon_rssi_c), 1068 accum_general->beacon_rssi_c, 1069 delta_general->beacon_rssi_c, 1070 max_general->beacon_rssi_c); 1071 pos += scnprintf(buf + pos, bufsz - pos, 1072 fmt_table, "beacon_energy_a:", 1073 le32_to_cpu(general->beacon_energy_a), 1074 accum_general->beacon_energy_a, 1075 delta_general->beacon_energy_a, 1076 max_general->beacon_energy_a); 1077 pos += scnprintf(buf + pos, bufsz - pos, 1078 fmt_table, "beacon_energy_b:", 1079 le32_to_cpu(general->beacon_energy_b), 1080 accum_general->beacon_energy_b, 1081 delta_general->beacon_energy_b, 1082 max_general->beacon_energy_b); 1083 pos += scnprintf(buf + pos, bufsz - pos, 1084 fmt_table, "beacon_energy_c:", 1085 le32_to_cpu(general->beacon_energy_c), 1086 accum_general->beacon_energy_c, 1087 delta_general->beacon_energy_c, 1088 max_general->beacon_energy_c); 1089 1090 pos += scnprintf(buf + pos, bufsz - pos, 1091 fmt_header, "Statistics_Rx - OFDM_HT:"); 1092 pos += scnprintf(buf + pos, bufsz - pos, 1093 fmt_table, "plcp_err:", 1094 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err, 1095 delta_ht->plcp_err, max_ht->plcp_err); 1096 pos += scnprintf(buf + pos, bufsz - pos, 1097 fmt_table, "overrun_err:", 1098 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err, 1099 delta_ht->overrun_err, max_ht->overrun_err); 1100 pos += scnprintf(buf + pos, bufsz - pos, 1101 fmt_table, "early_overrun_err:", 1102 le32_to_cpu(ht->early_overrun_err), 1103 accum_ht->early_overrun_err, 1104 delta_ht->early_overrun_err, 1105 max_ht->early_overrun_err); 1106 pos += scnprintf(buf + pos, bufsz - pos, 1107 fmt_table, "crc32_good:", 1108 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good, 1109 delta_ht->crc32_good, max_ht->crc32_good); 1110 pos += scnprintf(buf + pos, bufsz - pos, 1111 fmt_table, "crc32_err:", 1112 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err, 1113 delta_ht->crc32_err, max_ht->crc32_err); 1114 pos += scnprintf(buf + pos, bufsz - pos, 1115 fmt_table, "mh_format_err:", 1116 le32_to_cpu(ht->mh_format_err), 1117 accum_ht->mh_format_err, 1118 delta_ht->mh_format_err, max_ht->mh_format_err); 1119 pos += scnprintf(buf + pos, bufsz - pos, 1120 fmt_table, "agg_crc32_good:", 1121 le32_to_cpu(ht->agg_crc32_good), 1122 accum_ht->agg_crc32_good, 1123 delta_ht->agg_crc32_good, max_ht->agg_crc32_good); 1124 pos += scnprintf(buf + pos, bufsz - pos, 1125 fmt_table, "agg_mpdu_cnt:", 1126 le32_to_cpu(ht->agg_mpdu_cnt), 1127 accum_ht->agg_mpdu_cnt, 1128 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt); 1129 pos += scnprintf(buf + pos, bufsz - pos, 1130 fmt_table, "agg_cnt:", 1131 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt, 1132 delta_ht->agg_cnt, max_ht->agg_cnt); 1133 pos += scnprintf(buf + pos, bufsz - pos, 1134 fmt_table, "unsupport_mcs:", 1135 le32_to_cpu(ht->unsupport_mcs), 1136 accum_ht->unsupport_mcs, 1137 delta_ht->unsupport_mcs, max_ht->unsupport_mcs); 1138 1139 spin_unlock_bh(&priv->statistics.lock); 1140 1141 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1142 kfree(buf); 1143 return ret; 1144 } 1145 1146 static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file, 1147 char __user *user_buf, 1148 size_t count, loff_t *ppos) 1149 { 1150 struct iwl_priv *priv = file->private_data; 1151 int pos = 0; 1152 char *buf; 1153 int bufsz = (sizeof(struct statistics_tx) * 48) + 250; 1154 ssize_t ret; 1155 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx; 1156 1157 if (!iwl_is_alive(priv)) 1158 return -EAGAIN; 1159 1160 buf = kzalloc(bufsz, GFP_KERNEL); 1161 if (!buf) 1162 return -ENOMEM; 1163 1164 /* the statistic information display here is based on 1165 * the last statistics notification from uCode 1166 * might not reflect the current uCode activity 1167 */ 1168 spin_lock_bh(&priv->statistics.lock); 1169 1170 tx = &priv->statistics.tx; 1171 accum_tx = &priv->accum_stats.tx; 1172 delta_tx = &priv->delta_stats.tx; 1173 max_tx = &priv->max_delta_stats.tx; 1174 1175 pos += iwl_statistics_flag(priv, buf, bufsz); 1176 pos += scnprintf(buf + pos, bufsz - pos, 1177 fmt_header, "Statistics_Tx:"); 1178 pos += scnprintf(buf + pos, bufsz - pos, 1179 fmt_table, "preamble:", 1180 le32_to_cpu(tx->preamble_cnt), 1181 accum_tx->preamble_cnt, 1182 delta_tx->preamble_cnt, max_tx->preamble_cnt); 1183 pos += scnprintf(buf + pos, bufsz - pos, 1184 fmt_table, "rx_detected_cnt:", 1185 le32_to_cpu(tx->rx_detected_cnt), 1186 accum_tx->rx_detected_cnt, 1187 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt); 1188 pos += scnprintf(buf + pos, bufsz - pos, 1189 fmt_table, "bt_prio_defer_cnt:", 1190 le32_to_cpu(tx->bt_prio_defer_cnt), 1191 accum_tx->bt_prio_defer_cnt, 1192 delta_tx->bt_prio_defer_cnt, 1193 max_tx->bt_prio_defer_cnt); 1194 pos += scnprintf(buf + pos, bufsz - pos, 1195 fmt_table, "bt_prio_kill_cnt:", 1196 le32_to_cpu(tx->bt_prio_kill_cnt), 1197 accum_tx->bt_prio_kill_cnt, 1198 delta_tx->bt_prio_kill_cnt, 1199 max_tx->bt_prio_kill_cnt); 1200 pos += scnprintf(buf + pos, bufsz - pos, 1201 fmt_table, "few_bytes_cnt:", 1202 le32_to_cpu(tx->few_bytes_cnt), 1203 accum_tx->few_bytes_cnt, 1204 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt); 1205 pos += scnprintf(buf + pos, bufsz - pos, 1206 fmt_table, "cts_timeout:", 1207 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout, 1208 delta_tx->cts_timeout, max_tx->cts_timeout); 1209 pos += scnprintf(buf + pos, bufsz - pos, 1210 fmt_table, "ack_timeout:", 1211 le32_to_cpu(tx->ack_timeout), 1212 accum_tx->ack_timeout, 1213 delta_tx->ack_timeout, max_tx->ack_timeout); 1214 pos += scnprintf(buf + pos, bufsz - pos, 1215 fmt_table, "expected_ack_cnt:", 1216 le32_to_cpu(tx->expected_ack_cnt), 1217 accum_tx->expected_ack_cnt, 1218 delta_tx->expected_ack_cnt, 1219 max_tx->expected_ack_cnt); 1220 pos += scnprintf(buf + pos, bufsz - pos, 1221 fmt_table, "actual_ack_cnt:", 1222 le32_to_cpu(tx->actual_ack_cnt), 1223 accum_tx->actual_ack_cnt, 1224 delta_tx->actual_ack_cnt, 1225 max_tx->actual_ack_cnt); 1226 pos += scnprintf(buf + pos, bufsz - pos, 1227 fmt_table, "dump_msdu_cnt:", 1228 le32_to_cpu(tx->dump_msdu_cnt), 1229 accum_tx->dump_msdu_cnt, 1230 delta_tx->dump_msdu_cnt, 1231 max_tx->dump_msdu_cnt); 1232 pos += scnprintf(buf + pos, bufsz - pos, 1233 fmt_table, "abort_nxt_frame_mismatch:", 1234 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt), 1235 accum_tx->burst_abort_next_frame_mismatch_cnt, 1236 delta_tx->burst_abort_next_frame_mismatch_cnt, 1237 max_tx->burst_abort_next_frame_mismatch_cnt); 1238 pos += scnprintf(buf + pos, bufsz - pos, 1239 fmt_table, "abort_missing_nxt_frame:", 1240 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt), 1241 accum_tx->burst_abort_missing_next_frame_cnt, 1242 delta_tx->burst_abort_missing_next_frame_cnt, 1243 max_tx->burst_abort_missing_next_frame_cnt); 1244 pos += scnprintf(buf + pos, bufsz - pos, 1245 fmt_table, "cts_timeout_collision:", 1246 le32_to_cpu(tx->cts_timeout_collision), 1247 accum_tx->cts_timeout_collision, 1248 delta_tx->cts_timeout_collision, 1249 max_tx->cts_timeout_collision); 1250 pos += scnprintf(buf + pos, bufsz - pos, 1251 fmt_table, "ack_ba_timeout_collision:", 1252 le32_to_cpu(tx->ack_or_ba_timeout_collision), 1253 accum_tx->ack_or_ba_timeout_collision, 1254 delta_tx->ack_or_ba_timeout_collision, 1255 max_tx->ack_or_ba_timeout_collision); 1256 pos += scnprintf(buf + pos, bufsz - pos, 1257 fmt_table, "agg ba_timeout:", 1258 le32_to_cpu(tx->agg.ba_timeout), 1259 accum_tx->agg.ba_timeout, 1260 delta_tx->agg.ba_timeout, 1261 max_tx->agg.ba_timeout); 1262 pos += scnprintf(buf + pos, bufsz - pos, 1263 fmt_table, "agg ba_resched_frames:", 1264 le32_to_cpu(tx->agg.ba_reschedule_frames), 1265 accum_tx->agg.ba_reschedule_frames, 1266 delta_tx->agg.ba_reschedule_frames, 1267 max_tx->agg.ba_reschedule_frames); 1268 pos += scnprintf(buf + pos, bufsz - pos, 1269 fmt_table, "agg scd_query_agg_frame:", 1270 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt), 1271 accum_tx->agg.scd_query_agg_frame_cnt, 1272 delta_tx->agg.scd_query_agg_frame_cnt, 1273 max_tx->agg.scd_query_agg_frame_cnt); 1274 pos += scnprintf(buf + pos, bufsz - pos, 1275 fmt_table, "agg scd_query_no_agg:", 1276 le32_to_cpu(tx->agg.scd_query_no_agg), 1277 accum_tx->agg.scd_query_no_agg, 1278 delta_tx->agg.scd_query_no_agg, 1279 max_tx->agg.scd_query_no_agg); 1280 pos += scnprintf(buf + pos, bufsz - pos, 1281 fmt_table, "agg scd_query_agg:", 1282 le32_to_cpu(tx->agg.scd_query_agg), 1283 accum_tx->agg.scd_query_agg, 1284 delta_tx->agg.scd_query_agg, 1285 max_tx->agg.scd_query_agg); 1286 pos += scnprintf(buf + pos, bufsz - pos, 1287 fmt_table, "agg scd_query_mismatch:", 1288 le32_to_cpu(tx->agg.scd_query_mismatch), 1289 accum_tx->agg.scd_query_mismatch, 1290 delta_tx->agg.scd_query_mismatch, 1291 max_tx->agg.scd_query_mismatch); 1292 pos += scnprintf(buf + pos, bufsz - pos, 1293 fmt_table, "agg frame_not_ready:", 1294 le32_to_cpu(tx->agg.frame_not_ready), 1295 accum_tx->agg.frame_not_ready, 1296 delta_tx->agg.frame_not_ready, 1297 max_tx->agg.frame_not_ready); 1298 pos += scnprintf(buf + pos, bufsz - pos, 1299 fmt_table, "agg underrun:", 1300 le32_to_cpu(tx->agg.underrun), 1301 accum_tx->agg.underrun, 1302 delta_tx->agg.underrun, max_tx->agg.underrun); 1303 pos += scnprintf(buf + pos, bufsz - pos, 1304 fmt_table, "agg bt_prio_kill:", 1305 le32_to_cpu(tx->agg.bt_prio_kill), 1306 accum_tx->agg.bt_prio_kill, 1307 delta_tx->agg.bt_prio_kill, 1308 max_tx->agg.bt_prio_kill); 1309 pos += scnprintf(buf + pos, bufsz - pos, 1310 fmt_table, "agg rx_ba_rsp_cnt:", 1311 le32_to_cpu(tx->agg.rx_ba_rsp_cnt), 1312 accum_tx->agg.rx_ba_rsp_cnt, 1313 delta_tx->agg.rx_ba_rsp_cnt, 1314 max_tx->agg.rx_ba_rsp_cnt); 1315 1316 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) { 1317 pos += scnprintf(buf + pos, bufsz - pos, 1318 "tx power: (1/2 dB step)\n"); 1319 if ((priv->nvm_data->valid_tx_ant & ANT_A) && 1320 tx->tx_power.ant_a) 1321 pos += scnprintf(buf + pos, bufsz - pos, 1322 fmt_hex, "antenna A:", 1323 tx->tx_power.ant_a); 1324 if ((priv->nvm_data->valid_tx_ant & ANT_B) && 1325 tx->tx_power.ant_b) 1326 pos += scnprintf(buf + pos, bufsz - pos, 1327 fmt_hex, "antenna B:", 1328 tx->tx_power.ant_b); 1329 if ((priv->nvm_data->valid_tx_ant & ANT_C) && 1330 tx->tx_power.ant_c) 1331 pos += scnprintf(buf + pos, bufsz - pos, 1332 fmt_hex, "antenna C:", 1333 tx->tx_power.ant_c); 1334 } 1335 1336 spin_unlock_bh(&priv->statistics.lock); 1337 1338 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1339 kfree(buf); 1340 return ret; 1341 } 1342 1343 static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file, 1344 char __user *user_buf, 1345 size_t count, loff_t *ppos) 1346 { 1347 struct iwl_priv *priv = file->private_data; 1348 int pos = 0; 1349 char *buf; 1350 int bufsz = sizeof(struct statistics_general) * 10 + 300; 1351 ssize_t ret; 1352 struct statistics_general_common *general, *accum_general; 1353 struct statistics_general_common *delta_general, *max_general; 1354 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg; 1355 struct statistics_div *div, *accum_div, *delta_div, *max_div; 1356 1357 if (!iwl_is_alive(priv)) 1358 return -EAGAIN; 1359 1360 buf = kzalloc(bufsz, GFP_KERNEL); 1361 if (!buf) 1362 return -ENOMEM; 1363 1364 /* the statistic information display here is based on 1365 * the last statistics notification from uCode 1366 * might not reflect the current uCode activity 1367 */ 1368 1369 spin_lock_bh(&priv->statistics.lock); 1370 1371 general = &priv->statistics.common; 1372 dbg = &priv->statistics.common.dbg; 1373 div = &priv->statistics.common.div; 1374 accum_general = &priv->accum_stats.common; 1375 accum_dbg = &priv->accum_stats.common.dbg; 1376 accum_div = &priv->accum_stats.common.div; 1377 delta_general = &priv->delta_stats.common; 1378 max_general = &priv->max_delta_stats.common; 1379 delta_dbg = &priv->delta_stats.common.dbg; 1380 max_dbg = &priv->max_delta_stats.common.dbg; 1381 delta_div = &priv->delta_stats.common.div; 1382 max_div = &priv->max_delta_stats.common.div; 1383 1384 pos += iwl_statistics_flag(priv, buf, bufsz); 1385 pos += scnprintf(buf + pos, bufsz - pos, 1386 fmt_header, "Statistics_General:"); 1387 pos += scnprintf(buf + pos, bufsz - pos, 1388 fmt_value, "temperature:", 1389 le32_to_cpu(general->temperature)); 1390 pos += scnprintf(buf + pos, bufsz - pos, 1391 fmt_value, "temperature_m:", 1392 le32_to_cpu(general->temperature_m)); 1393 pos += scnprintf(buf + pos, bufsz - pos, 1394 fmt_value, "ttl_timestamp:", 1395 le32_to_cpu(general->ttl_timestamp)); 1396 pos += scnprintf(buf + pos, bufsz - pos, 1397 fmt_table, "burst_check:", 1398 le32_to_cpu(dbg->burst_check), 1399 accum_dbg->burst_check, 1400 delta_dbg->burst_check, max_dbg->burst_check); 1401 pos += scnprintf(buf + pos, bufsz - pos, 1402 fmt_table, "burst_count:", 1403 le32_to_cpu(dbg->burst_count), 1404 accum_dbg->burst_count, 1405 delta_dbg->burst_count, max_dbg->burst_count); 1406 pos += scnprintf(buf + pos, bufsz - pos, 1407 fmt_table, "wait_for_silence_timeout_count:", 1408 le32_to_cpu(dbg->wait_for_silence_timeout_cnt), 1409 accum_dbg->wait_for_silence_timeout_cnt, 1410 delta_dbg->wait_for_silence_timeout_cnt, 1411 max_dbg->wait_for_silence_timeout_cnt); 1412 pos += scnprintf(buf + pos, bufsz - pos, 1413 fmt_table, "sleep_time:", 1414 le32_to_cpu(general->sleep_time), 1415 accum_general->sleep_time, 1416 delta_general->sleep_time, max_general->sleep_time); 1417 pos += scnprintf(buf + pos, bufsz - pos, 1418 fmt_table, "slots_out:", 1419 le32_to_cpu(general->slots_out), 1420 accum_general->slots_out, 1421 delta_general->slots_out, max_general->slots_out); 1422 pos += scnprintf(buf + pos, bufsz - pos, 1423 fmt_table, "slots_idle:", 1424 le32_to_cpu(general->slots_idle), 1425 accum_general->slots_idle, 1426 delta_general->slots_idle, max_general->slots_idle); 1427 pos += scnprintf(buf + pos, bufsz - pos, 1428 fmt_table, "tx_on_a:", 1429 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a, 1430 delta_div->tx_on_a, max_div->tx_on_a); 1431 pos += scnprintf(buf + pos, bufsz - pos, 1432 fmt_table, "tx_on_b:", 1433 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b, 1434 delta_div->tx_on_b, max_div->tx_on_b); 1435 pos += scnprintf(buf + pos, bufsz - pos, 1436 fmt_table, "exec_time:", 1437 le32_to_cpu(div->exec_time), accum_div->exec_time, 1438 delta_div->exec_time, max_div->exec_time); 1439 pos += scnprintf(buf + pos, bufsz - pos, 1440 fmt_table, "probe_time:", 1441 le32_to_cpu(div->probe_time), accum_div->probe_time, 1442 delta_div->probe_time, max_div->probe_time); 1443 pos += scnprintf(buf + pos, bufsz - pos, 1444 fmt_table, "rx_enable_counter:", 1445 le32_to_cpu(general->rx_enable_counter), 1446 accum_general->rx_enable_counter, 1447 delta_general->rx_enable_counter, 1448 max_general->rx_enable_counter); 1449 pos += scnprintf(buf + pos, bufsz - pos, 1450 fmt_table, "num_of_sos_states:", 1451 le32_to_cpu(general->num_of_sos_states), 1452 accum_general->num_of_sos_states, 1453 delta_general->num_of_sos_states, 1454 max_general->num_of_sos_states); 1455 1456 spin_unlock_bh(&priv->statistics.lock); 1457 1458 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1459 kfree(buf); 1460 return ret; 1461 } 1462 1463 static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file, 1464 char __user *user_buf, 1465 size_t count, loff_t *ppos) 1466 { 1467 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 1468 int pos = 0; 1469 char *buf; 1470 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200; 1471 ssize_t ret; 1472 struct statistics_bt_activity *bt, *accum_bt; 1473 1474 if (!iwl_is_alive(priv)) 1475 return -EAGAIN; 1476 1477 if (!priv->bt_enable_flag) 1478 return -EINVAL; 1479 1480 /* make request to uCode to retrieve statistics information */ 1481 mutex_lock(&priv->mutex); 1482 ret = iwl_send_statistics_request(priv, 0, false); 1483 mutex_unlock(&priv->mutex); 1484 1485 if (ret) 1486 return -EAGAIN; 1487 buf = kzalloc(bufsz, GFP_KERNEL); 1488 if (!buf) 1489 return -ENOMEM; 1490 1491 /* 1492 * the statistic information display here is based on 1493 * the last statistics notification from uCode 1494 * might not reflect the current uCode activity 1495 */ 1496 1497 spin_lock_bh(&priv->statistics.lock); 1498 1499 bt = &priv->statistics.bt_activity; 1500 accum_bt = &priv->accum_stats.bt_activity; 1501 1502 pos += iwl_statistics_flag(priv, buf, bufsz); 1503 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n"); 1504 pos += scnprintf(buf + pos, bufsz - pos, 1505 "\t\t\tcurrent\t\t\taccumulative\n"); 1506 pos += scnprintf(buf + pos, bufsz - pos, 1507 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n", 1508 le32_to_cpu(bt->hi_priority_tx_req_cnt), 1509 accum_bt->hi_priority_tx_req_cnt); 1510 pos += scnprintf(buf + pos, bufsz - pos, 1511 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n", 1512 le32_to_cpu(bt->hi_priority_tx_denied_cnt), 1513 accum_bt->hi_priority_tx_denied_cnt); 1514 pos += scnprintf(buf + pos, bufsz - pos, 1515 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n", 1516 le32_to_cpu(bt->lo_priority_tx_req_cnt), 1517 accum_bt->lo_priority_tx_req_cnt); 1518 pos += scnprintf(buf + pos, bufsz - pos, 1519 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n", 1520 le32_to_cpu(bt->lo_priority_tx_denied_cnt), 1521 accum_bt->lo_priority_tx_denied_cnt); 1522 pos += scnprintf(buf + pos, bufsz - pos, 1523 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n", 1524 le32_to_cpu(bt->hi_priority_rx_req_cnt), 1525 accum_bt->hi_priority_rx_req_cnt); 1526 pos += scnprintf(buf + pos, bufsz - pos, 1527 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n", 1528 le32_to_cpu(bt->hi_priority_rx_denied_cnt), 1529 accum_bt->hi_priority_rx_denied_cnt); 1530 pos += scnprintf(buf + pos, bufsz - pos, 1531 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n", 1532 le32_to_cpu(bt->lo_priority_rx_req_cnt), 1533 accum_bt->lo_priority_rx_req_cnt); 1534 pos += scnprintf(buf + pos, bufsz - pos, 1535 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n", 1536 le32_to_cpu(bt->lo_priority_rx_denied_cnt), 1537 accum_bt->lo_priority_rx_denied_cnt); 1538 1539 pos += scnprintf(buf + pos, bufsz - pos, 1540 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n", 1541 le32_to_cpu(priv->statistics.num_bt_kills), 1542 priv->statistics.accum_num_bt_kills); 1543 1544 spin_unlock_bh(&priv->statistics.lock); 1545 1546 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1547 kfree(buf); 1548 return ret; 1549 } 1550 1551 static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file, 1552 char __user *user_buf, 1553 size_t count, loff_t *ppos) 1554 { 1555 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 1556 int pos = 0; 1557 char *buf; 1558 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) + 1559 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200; 1560 ssize_t ret; 1561 1562 if (!iwl_is_alive(priv)) 1563 return -EAGAIN; 1564 1565 buf = kzalloc(bufsz, GFP_KERNEL); 1566 if (!buf) 1567 return -ENOMEM; 1568 1569 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n"); 1570 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n", 1571 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY), 1572 priv->reply_tx_stats.pp_delay); 1573 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1574 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES), 1575 priv->reply_tx_stats.pp_few_bytes); 1576 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1577 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO), 1578 priv->reply_tx_stats.pp_bt_prio); 1579 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1580 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD), 1581 priv->reply_tx_stats.pp_quiet_period); 1582 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1583 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK), 1584 priv->reply_tx_stats.pp_calc_ttak); 1585 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1586 iwl_get_tx_fail_reason( 1587 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY), 1588 priv->reply_tx_stats.int_crossed_retry); 1589 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1590 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT), 1591 priv->reply_tx_stats.short_limit); 1592 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1593 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT), 1594 priv->reply_tx_stats.long_limit); 1595 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1596 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN), 1597 priv->reply_tx_stats.fifo_underrun); 1598 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1599 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW), 1600 priv->reply_tx_stats.drain_flow); 1601 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1602 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH), 1603 priv->reply_tx_stats.rfkill_flush); 1604 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1605 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE), 1606 priv->reply_tx_stats.life_expire); 1607 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1608 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS), 1609 priv->reply_tx_stats.dest_ps); 1610 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1611 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED), 1612 priv->reply_tx_stats.host_abort); 1613 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1614 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY), 1615 priv->reply_tx_stats.pp_delay); 1616 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1617 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID), 1618 priv->reply_tx_stats.sta_invalid); 1619 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1620 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED), 1621 priv->reply_tx_stats.frag_drop); 1622 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1623 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE), 1624 priv->reply_tx_stats.tid_disable); 1625 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1626 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED), 1627 priv->reply_tx_stats.fifo_flush); 1628 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1629 iwl_get_tx_fail_reason( 1630 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL), 1631 priv->reply_tx_stats.insuff_cf_poll); 1632 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1633 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX), 1634 priv->reply_tx_stats.fail_hw_drop); 1635 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1636 iwl_get_tx_fail_reason( 1637 TX_STATUS_FAIL_NO_BEACON_ON_RADAR), 1638 priv->reply_tx_stats.sta_color_mismatch); 1639 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n", 1640 priv->reply_tx_stats.unknown); 1641 1642 pos += scnprintf(buf + pos, bufsz - pos, 1643 "\nStatistics_Agg_TX_Error:\n"); 1644 1645 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1646 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK), 1647 priv->reply_agg_tx_stats.underrun); 1648 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1649 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK), 1650 priv->reply_agg_tx_stats.bt_prio); 1651 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1652 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK), 1653 priv->reply_agg_tx_stats.few_bytes); 1654 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1655 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK), 1656 priv->reply_agg_tx_stats.abort); 1657 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1658 iwl_get_agg_tx_fail_reason( 1659 AGG_TX_STATE_LAST_SENT_TTL_MSK), 1660 priv->reply_agg_tx_stats.last_sent_ttl); 1661 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1662 iwl_get_agg_tx_fail_reason( 1663 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK), 1664 priv->reply_agg_tx_stats.last_sent_try); 1665 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1666 iwl_get_agg_tx_fail_reason( 1667 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK), 1668 priv->reply_agg_tx_stats.last_sent_bt_kill); 1669 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1670 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK), 1671 priv->reply_agg_tx_stats.scd_query); 1672 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n", 1673 iwl_get_agg_tx_fail_reason( 1674 AGG_TX_STATE_TEST_BAD_CRC32_MSK), 1675 priv->reply_agg_tx_stats.bad_crc32); 1676 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1677 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK), 1678 priv->reply_agg_tx_stats.response); 1679 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1680 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK), 1681 priv->reply_agg_tx_stats.dump_tx); 1682 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n", 1683 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK), 1684 priv->reply_agg_tx_stats.delay_tx); 1685 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n", 1686 priv->reply_agg_tx_stats.unknown); 1687 1688 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1689 kfree(buf); 1690 return ret; 1691 } 1692 1693 static ssize_t iwl_dbgfs_sensitivity_read(struct file *file, 1694 char __user *user_buf, 1695 size_t count, loff_t *ppos) { 1696 1697 struct iwl_priv *priv = file->private_data; 1698 int pos = 0; 1699 int cnt = 0; 1700 char *buf; 1701 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100; 1702 ssize_t ret; 1703 struct iwl_sensitivity_data *data; 1704 1705 data = &priv->sensitivity_data; 1706 buf = kzalloc(bufsz, GFP_KERNEL); 1707 if (!buf) 1708 return -ENOMEM; 1709 1710 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n", 1711 data->auto_corr_ofdm); 1712 pos += scnprintf(buf + pos, bufsz - pos, 1713 "auto_corr_ofdm_mrc:\t\t %u\n", 1714 data->auto_corr_ofdm_mrc); 1715 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n", 1716 data->auto_corr_ofdm_x1); 1717 pos += scnprintf(buf + pos, bufsz - pos, 1718 "auto_corr_ofdm_mrc_x1:\t\t %u\n", 1719 data->auto_corr_ofdm_mrc_x1); 1720 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n", 1721 data->auto_corr_cck); 1722 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n", 1723 data->auto_corr_cck_mrc); 1724 pos += scnprintf(buf + pos, bufsz - pos, 1725 "last_bad_plcp_cnt_ofdm:\t\t %u\n", 1726 data->last_bad_plcp_cnt_ofdm); 1727 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n", 1728 data->last_fa_cnt_ofdm); 1729 pos += scnprintf(buf + pos, bufsz - pos, 1730 "last_bad_plcp_cnt_cck:\t\t %u\n", 1731 data->last_bad_plcp_cnt_cck); 1732 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n", 1733 data->last_fa_cnt_cck); 1734 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n", 1735 data->nrg_curr_state); 1736 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n", 1737 data->nrg_prev_state); 1738 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t"); 1739 for (cnt = 0; cnt < 10; cnt++) { 1740 pos += scnprintf(buf + pos, bufsz - pos, " %u", 1741 data->nrg_value[cnt]); 1742 } 1743 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 1744 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t"); 1745 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) { 1746 pos += scnprintf(buf + pos, bufsz - pos, " %u", 1747 data->nrg_silence_rssi[cnt]); 1748 } 1749 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 1750 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n", 1751 data->nrg_silence_ref); 1752 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n", 1753 data->nrg_energy_idx); 1754 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n", 1755 data->nrg_silence_idx); 1756 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n", 1757 data->nrg_th_cck); 1758 pos += scnprintf(buf + pos, bufsz - pos, 1759 "nrg_auto_corr_silence_diff:\t %u\n", 1760 data->nrg_auto_corr_silence_diff); 1761 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n", 1762 data->num_in_cck_no_fa); 1763 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n", 1764 data->nrg_th_ofdm); 1765 1766 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1767 kfree(buf); 1768 return ret; 1769 } 1770 1771 1772 static ssize_t iwl_dbgfs_chain_noise_read(struct file *file, 1773 char __user *user_buf, 1774 size_t count, loff_t *ppos) { 1775 1776 struct iwl_priv *priv = file->private_data; 1777 int pos = 0; 1778 int cnt = 0; 1779 char *buf; 1780 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100; 1781 ssize_t ret; 1782 struct iwl_chain_noise_data *data; 1783 1784 data = &priv->chain_noise_data; 1785 buf = kzalloc(bufsz, GFP_KERNEL); 1786 if (!buf) 1787 return -ENOMEM; 1788 1789 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n", 1790 data->active_chains); 1791 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n", 1792 data->chain_noise_a); 1793 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n", 1794 data->chain_noise_b); 1795 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n", 1796 data->chain_noise_c); 1797 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n", 1798 data->chain_signal_a); 1799 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n", 1800 data->chain_signal_b); 1801 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n", 1802 data->chain_signal_c); 1803 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n", 1804 data->beacon_count); 1805 1806 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t"); 1807 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { 1808 pos += scnprintf(buf + pos, bufsz - pos, " %u", 1809 data->disconn_array[cnt]); 1810 } 1811 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 1812 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t"); 1813 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) { 1814 pos += scnprintf(buf + pos, bufsz - pos, " %u", 1815 data->delta_gain_code[cnt]); 1816 } 1817 pos += scnprintf(buf + pos, bufsz - pos, "\n"); 1818 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n", 1819 data->radio_write); 1820 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n", 1821 data->state); 1822 1823 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1824 kfree(buf); 1825 return ret; 1826 } 1827 1828 static ssize_t iwl_dbgfs_power_save_status_read(struct file *file, 1829 char __user *user_buf, 1830 size_t count, loff_t *ppos) 1831 { 1832 struct iwl_priv *priv = file->private_data; 1833 char buf[60]; 1834 int pos = 0; 1835 const size_t bufsz = sizeof(buf); 1836 u32 pwrsave_status; 1837 1838 pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) & 1839 CSR_GP_REG_POWER_SAVE_STATUS_MSK; 1840 1841 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: "); 1842 pos += scnprintf(buf + pos, bufsz - pos, "%s\n", 1843 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" : 1844 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" : 1845 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" : 1846 "error"); 1847 1848 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1849 } 1850 1851 static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file, 1852 const char __user *user_buf, 1853 size_t count, loff_t *ppos) 1854 { 1855 struct iwl_priv *priv = file->private_data; 1856 char buf[8]; 1857 int buf_size; 1858 int clear; 1859 1860 memset(buf, 0, sizeof(buf)); 1861 buf_size = min(count, sizeof(buf) - 1); 1862 if (copy_from_user(buf, user_buf, buf_size)) 1863 return -EFAULT; 1864 if (sscanf(buf, "%d", &clear) != 1) 1865 return -EFAULT; 1866 1867 /* make request to uCode to retrieve statistics information */ 1868 mutex_lock(&priv->mutex); 1869 iwl_send_statistics_request(priv, 0, true); 1870 mutex_unlock(&priv->mutex); 1871 1872 return count; 1873 } 1874 1875 static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file, 1876 char __user *user_buf, 1877 size_t count, loff_t *ppos) { 1878 1879 struct iwl_priv *priv = file->private_data; 1880 int pos = 0; 1881 char buf[128]; 1882 const size_t bufsz = sizeof(buf); 1883 1884 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n", 1885 priv->event_log.ucode_trace ? "On" : "Off"); 1886 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n", 1887 priv->event_log.non_wraps_count); 1888 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n", 1889 priv->event_log.wraps_once_count); 1890 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n", 1891 priv->event_log.wraps_more_count); 1892 1893 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1894 } 1895 1896 static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file, 1897 const char __user *user_buf, 1898 size_t count, loff_t *ppos) 1899 { 1900 struct iwl_priv *priv = file->private_data; 1901 char buf[8]; 1902 int buf_size; 1903 int trace; 1904 1905 memset(buf, 0, sizeof(buf)); 1906 buf_size = min(count, sizeof(buf) - 1); 1907 if (copy_from_user(buf, user_buf, buf_size)) 1908 return -EFAULT; 1909 if (sscanf(buf, "%d", &trace) != 1) 1910 return -EFAULT; 1911 1912 if (trace) { 1913 priv->event_log.ucode_trace = true; 1914 if (iwl_is_alive(priv)) { 1915 /* start collecting data now */ 1916 mod_timer(&priv->ucode_trace, jiffies); 1917 } 1918 } else { 1919 priv->event_log.ucode_trace = false; 1920 del_timer_sync(&priv->ucode_trace); 1921 } 1922 1923 return count; 1924 } 1925 1926 static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file, 1927 char __user *user_buf, 1928 size_t count, loff_t *ppos) { 1929 1930 struct iwl_priv *priv = file->private_data; 1931 int len = 0; 1932 char buf[20]; 1933 1934 len = sprintf(buf, "0x%04X\n", 1935 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags)); 1936 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1937 } 1938 1939 static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file, 1940 char __user *user_buf, 1941 size_t count, loff_t *ppos) { 1942 1943 struct iwl_priv *priv = file->private_data; 1944 int len = 0; 1945 char buf[20]; 1946 1947 len = sprintf(buf, "0x%04X\n", 1948 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags)); 1949 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1950 } 1951 1952 static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file, 1953 char __user *user_buf, 1954 size_t count, loff_t *ppos) { 1955 1956 struct iwl_priv *priv = file->private_data; 1957 int pos = 0; 1958 char buf[12]; 1959 const size_t bufsz = sizeof(buf); 1960 1961 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", 1962 priv->missed_beacon_threshold); 1963 1964 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 1965 } 1966 1967 static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file, 1968 const char __user *user_buf, 1969 size_t count, loff_t *ppos) 1970 { 1971 struct iwl_priv *priv = file->private_data; 1972 char buf[8]; 1973 int buf_size; 1974 int missed; 1975 1976 memset(buf, 0, sizeof(buf)); 1977 buf_size = min(count, sizeof(buf) - 1); 1978 if (copy_from_user(buf, user_buf, buf_size)) 1979 return -EFAULT; 1980 if (sscanf(buf, "%d", &missed) != 1) 1981 return -EINVAL; 1982 1983 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN || 1984 missed > IWL_MISSED_BEACON_THRESHOLD_MAX) 1985 priv->missed_beacon_threshold = 1986 IWL_MISSED_BEACON_THRESHOLD_DEF; 1987 else 1988 priv->missed_beacon_threshold = missed; 1989 1990 return count; 1991 } 1992 1993 static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file, 1994 char __user *user_buf, 1995 size_t count, loff_t *ppos) { 1996 1997 struct iwl_priv *priv = file->private_data; 1998 int pos = 0; 1999 char buf[12]; 2000 const size_t bufsz = sizeof(buf); 2001 2002 pos += scnprintf(buf + pos, bufsz - pos, "%u\n", 2003 priv->plcp_delta_threshold); 2004 2005 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2006 } 2007 2008 static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file, 2009 const char __user *user_buf, 2010 size_t count, loff_t *ppos) { 2011 2012 struct iwl_priv *priv = file->private_data; 2013 char buf[8]; 2014 int buf_size; 2015 int plcp; 2016 2017 memset(buf, 0, sizeof(buf)); 2018 buf_size = min(count, sizeof(buf) - 1); 2019 if (copy_from_user(buf, user_buf, buf_size)) 2020 return -EFAULT; 2021 if (sscanf(buf, "%d", &plcp) != 1) 2022 return -EINVAL; 2023 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) || 2024 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX)) 2025 priv->plcp_delta_threshold = 2026 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE; 2027 else 2028 priv->plcp_delta_threshold = plcp; 2029 return count; 2030 } 2031 2032 static ssize_t iwl_dbgfs_rf_reset_read(struct file *file, 2033 char __user *user_buf, 2034 size_t count, loff_t *ppos) 2035 { 2036 struct iwl_priv *priv = file->private_data; 2037 int pos = 0; 2038 char buf[300]; 2039 const size_t bufsz = sizeof(buf); 2040 struct iwl_rf_reset *rf_reset = &priv->rf_reset; 2041 2042 pos += scnprintf(buf + pos, bufsz - pos, 2043 "RF reset statistics\n"); 2044 pos += scnprintf(buf + pos, bufsz - pos, 2045 "\tnumber of reset request: %d\n", 2046 rf_reset->reset_request_count); 2047 pos += scnprintf(buf + pos, bufsz - pos, 2048 "\tnumber of reset request success: %d\n", 2049 rf_reset->reset_success_count); 2050 pos += scnprintf(buf + pos, bufsz - pos, 2051 "\tnumber of reset request reject: %d\n", 2052 rf_reset->reset_reject_count); 2053 2054 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2055 } 2056 2057 static ssize_t iwl_dbgfs_rf_reset_write(struct file *file, 2058 const char __user *user_buf, 2059 size_t count, loff_t *ppos) { 2060 2061 struct iwl_priv *priv = file->private_data; 2062 int ret; 2063 2064 ret = iwl_force_rf_reset(priv, true); 2065 return ret ? ret : count; 2066 } 2067 2068 static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file, 2069 const char __user *user_buf, 2070 size_t count, loff_t *ppos) { 2071 2072 struct iwl_priv *priv = file->private_data; 2073 char buf[8]; 2074 int buf_size; 2075 int flush; 2076 2077 memset(buf, 0, sizeof(buf)); 2078 buf_size = min(count, sizeof(buf) - 1); 2079 if (copy_from_user(buf, user_buf, buf_size)) 2080 return -EFAULT; 2081 if (sscanf(buf, "%d", &flush) != 1) 2082 return -EINVAL; 2083 2084 if (iwl_is_rfkill(priv)) 2085 return -EFAULT; 2086 2087 iwlagn_dev_txfifo_flush(priv); 2088 2089 return count; 2090 } 2091 2092 static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file, 2093 char __user *user_buf, 2094 size_t count, loff_t *ppos) { 2095 2096 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 2097 int pos = 0; 2098 char buf[200]; 2099 const size_t bufsz = sizeof(buf); 2100 2101 if (!priv->bt_enable_flag) { 2102 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n"); 2103 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2104 } 2105 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n", 2106 priv->bt_enable_flag); 2107 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n", 2108 priv->bt_full_concurrent ? "full concurrency" : "3-wire"); 2109 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, " 2110 "last traffic notif: %d\n", 2111 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load); 2112 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, " 2113 "kill_ack_mask: %x, kill_cts_mask: %x\n", 2114 priv->bt_ch_announce, priv->kill_ack_mask, 2115 priv->kill_cts_mask); 2116 2117 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: "); 2118 switch (priv->bt_traffic_load) { 2119 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: 2120 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n"); 2121 break; 2122 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH: 2123 pos += scnprintf(buf + pos, bufsz - pos, "High\n"); 2124 break; 2125 case IWL_BT_COEX_TRAFFIC_LOAD_LOW: 2126 pos += scnprintf(buf + pos, bufsz - pos, "Low\n"); 2127 break; 2128 case IWL_BT_COEX_TRAFFIC_LOAD_NONE: 2129 default: 2130 pos += scnprintf(buf + pos, bufsz - pos, "None\n"); 2131 break; 2132 } 2133 2134 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2135 } 2136 2137 static ssize_t iwl_dbgfs_protection_mode_read(struct file *file, 2138 char __user *user_buf, 2139 size_t count, loff_t *ppos) 2140 { 2141 struct iwl_priv *priv = (struct iwl_priv *)file->private_data; 2142 2143 int pos = 0; 2144 char buf[40]; 2145 const size_t bufsz = sizeof(buf); 2146 2147 if (priv->cfg->ht_params) 2148 pos += scnprintf(buf + pos, bufsz - pos, 2149 "use %s for aggregation\n", 2150 (priv->hw_params.use_rts_for_aggregation) ? 2151 "rts/cts" : "cts-to-self"); 2152 else 2153 pos += scnprintf(buf + pos, bufsz - pos, "N/A"); 2154 2155 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2156 } 2157 2158 static ssize_t iwl_dbgfs_protection_mode_write(struct file *file, 2159 const char __user *user_buf, 2160 size_t count, loff_t *ppos) { 2161 2162 struct iwl_priv *priv = file->private_data; 2163 char buf[8]; 2164 int buf_size; 2165 int rts; 2166 2167 if (!priv->cfg->ht_params) 2168 return -EINVAL; 2169 2170 memset(buf, 0, sizeof(buf)); 2171 buf_size = min(count, sizeof(buf) - 1); 2172 if (copy_from_user(buf, user_buf, buf_size)) 2173 return -EFAULT; 2174 if (sscanf(buf, "%d", &rts) != 1) 2175 return -EINVAL; 2176 if (rts) 2177 priv->hw_params.use_rts_for_aggregation = true; 2178 else 2179 priv->hw_params.use_rts_for_aggregation = false; 2180 return count; 2181 } 2182 2183 static int iwl_cmd_echo_test(struct iwl_priv *priv) 2184 { 2185 int ret; 2186 struct iwl_host_cmd cmd = { 2187 .id = REPLY_ECHO, 2188 .len = { 0 }, 2189 }; 2190 2191 ret = iwl_dvm_send_cmd(priv, &cmd); 2192 if (ret) 2193 IWL_ERR(priv, "echo testing fail: 0X%x\n", ret); 2194 else 2195 IWL_DEBUG_INFO(priv, "echo testing pass\n"); 2196 return ret; 2197 } 2198 2199 static ssize_t iwl_dbgfs_echo_test_write(struct file *file, 2200 const char __user *user_buf, 2201 size_t count, loff_t *ppos) 2202 { 2203 struct iwl_priv *priv = file->private_data; 2204 char buf[8]; 2205 int buf_size; 2206 2207 memset(buf, 0, sizeof(buf)); 2208 buf_size = min(count, sizeof(buf) - 1); 2209 if (copy_from_user(buf, user_buf, buf_size)) 2210 return -EFAULT; 2211 2212 iwl_cmd_echo_test(priv); 2213 return count; 2214 } 2215 2216 #ifdef CONFIG_IWLWIFI_DEBUG 2217 static ssize_t iwl_dbgfs_log_event_read(struct file *file, 2218 char __user *user_buf, 2219 size_t count, loff_t *ppos) 2220 { 2221 struct iwl_priv *priv = file->private_data; 2222 char *buf = NULL; 2223 ssize_t ret; 2224 2225 ret = iwl_dump_nic_event_log(priv, true, &buf); 2226 if (ret > 0) 2227 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 2228 kfree(buf); 2229 return ret; 2230 } 2231 2232 static ssize_t iwl_dbgfs_log_event_write(struct file *file, 2233 const char __user *user_buf, 2234 size_t count, loff_t *ppos) 2235 { 2236 struct iwl_priv *priv = file->private_data; 2237 u32 event_log_flag; 2238 char buf[8]; 2239 int buf_size; 2240 2241 /* check that the interface is up */ 2242 if (!iwl_is_ready(priv)) 2243 return -EAGAIN; 2244 2245 memset(buf, 0, sizeof(buf)); 2246 buf_size = min(count, sizeof(buf) - 1); 2247 if (copy_from_user(buf, user_buf, buf_size)) 2248 return -EFAULT; 2249 if (sscanf(buf, "%d", &event_log_flag) != 1) 2250 return -EFAULT; 2251 if (event_log_flag == 1) 2252 iwl_dump_nic_event_log(priv, true, NULL); 2253 2254 return count; 2255 } 2256 #endif 2257 2258 static ssize_t iwl_dbgfs_calib_disabled_read(struct file *file, 2259 char __user *user_buf, 2260 size_t count, loff_t *ppos) 2261 { 2262 struct iwl_priv *priv = file->private_data; 2263 char buf[120]; 2264 int pos = 0; 2265 const size_t bufsz = sizeof(buf); 2266 2267 pos += scnprintf(buf + pos, bufsz - pos, 2268 "Sensitivity calibrations %s\n", 2269 (priv->calib_disabled & 2270 IWL_SENSITIVITY_CALIB_DISABLED) ? 2271 "DISABLED" : "ENABLED"); 2272 pos += scnprintf(buf + pos, bufsz - pos, 2273 "Chain noise calibrations %s\n", 2274 (priv->calib_disabled & 2275 IWL_CHAIN_NOISE_CALIB_DISABLED) ? 2276 "DISABLED" : "ENABLED"); 2277 pos += scnprintf(buf + pos, bufsz - pos, 2278 "Tx power calibrations %s\n", 2279 (priv->calib_disabled & 2280 IWL_TX_POWER_CALIB_DISABLED) ? 2281 "DISABLED" : "ENABLED"); 2282 2283 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 2284 } 2285 2286 static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file, 2287 const char __user *user_buf, 2288 size_t count, loff_t *ppos) 2289 { 2290 struct iwl_priv *priv = file->private_data; 2291 char buf[8]; 2292 u32 calib_disabled; 2293 int buf_size; 2294 2295 memset(buf, 0, sizeof(buf)); 2296 buf_size = min(count, sizeof(buf) - 1); 2297 if (copy_from_user(buf, user_buf, buf_size)) 2298 return -EFAULT; 2299 if (sscanf(buf, "%x", &calib_disabled) != 1) 2300 return -EFAULT; 2301 2302 priv->calib_disabled = calib_disabled; 2303 2304 return count; 2305 } 2306 2307 static ssize_t iwl_dbgfs_fw_restart_write(struct file *file, 2308 const char __user *user_buf, 2309 size_t count, loff_t *ppos) 2310 { 2311 struct iwl_priv *priv = file->private_data; 2312 bool restart_fw = iwlwifi_mod_params.restart_fw; 2313 int __maybe_unused ret; 2314 2315 iwlwifi_mod_params.restart_fw = true; 2316 2317 mutex_lock(&priv->mutex); 2318 2319 /* take the return value to make compiler happy - it will fail anyway */ 2320 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_ERROR, 0, 0, NULL); 2321 2322 mutex_unlock(&priv->mutex); 2323 2324 iwlwifi_mod_params.restart_fw = restart_fw; 2325 2326 return count; 2327 } 2328 2329 DEBUGFS_READ_FILE_OPS(ucode_rx_stats); 2330 DEBUGFS_READ_FILE_OPS(ucode_tx_stats); 2331 DEBUGFS_READ_FILE_OPS(ucode_general_stats); 2332 DEBUGFS_READ_FILE_OPS(sensitivity); 2333 DEBUGFS_READ_FILE_OPS(chain_noise); 2334 DEBUGFS_READ_FILE_OPS(power_save_status); 2335 DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics); 2336 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing); 2337 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon); 2338 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta); 2339 DEBUGFS_READ_WRITE_FILE_OPS(rf_reset); 2340 DEBUGFS_READ_FILE_OPS(rxon_flags); 2341 DEBUGFS_READ_FILE_OPS(rxon_filter_flags); 2342 DEBUGFS_WRITE_FILE_OPS(txfifo_flush); 2343 DEBUGFS_READ_FILE_OPS(ucode_bt_stats); 2344 DEBUGFS_READ_FILE_OPS(bt_traffic); 2345 DEBUGFS_READ_WRITE_FILE_OPS(protection_mode); 2346 DEBUGFS_READ_FILE_OPS(reply_tx_error); 2347 DEBUGFS_WRITE_FILE_OPS(echo_test); 2348 DEBUGFS_WRITE_FILE_OPS(fw_restart); 2349 #ifdef CONFIG_IWLWIFI_DEBUG 2350 DEBUGFS_READ_WRITE_FILE_OPS(log_event); 2351 #endif 2352 DEBUGFS_READ_WRITE_FILE_OPS(calib_disabled); 2353 2354 /* 2355 * Create the debugfs files and directories 2356 * 2357 */ 2358 int iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir) 2359 { 2360 struct dentry *dir_data, *dir_rf, *dir_debug; 2361 2362 priv->debugfs_dir = dbgfs_dir; 2363 2364 dir_data = debugfs_create_dir("data", dbgfs_dir); 2365 if (!dir_data) 2366 goto err; 2367 dir_rf = debugfs_create_dir("rf", dbgfs_dir); 2368 if (!dir_rf) 2369 goto err; 2370 dir_debug = debugfs_create_dir("debug", dbgfs_dir); 2371 if (!dir_debug) 2372 goto err; 2373 2374 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR); 2375 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR); 2376 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR); 2377 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR); 2378 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR); 2379 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR); 2380 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR); 2381 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR); 2382 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR); 2383 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR); 2384 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR); 2385 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR); 2386 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR); 2387 2388 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR); 2389 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR); 2390 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR); 2391 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR); 2392 DEBUGFS_ADD_FILE(rf_reset, dir_debug, S_IWUSR | S_IRUSR); 2393 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR); 2394 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR); 2395 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR); 2396 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR); 2397 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR); 2398 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR); 2399 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR); 2400 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR); 2401 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR); 2402 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR); 2403 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR); 2404 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR); 2405 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR); 2406 DEBUGFS_ADD_FILE(fw_restart, dir_debug, S_IWUSR); 2407 #ifdef CONFIG_IWLWIFI_DEBUG 2408 DEBUGFS_ADD_FILE(log_event, dir_debug, S_IWUSR | S_IRUSR); 2409 #endif 2410 2411 if (iwl_advanced_bt_coexist(priv)) 2412 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR); 2413 2414 /* Calibrations disabled/enabled status*/ 2415 DEBUGFS_ADD_FILE(calib_disabled, dir_rf, S_IWUSR | S_IRUSR); 2416 2417 /* 2418 * Create a symlink with mac80211. This is not very robust, as it does 2419 * not remove the symlink created. The implicit assumption is that 2420 * when the opmode exits, mac80211 will also exit, and will remove 2421 * this symlink as part of its cleanup. 2422 */ 2423 if (priv->mac80211_registered) { 2424 char buf[100]; 2425 struct dentry *mac80211_dir, *dev_dir; 2426 2427 dev_dir = dbgfs_dir->d_parent; 2428 mac80211_dir = priv->hw->wiphy->debugfsdir; 2429 2430 snprintf(buf, 100, "../../%pd2", dev_dir); 2431 2432 if (!debugfs_create_symlink("iwlwifi", mac80211_dir, buf)) 2433 goto err; 2434 } 2435 2436 return 0; 2437 2438 err: 2439 IWL_ERR(priv, "failed to create the dvm debugfs entries\n"); 2440 return -ENOMEM; 2441 } 2442