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