Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
| 8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
| 33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | #include "mvm.h" |
| 64 | #include "sta.h" |
| 65 | #include "iwl-io.h" |
| 66 | |
| 67 | struct iwl_dbgfs_mvm_ctx { |
| 68 | struct iwl_mvm *mvm; |
| 69 | struct ieee80211_vif *vif; |
| 70 | }; |
| 71 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 72 | static ssize_t iwl_dbgfs_tx_flush_write(struct file *file, |
| 73 | const char __user *user_buf, |
| 74 | size_t count, loff_t *ppos) |
| 75 | { |
| 76 | struct iwl_mvm *mvm = file->private_data; |
| 77 | |
| 78 | char buf[16]; |
| 79 | int buf_size, ret; |
| 80 | u32 scd_q_msk; |
| 81 | |
| 82 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 83 | return -EIO; |
| 84 | |
| 85 | memset(buf, 0, sizeof(buf)); |
| 86 | buf_size = min(count, sizeof(buf) - 1); |
| 87 | if (copy_from_user(buf, user_buf, buf_size)) |
| 88 | return -EFAULT; |
| 89 | |
| 90 | if (sscanf(buf, "%x", &scd_q_msk) != 1) |
| 91 | return -EINVAL; |
| 92 | |
| 93 | IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk); |
| 94 | |
| 95 | mutex_lock(&mvm->mutex); |
| 96 | ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count; |
| 97 | mutex_unlock(&mvm->mutex); |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static ssize_t iwl_dbgfs_sta_drain_write(struct file *file, |
| 103 | const char __user *user_buf, |
| 104 | size_t count, loff_t *ppos) |
| 105 | { |
| 106 | struct iwl_mvm *mvm = file->private_data; |
| 107 | struct ieee80211_sta *sta; |
| 108 | |
| 109 | char buf[8]; |
| 110 | int buf_size, sta_id, drain, ret; |
| 111 | |
| 112 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 113 | return -EIO; |
| 114 | |
| 115 | memset(buf, 0, sizeof(buf)); |
| 116 | buf_size = min(count, sizeof(buf) - 1); |
| 117 | if (copy_from_user(buf, user_buf, buf_size)) |
| 118 | return -EFAULT; |
| 119 | |
| 120 | if (sscanf(buf, "%d %d", &sta_id, &drain) != 2) |
| 121 | return -EINVAL; |
| 122 | |
| 123 | mutex_lock(&mvm->mutex); |
| 124 | |
| 125 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 126 | lockdep_is_held(&mvm->mutex)); |
| 127 | if (IS_ERR_OR_NULL(sta)) |
| 128 | ret = -ENOENT; |
| 129 | else |
| 130 | ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? : |
| 131 | count; |
| 132 | |
| 133 | mutex_unlock(&mvm->mutex); |
| 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, |
| 139 | size_t count, loff_t *ppos) |
| 140 | { |
| 141 | struct iwl_mvm *mvm = file->private_data; |
| 142 | const struct fw_img *img; |
| 143 | int ofs, len, pos = 0; |
| 144 | size_t bufsz, ret; |
| 145 | char *buf; |
| 146 | u8 *ptr; |
| 147 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 148 | if (!mvm->ucode_loaded) |
| 149 | return -EINVAL; |
| 150 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 151 | /* default is to dump the entire data segment */ |
| 152 | if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 153 | img = &mvm->fw->img[mvm->cur_ucode]; |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 154 | ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 155 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 156 | } else { |
| 157 | ofs = mvm->dbgfs_sram_offset; |
| 158 | len = mvm->dbgfs_sram_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 160 | |
| 161 | bufsz = len * 4 + 256; |
| 162 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 163 | if (!buf) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | ptr = kzalloc(len, GFP_KERNEL); |
| 167 | if (!ptr) { |
| 168 | kfree(buf); |
| 169 | return -ENOMEM; |
| 170 | } |
| 171 | |
| 172 | pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len); |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 173 | pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 174 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 175 | iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 176 | for (ofs = 0; ofs < len; ofs += 16) { |
| 177 | pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs); |
| 178 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, |
| 179 | bufsz - pos, false); |
| 180 | pos += strlen(buf + pos); |
| 181 | if (bufsz - pos > 0) |
| 182 | buf[pos++] = '\n'; |
| 183 | } |
| 184 | |
| 185 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 186 | |
| 187 | kfree(buf); |
| 188 | kfree(ptr); |
| 189 | |
| 190 | return ret; |
| 191 | } |
| 192 | |
| 193 | static ssize_t iwl_dbgfs_sram_write(struct file *file, |
| 194 | const char __user *user_buf, size_t count, |
| 195 | loff_t *ppos) |
| 196 | { |
| 197 | struct iwl_mvm *mvm = file->private_data; |
| 198 | char buf[64]; |
| 199 | int buf_size; |
| 200 | u32 offset, len; |
| 201 | |
| 202 | memset(buf, 0, sizeof(buf)); |
| 203 | buf_size = min(count, sizeof(buf) - 1); |
| 204 | if (copy_from_user(buf, user_buf, buf_size)) |
| 205 | return -EFAULT; |
| 206 | |
| 207 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { |
| 208 | if ((offset & 0x3) || (len & 0x3)) |
| 209 | return -EINVAL; |
| 210 | mvm->dbgfs_sram_offset = offset; |
| 211 | mvm->dbgfs_sram_len = len; |
| 212 | } else { |
| 213 | mvm->dbgfs_sram_offset = 0; |
| 214 | mvm->dbgfs_sram_len = 0; |
| 215 | } |
| 216 | |
| 217 | return count; |
| 218 | } |
| 219 | |
| 220 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, |
| 221 | size_t count, loff_t *ppos) |
| 222 | { |
| 223 | struct iwl_mvm *mvm = file->private_data; |
| 224 | struct ieee80211_sta *sta; |
| 225 | char buf[400]; |
| 226 | int i, pos = 0, bufsz = sizeof(buf); |
| 227 | |
| 228 | mutex_lock(&mvm->mutex); |
| 229 | |
| 230 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 231 | pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); |
| 232 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 233 | lockdep_is_held(&mvm->mutex)); |
| 234 | if (!sta) |
| 235 | pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); |
| 236 | else if (IS_ERR(sta)) |
| 237 | pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", |
| 238 | PTR_ERR(sta)); |
| 239 | else |
| 240 | pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", |
| 241 | sta->addr); |
| 242 | } |
| 243 | |
| 244 | mutex_unlock(&mvm->mutex); |
| 245 | |
| 246 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 247 | } |
| 248 | |
| 249 | static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file, |
| 250 | const char __user *user_buf, |
| 251 | size_t count, loff_t *ppos) |
| 252 | { |
| 253 | struct iwl_mvm *mvm = file->private_data; |
| 254 | char buf[8] = {}; |
| 255 | int allow; |
| 256 | |
| 257 | if (!mvm->ucode_loaded) |
| 258 | return -EIO; |
| 259 | |
| 260 | if (copy_from_user(buf, user_buf, sizeof(buf))) |
| 261 | return -EFAULT; |
| 262 | |
| 263 | if (sscanf(buf, "%d", &allow) != 1) |
| 264 | return -EINVAL; |
| 265 | |
| 266 | IWL_DEBUG_POWER(mvm, "%s device power down\n", |
| 267 | allow ? "allow" : "prevent"); |
| 268 | |
| 269 | /* |
| 270 | * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it |
| 271 | */ |
| 272 | |
| 273 | return count; |
| 274 | } |
| 275 | |
| 276 | static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file, |
| 277 | const char __user *user_buf, |
| 278 | size_t count, loff_t *ppos) |
| 279 | { |
| 280 | struct iwl_mvm *mvm = file->private_data; |
| 281 | char buf[8] = {}; |
| 282 | int allow; |
| 283 | |
| 284 | if (copy_from_user(buf, user_buf, sizeof(buf))) |
| 285 | return -EFAULT; |
| 286 | |
| 287 | if (sscanf(buf, "%d", &allow) != 1) |
| 288 | return -EINVAL; |
| 289 | |
| 290 | IWL_DEBUG_POWER(mvm, "%s device power down in d3\n", |
| 291 | allow ? "allow" : "prevent"); |
| 292 | |
| 293 | /* |
| 294 | * TODO: When WoWLAN FW alive notification happens, driver will send |
| 295 | * REPLY_DEBUG_CMD setting power_down_allow flag according to |
| 296 | * mvm->prevent_power_down_d3 |
| 297 | */ |
| 298 | mvm->prevent_power_down_d3 = !allow; |
| 299 | |
| 300 | return count; |
| 301 | } |
| 302 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 303 | static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm, |
| 304 | struct ieee80211_vif *vif, |
| 305 | enum iwl_dbgfs_pm_mask param, int val) |
| 306 | { |
| 307 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 308 | struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm; |
| 309 | |
| 310 | dbgfs_pm->mask |= param; |
| 311 | |
| 312 | switch (param) { |
| 313 | case MVM_DEBUGFS_PM_KEEP_ALIVE: { |
| 314 | struct ieee80211_hw *hw = mvm->hw; |
| 315 | int dtimper = hw->conf.ps_dtim_period ?: 1; |
| 316 | int dtimper_msec = dtimper * vif->bss_conf.beacon_int; |
| 317 | |
| 318 | IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val); |
| 319 | if (val * MSEC_PER_SEC < 3 * dtimper_msec) { |
| 320 | IWL_WARN(mvm, |
| 321 | "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n", |
| 322 | val * MSEC_PER_SEC, 3 * dtimper_msec); |
| 323 | } |
| 324 | dbgfs_pm->keep_alive_seconds = val; |
| 325 | break; |
| 326 | } |
| 327 | case MVM_DEBUGFS_PM_SKIP_OVER_DTIM: |
| 328 | IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n", |
| 329 | val ? "enabled" : "disabled"); |
| 330 | dbgfs_pm->skip_over_dtim = val; |
| 331 | break; |
| 332 | case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS: |
| 333 | IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val); |
| 334 | dbgfs_pm->skip_dtim_periods = val; |
| 335 | break; |
| 336 | case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT: |
| 337 | IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val); |
| 338 | dbgfs_pm->rx_data_timeout = val; |
| 339 | break; |
| 340 | case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT: |
| 341 | IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val); |
| 342 | dbgfs_pm->tx_data_timeout = val; |
| 343 | break; |
| 344 | case MVM_DEBUGFS_PM_DISABLE_POWER_OFF: |
| 345 | IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val); |
| 346 | dbgfs_pm->disable_power_off = val; |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | static ssize_t iwl_dbgfs_pm_params_write(struct file *file, |
| 352 | const char __user *user_buf, |
| 353 | size_t count, loff_t *ppos) |
| 354 | { |
| 355 | struct ieee80211_vif *vif = file->private_data; |
| 356 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 357 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; |
| 358 | enum iwl_dbgfs_pm_mask param; |
| 359 | char buf[32] = {}; |
| 360 | int val; |
| 361 | int ret; |
| 362 | |
| 363 | if (copy_from_user(buf, user_buf, sizeof(buf))) |
| 364 | return -EFAULT; |
| 365 | |
| 366 | if (!strncmp("keep_alive=", buf, 11)) { |
| 367 | if (sscanf(buf + 11, "%d", &val) != 1) |
| 368 | return -EINVAL; |
| 369 | param = MVM_DEBUGFS_PM_KEEP_ALIVE; |
| 370 | } else if (!strncmp("skip_over_dtim=", buf, 15)) { |
| 371 | if (sscanf(buf + 15, "%d", &val) != 1) |
| 372 | return -EINVAL; |
| 373 | param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM; |
| 374 | } else if (!strncmp("skip_dtim_periods=", buf, 18)) { |
| 375 | if (sscanf(buf + 18, "%d", &val) != 1) |
| 376 | return -EINVAL; |
| 377 | param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS; |
| 378 | } else if (!strncmp("rx_data_timeout=", buf, 16)) { |
| 379 | if (sscanf(buf + 16, "%d", &val) != 1) |
| 380 | return -EINVAL; |
| 381 | param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT; |
| 382 | } else if (!strncmp("tx_data_timeout=", buf, 16)) { |
| 383 | if (sscanf(buf + 16, "%d", &val) != 1) |
| 384 | return -EINVAL; |
| 385 | param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT; |
| 386 | } else if (!strncmp("disable_power_off=", buf, 18)) { |
| 387 | if (sscanf(buf + 18, "%d", &val) != 1) |
| 388 | return -EINVAL; |
| 389 | param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF; |
| 390 | } else { |
| 391 | return -EINVAL; |
| 392 | } |
| 393 | |
| 394 | mutex_lock(&mvm->mutex); |
| 395 | iwl_dbgfs_update_pm(mvm, vif, param, val); |
| 396 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 397 | mutex_unlock(&mvm->mutex); |
| 398 | |
| 399 | return ret ?: count; |
| 400 | } |
| 401 | |
| 402 | static ssize_t iwl_dbgfs_pm_params_read(struct file *file, |
| 403 | char __user *user_buf, |
| 404 | size_t count, loff_t *ppos) |
| 405 | { |
| 406 | struct ieee80211_vif *vif = file->private_data; |
| 407 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 408 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; |
| 409 | struct iwl_powertable_cmd cmd = {}; |
| 410 | char buf[256]; |
| 411 | int bufsz = sizeof(buf); |
| 412 | int pos = 0; |
| 413 | |
| 414 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
| 415 | |
| 416 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n", |
| 417 | (cmd.flags & |
| 418 | cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ? |
| 419 | 0 : 1); |
| 420 | pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n", |
| 421 | le32_to_cpu(cmd.skip_dtim_periods)); |
| 422 | pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n", |
| 423 | iwlmvm_mod_params.power_scheme); |
| 424 | pos += scnprintf(buf+pos, bufsz-pos, "flags = %d\n", |
| 425 | le16_to_cpu(cmd.flags)); |
| 426 | pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n", |
| 427 | cmd.keep_alive_seconds); |
| 428 | |
| 429 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) { |
| 430 | pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n", |
| 431 | (cmd.flags & |
| 432 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? |
| 433 | 1 : 0); |
| 434 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n", |
| 435 | le32_to_cpu(cmd.rx_data_timeout)); |
| 436 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n", |
| 437 | le32_to_cpu(cmd.tx_data_timeout)); |
| 438 | } |
| 439 | |
| 440 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 441 | } |
| 442 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 443 | static ssize_t iwl_dbgfs_mac_params_read(struct file *file, |
| 444 | char __user *user_buf, |
| 445 | size_t count, loff_t *ppos) |
| 446 | { |
| 447 | struct ieee80211_vif *vif = file->private_data; |
| 448 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 449 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; |
| 450 | u8 ap_sta_id; |
| 451 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 452 | char buf[512]; |
| 453 | int bufsz = sizeof(buf); |
| 454 | int pos = 0; |
| 455 | int i; |
| 456 | |
| 457 | mutex_lock(&mvm->mutex); |
| 458 | |
| 459 | ap_sta_id = mvmvif->ap_sta_id; |
| 460 | |
| 461 | pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n", |
| 462 | mvmvif->id, mvmvif->color); |
| 463 | pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n", |
| 464 | vif->bss_conf.bssid); |
| 465 | pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n"); |
| 466 | for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) { |
| 467 | pos += scnprintf(buf+pos, bufsz-pos, |
| 468 | "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n", |
| 469 | i, mvmvif->queue_params[i].txop, |
| 470 | mvmvif->queue_params[i].cw_min, |
| 471 | mvmvif->queue_params[i].cw_max, |
| 472 | mvmvif->queue_params[i].aifs, |
| 473 | mvmvif->queue_params[i].uapsd); |
| 474 | } |
| 475 | |
Emmanuel Grumbach | 2b76ef1 | 2013-01-24 10:35:13 +0200 | [diff] [blame] | 476 | if (vif->type == NL80211_IFTYPE_STATION && |
| 477 | ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 478 | struct ieee80211_sta *sta; |
| 479 | struct iwl_mvm_sta *mvm_sta; |
| 480 | |
| 481 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id], |
| 482 | lockdep_is_held(&mvm->mutex)); |
| 483 | mvm_sta = (void *)sta->drv_priv; |
| 484 | pos += scnprintf(buf+pos, bufsz-pos, |
| 485 | "ap_sta_id %d - reduced Tx power %d\n", |
| 486 | ap_sta_id, mvm_sta->bt_reduced_txpower); |
| 487 | } |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 488 | |
| 489 | rcu_read_lock(); |
| 490 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 491 | if (chanctx_conf) { |
| 492 | pos += scnprintf(buf+pos, bufsz-pos, |
| 493 | "idle rx chains %d, active rx chains: %d\n", |
| 494 | chanctx_conf->rx_chains_static, |
| 495 | chanctx_conf->rx_chains_dynamic); |
| 496 | } |
| 497 | rcu_read_unlock(); |
| 498 | |
| 499 | mutex_unlock(&mvm->mutex); |
| 500 | |
| 501 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 502 | } |
| 503 | |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 504 | #define BT_MBOX_MSG(_notif, _num, _field) \ |
| 505 | ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\ |
| 506 | >> BT_MBOX##_num##_##_field##_POS) |
| 507 | |
| 508 | |
| 509 | #define BT_MBOX_PRINT(_num, _field, _end) \ |
| 510 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 511 | "\t%s: %d%s", \ |
| 512 | #_field, \ |
| 513 | BT_MBOX_MSG(notif, _num, _field), \ |
| 514 | true ? "\n" : ", "); |
| 515 | |
| 516 | static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, |
| 517 | size_t count, loff_t *ppos) |
| 518 | { |
| 519 | struct iwl_mvm *mvm = file->private_data; |
| 520 | struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; |
| 521 | char *buf; |
| 522 | int ret, pos = 0, bufsz = sizeof(char) * 1024; |
| 523 | |
| 524 | buf = kmalloc(bufsz, GFP_KERNEL); |
| 525 | if (!buf) |
| 526 | return -ENOMEM; |
| 527 | |
| 528 | mutex_lock(&mvm->mutex); |
| 529 | |
| 530 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); |
| 531 | |
| 532 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); |
| 533 | BT_MBOX_PRINT(0, LE_PROF1, false); |
| 534 | BT_MBOX_PRINT(0, LE_PROF2, false); |
| 535 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); |
| 536 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); |
| 537 | BT_MBOX_PRINT(0, INBAND_S, false); |
| 538 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); |
| 539 | BT_MBOX_PRINT(0, LE_SCAN, false); |
| 540 | BT_MBOX_PRINT(0, LE_ADV, false); |
| 541 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); |
| 542 | BT_MBOX_PRINT(0, OPEN_CON_1, true); |
| 543 | |
| 544 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); |
| 545 | |
| 546 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); |
| 547 | BT_MBOX_PRINT(1, IP_SR, false); |
| 548 | BT_MBOX_PRINT(1, LE_MSTR, false); |
| 549 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); |
| 550 | BT_MBOX_PRINT(1, MSG_TYPE, false); |
| 551 | BT_MBOX_PRINT(1, SSN, true); |
| 552 | |
| 553 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); |
| 554 | |
| 555 | BT_MBOX_PRINT(2, SNIFF_ACT, false); |
| 556 | BT_MBOX_PRINT(2, PAG, false); |
| 557 | BT_MBOX_PRINT(2, INQUIRY, false); |
| 558 | BT_MBOX_PRINT(2, CONN, false); |
| 559 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); |
| 560 | BT_MBOX_PRINT(2, DISC, false); |
| 561 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); |
| 562 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); |
| 563 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); |
| 564 | BT_MBOX_PRINT(2, SCO_DURATION, true); |
| 565 | |
| 566 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); |
| 567 | |
| 568 | BT_MBOX_PRINT(3, SCO_STATE, false); |
| 569 | BT_MBOX_PRINT(3, SNIFF_STATE, false); |
| 570 | BT_MBOX_PRINT(3, A2DP_STATE, false); |
| 571 | BT_MBOX_PRINT(3, ACL_STATE, false); |
| 572 | BT_MBOX_PRINT(3, MSTR_STATE, false); |
| 573 | BT_MBOX_PRINT(3, OBX_STATE, false); |
| 574 | BT_MBOX_PRINT(3, OPEN_CON_2, false); |
| 575 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); |
| 576 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); |
| 577 | BT_MBOX_PRINT(3, INBAND_P, false); |
| 578 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); |
| 579 | BT_MBOX_PRINT(3, SSN_2, false); |
| 580 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); |
| 581 | |
| 582 | pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n", |
| 583 | notif->bt_status); |
| 584 | pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n", |
| 585 | notif->bt_open_conn); |
| 586 | pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n", |
| 587 | notif->bt_traffic_load); |
| 588 | pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n", |
| 589 | notif->bt_agg_traffic_load); |
| 590 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", |
| 591 | notif->bt_ci_compliance); |
| 592 | |
| 593 | mutex_unlock(&mvm->mutex); |
| 594 | |
| 595 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 596 | kfree(buf); |
| 597 | |
| 598 | return ret; |
| 599 | } |
| 600 | #undef BT_MBOX_PRINT |
| 601 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 602 | static ssize_t iwl_dbgfs_fw_restart_write(struct file *file, |
| 603 | const char __user *user_buf, |
| 604 | size_t count, loff_t *ppos) |
| 605 | { |
| 606 | struct iwl_mvm *mvm = file->private_data; |
| 607 | bool restart_fw = iwlwifi_mod_params.restart_fw; |
| 608 | int ret; |
| 609 | |
| 610 | iwlwifi_mod_params.restart_fw = true; |
| 611 | |
| 612 | mutex_lock(&mvm->mutex); |
| 613 | |
| 614 | /* take the return value to make compiler happy - it will fail anyway */ |
| 615 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL); |
| 616 | |
| 617 | mutex_unlock(&mvm->mutex); |
| 618 | |
| 619 | iwlwifi_mod_params.restart_fw = restart_fw; |
| 620 | |
| 621 | return count; |
| 622 | } |
| 623 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 624 | static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif, |
| 625 | enum iwl_dbgfs_bf_mask param, int value) |
| 626 | { |
| 627 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 628 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; |
| 629 | |
| 630 | dbgfs_bf->mask |= param; |
| 631 | |
| 632 | switch (param) { |
| 633 | case MVM_DEBUGFS_BF_ENERGY_DELTA: |
| 634 | dbgfs_bf->bf_energy_delta = value; |
| 635 | break; |
| 636 | case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA: |
| 637 | dbgfs_bf->bf_roaming_energy_delta = value; |
| 638 | break; |
| 639 | case MVM_DEBUGFS_BF_ROAMING_STATE: |
| 640 | dbgfs_bf->bf_roaming_state = value; |
| 641 | break; |
| 642 | case MVM_DEBUGFS_BF_TEMPERATURE_DELTA: |
| 643 | dbgfs_bf->bf_temperature_delta = value; |
| 644 | break; |
| 645 | case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER: |
| 646 | dbgfs_bf->bf_enable_beacon_filter = value; |
| 647 | break; |
| 648 | case MVM_DEBUGFS_BF_DEBUG_FLAG: |
| 649 | dbgfs_bf->bf_debug_flag = value; |
| 650 | break; |
| 651 | case MVM_DEBUGFS_BF_ESCAPE_TIMER: |
| 652 | dbgfs_bf->bf_escape_timer = value; |
| 653 | break; |
| 654 | case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT: |
| 655 | dbgfs_bf->ba_enable_beacon_abort = value; |
| 656 | break; |
| 657 | case MVM_DEBUGFS_BA_ESCAPE_TIMER: |
| 658 | dbgfs_bf->ba_escape_timer = value; |
| 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | static ssize_t iwl_dbgfs_bf_params_write(struct file *file, |
| 664 | const char __user *user_buf, |
| 665 | size_t count, loff_t *ppos) |
| 666 | { |
| 667 | struct ieee80211_vif *vif = file->private_data; |
| 668 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 669 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; |
| 670 | enum iwl_dbgfs_bf_mask param; |
| 671 | char buf[256]; |
| 672 | int buf_size; |
| 673 | int value; |
| 674 | int ret = 0; |
| 675 | |
| 676 | memset(buf, 0, sizeof(buf)); |
| 677 | buf_size = min(count, sizeof(buf) - 1); |
| 678 | if (copy_from_user(buf, user_buf, buf_size)) |
| 679 | return -EFAULT; |
| 680 | |
| 681 | if (!strncmp("bf_energy_delta=", buf, 16)) { |
| 682 | if (sscanf(buf+16, "%d", &value) != 1) |
| 683 | return -EINVAL; |
| 684 | if (value < IWL_BF_ENERGY_DELTA_MIN || |
| 685 | value > IWL_BF_ENERGY_DELTA_MAX) |
| 686 | return -EINVAL; |
| 687 | param = MVM_DEBUGFS_BF_ENERGY_DELTA; |
| 688 | } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) { |
| 689 | if (sscanf(buf+24, "%d", &value) != 1) |
| 690 | return -EINVAL; |
| 691 | if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN || |
| 692 | value > IWL_BF_ROAMING_ENERGY_DELTA_MAX) |
| 693 | return -EINVAL; |
| 694 | param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA; |
| 695 | } else if (!strncmp("bf_roaming_state=", buf, 17)) { |
| 696 | if (sscanf(buf+17, "%d", &value) != 1) |
| 697 | return -EINVAL; |
| 698 | if (value < IWL_BF_ROAMING_STATE_MIN || |
| 699 | value > IWL_BF_ROAMING_STATE_MAX) |
| 700 | return -EINVAL; |
| 701 | param = MVM_DEBUGFS_BF_ROAMING_STATE; |
| 702 | } else if (!strncmp("bf_temperature_delta=", buf, 21)) { |
| 703 | if (sscanf(buf+21, "%d", &value) != 1) |
| 704 | return -EINVAL; |
| 705 | if (value < IWL_BF_TEMPERATURE_DELTA_MIN || |
| 706 | value > IWL_BF_TEMPERATURE_DELTA_MAX) |
| 707 | return -EINVAL; |
| 708 | param = MVM_DEBUGFS_BF_TEMPERATURE_DELTA; |
| 709 | } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) { |
| 710 | if (sscanf(buf+24, "%d", &value) != 1) |
| 711 | return -EINVAL; |
| 712 | if (value < 0 || value > 1) |
| 713 | return -EINVAL; |
| 714 | param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER; |
| 715 | } else if (!strncmp("bf_debug_flag=", buf, 14)) { |
| 716 | if (sscanf(buf+14, "%d", &value) != 1) |
| 717 | return -EINVAL; |
| 718 | if (value < 0 || value > 1) |
| 719 | return -EINVAL; |
| 720 | param = MVM_DEBUGFS_BF_DEBUG_FLAG; |
| 721 | } else if (!strncmp("bf_escape_timer=", buf, 16)) { |
| 722 | if (sscanf(buf+16, "%d", &value) != 1) |
| 723 | return -EINVAL; |
| 724 | if (value < IWL_BF_ESCAPE_TIMER_MIN || |
| 725 | value > IWL_BF_ESCAPE_TIMER_MAX) |
| 726 | return -EINVAL; |
| 727 | param = MVM_DEBUGFS_BF_ESCAPE_TIMER; |
| 728 | } else if (!strncmp("ba_escape_timer=", buf, 16)) { |
| 729 | if (sscanf(buf+16, "%d", &value) != 1) |
| 730 | return -EINVAL; |
| 731 | if (value < IWL_BA_ESCAPE_TIMER_MIN || |
| 732 | value > IWL_BA_ESCAPE_TIMER_MAX) |
| 733 | return -EINVAL; |
| 734 | param = MVM_DEBUGFS_BA_ESCAPE_TIMER; |
| 735 | } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) { |
| 736 | if (sscanf(buf+23, "%d", &value) != 1) |
| 737 | return -EINVAL; |
| 738 | if (value < 0 || value > 1) |
| 739 | return -EINVAL; |
| 740 | param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT; |
| 741 | } else { |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | |
| 745 | mutex_lock(&mvm->mutex); |
| 746 | iwl_dbgfs_update_bf(vif, param, value); |
| 747 | if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) { |
| 748 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); |
| 749 | } else { |
| 750 | if (mvmvif->bf_enabled) |
| 751 | ret = iwl_mvm_enable_beacon_filter(mvm, vif); |
| 752 | else |
| 753 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); |
| 754 | } |
| 755 | mutex_unlock(&mvm->mutex); |
| 756 | |
| 757 | return ret ?: count; |
| 758 | } |
| 759 | |
| 760 | static ssize_t iwl_dbgfs_bf_params_read(struct file *file, |
| 761 | char __user *user_buf, |
| 762 | size_t count, loff_t *ppos) |
| 763 | { |
| 764 | struct ieee80211_vif *vif = file->private_data; |
| 765 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 766 | char buf[256]; |
| 767 | int pos = 0; |
| 768 | const size_t bufsz = sizeof(buf); |
| 769 | struct iwl_beacon_filter_cmd cmd = { |
| 770 | .bf_energy_delta = IWL_BF_ENERGY_DELTA_DEFAULT, |
| 771 | .bf_roaming_energy_delta = IWL_BF_ROAMING_ENERGY_DELTA_DEFAULT, |
| 772 | .bf_roaming_state = IWL_BF_ROAMING_STATE_DEFAULT, |
| 773 | .bf_temperature_delta = IWL_BF_TEMPERATURE_DELTA_DEFAULT, |
| 774 | .bf_enable_beacon_filter = IWL_BF_ENABLE_BEACON_FILTER_DEFAULT, |
| 775 | .bf_debug_flag = IWL_BF_DEBUG_FLAG_DEFAULT, |
| 776 | .bf_escape_timer = cpu_to_le32(IWL_BF_ESCAPE_TIMER_DEFAULT), |
| 777 | .ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_DEFAULT), |
| 778 | .ba_enable_beacon_abort = IWL_BA_ENABLE_BEACON_ABORT_DEFAULT, |
| 779 | }; |
| 780 | |
| 781 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
| 782 | if (mvmvif->bf_enabled) |
| 783 | cmd.bf_enable_beacon_filter = 1; |
| 784 | else |
| 785 | cmd.bf_enable_beacon_filter = 0; |
| 786 | |
| 787 | pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n", |
| 788 | cmd.bf_energy_delta); |
| 789 | pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n", |
| 790 | cmd.bf_roaming_energy_delta); |
| 791 | pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n", |
| 792 | cmd.bf_roaming_state); |
| 793 | pos += scnprintf(buf+pos, bufsz-pos, "bf_temperature_delta = %d\n", |
| 794 | cmd.bf_temperature_delta); |
| 795 | pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n", |
| 796 | cmd.bf_enable_beacon_filter); |
| 797 | pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n", |
| 798 | cmd.bf_debug_flag); |
| 799 | pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n", |
| 800 | cmd.bf_escape_timer); |
| 801 | pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n", |
| 802 | cmd.ba_escape_timer); |
| 803 | pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n", |
| 804 | cmd.ba_enable_beacon_abort); |
| 805 | |
| 806 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 807 | } |
| 808 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 809 | #ifdef CONFIG_PM_SLEEP |
| 810 | static ssize_t iwl_dbgfs_d3_sram_write(struct file *file, |
| 811 | const char __user *user_buf, |
| 812 | size_t count, loff_t *ppos) |
| 813 | { |
| 814 | struct iwl_mvm *mvm = file->private_data; |
| 815 | char buf[8] = {}; |
| 816 | int store; |
| 817 | |
| 818 | if (copy_from_user(buf, user_buf, sizeof(buf))) |
| 819 | return -EFAULT; |
| 820 | |
| 821 | if (sscanf(buf, "%d", &store) != 1) |
| 822 | return -EINVAL; |
| 823 | |
| 824 | mvm->store_d3_resume_sram = store; |
| 825 | |
| 826 | return count; |
| 827 | } |
| 828 | |
| 829 | static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf, |
| 830 | size_t count, loff_t *ppos) |
| 831 | { |
| 832 | struct iwl_mvm *mvm = file->private_data; |
| 833 | const struct fw_img *img; |
| 834 | int ofs, len, pos = 0; |
| 835 | size_t bufsz, ret; |
| 836 | char *buf; |
| 837 | u8 *ptr = mvm->d3_resume_sram; |
| 838 | |
| 839 | img = &mvm->fw->img[IWL_UCODE_WOWLAN]; |
| 840 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 841 | |
| 842 | bufsz = len * 4 + 256; |
| 843 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 844 | if (!buf) |
| 845 | return -ENOMEM; |
| 846 | |
| 847 | pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n", |
| 848 | mvm->store_d3_resume_sram ? "en" : "dis"); |
| 849 | |
| 850 | if (ptr) { |
| 851 | for (ofs = 0; ofs < len; ofs += 16) { |
| 852 | pos += scnprintf(buf + pos, bufsz - pos, |
| 853 | "0x%.4x ", ofs); |
| 854 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, |
| 855 | bufsz - pos, false); |
| 856 | pos += strlen(buf + pos); |
| 857 | if (bufsz - pos > 0) |
| 858 | buf[pos++] = '\n'; |
| 859 | } |
| 860 | } else { |
| 861 | pos += scnprintf(buf + pos, bufsz - pos, |
| 862 | "(no data captured)\n"); |
| 863 | } |
| 864 | |
| 865 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 866 | |
| 867 | kfree(buf); |
| 868 | |
| 869 | return ret; |
| 870 | } |
| 871 | #endif |
| 872 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 873 | #define MVM_DEBUGFS_READ_FILE_OPS(name) \ |
| 874 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ |
| 875 | .read = iwl_dbgfs_##name##_read, \ |
Wei Yongjun | ba5295f | 2013-02-25 21:24:11 +0800 | [diff] [blame] | 876 | .open = simple_open, \ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 877 | .llseek = generic_file_llseek, \ |
| 878 | } |
| 879 | |
| 880 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \ |
| 881 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ |
| 882 | .write = iwl_dbgfs_##name##_write, \ |
| 883 | .read = iwl_dbgfs_##name##_read, \ |
Wei Yongjun | ba5295f | 2013-02-25 21:24:11 +0800 | [diff] [blame] | 884 | .open = simple_open, \ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 885 | .llseek = generic_file_llseek, \ |
| 886 | }; |
| 887 | |
| 888 | #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \ |
| 889 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ |
| 890 | .write = iwl_dbgfs_##name##_write, \ |
Wei Yongjun | ba5295f | 2013-02-25 21:24:11 +0800 | [diff] [blame] | 891 | .open = simple_open, \ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 892 | .llseek = generic_file_llseek, \ |
| 893 | }; |
| 894 | |
| 895 | #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \ |
| 896 | if (!debugfs_create_file(#name, mode, parent, mvm, \ |
| 897 | &iwl_dbgfs_##name##_ops)) \ |
| 898 | goto err; \ |
| 899 | } while (0) |
| 900 | |
| 901 | #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \ |
| 902 | if (!debugfs_create_file(#name, mode, parent, vif, \ |
| 903 | &iwl_dbgfs_##name##_ops)) \ |
| 904 | goto err; \ |
| 905 | } while (0) |
| 906 | |
| 907 | /* Device wide debugfs entries */ |
| 908 | MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush); |
| 909 | MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain); |
| 910 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram); |
| 911 | MVM_DEBUGFS_READ_FILE_OPS(stations); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 912 | MVM_DEBUGFS_READ_FILE_OPS(bt_notif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 913 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow); |
| 914 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 915 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 916 | #ifdef CONFIG_PM_SLEEP |
| 917 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram); |
| 918 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 919 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 920 | /* Interface specific debugfs entries */ |
| 921 | MVM_DEBUGFS_READ_FILE_OPS(mac_params); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 922 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params); |
| 923 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params); |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 924 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 925 | int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) |
| 926 | { |
| 927 | char buf[100]; |
| 928 | |
| 929 | mvm->debugfs_dir = dbgfs_dir; |
| 930 | |
| 931 | MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR); |
| 932 | MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR); |
| 933 | MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR); |
| 934 | MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 935 | MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 936 | MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR); |
| 937 | MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 938 | MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 939 | #ifdef CONFIG_PM_SLEEP |
| 940 | MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 941 | MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR); |
Johannes Berg | b011471 | 2013-06-12 14:55:40 +0200 | [diff] [blame^] | 942 | if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR, |
| 943 | mvm->debugfs_dir, &mvm->d3_wake_sysassert)) |
| 944 | goto err; |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 945 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 946 | |
| 947 | /* |
| 948 | * Create a symlink with mac80211. It will be removed when mac80211 |
| 949 | * exists (before the opmode exists which removes the target.) |
| 950 | */ |
| 951 | snprintf(buf, 100, "../../%s/%s", |
| 952 | dbgfs_dir->d_parent->d_parent->d_name.name, |
| 953 | dbgfs_dir->d_parent->d_name.name); |
| 954 | if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf)) |
| 955 | goto err; |
| 956 | |
| 957 | return 0; |
| 958 | err: |
| 959 | IWL_ERR(mvm, "Can't create the mvm debugfs directory\n"); |
| 960 | return -ENOMEM; |
| 961 | } |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 962 | |
| 963 | void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 964 | { |
| 965 | struct dentry *dbgfs_dir = vif->debugfs_dir; |
| 966 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 967 | char buf[100]; |
| 968 | |
| 969 | if (!dbgfs_dir) |
| 970 | return; |
| 971 | |
| 972 | mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir); |
| 973 | mvmvif->dbgfs_data = mvm; |
| 974 | |
| 975 | if (!mvmvif->dbgfs_dir) { |
| 976 | IWL_ERR(mvm, "Failed to create debugfs directory under %s\n", |
| 977 | dbgfs_dir->d_name.name); |
| 978 | return; |
| 979 | } |
| 980 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 981 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM && |
| 982 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) |
| 983 | MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR | |
| 984 | S_IRUSR); |
| 985 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 986 | MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, |
| 987 | S_IRUSR); |
| 988 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 989 | if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p && |
| 990 | mvmvif == mvm->bf_allowed_vif) |
| 991 | MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, |
| 992 | S_IRUSR | S_IWUSR); |
| 993 | |
Johannes Berg | 6349437 | 2013-03-26 10:47:53 +0100 | [diff] [blame] | 994 | /* |
| 995 | * Create symlink for convenience pointing to interface specific |
| 996 | * debugfs entries for the driver. For example, under |
| 997 | * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/ |
| 998 | * find |
| 999 | * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/ |
| 1000 | */ |
| 1001 | snprintf(buf, 100, "../../../%s/%s/%s/%s", |
| 1002 | dbgfs_dir->d_parent->d_parent->d_name.name, |
| 1003 | dbgfs_dir->d_parent->d_name.name, |
| 1004 | dbgfs_dir->d_name.name, |
| 1005 | mvmvif->dbgfs_dir->d_name.name); |
| 1006 | |
| 1007 | mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name, |
| 1008 | mvm->debugfs_dir, buf); |
| 1009 | if (!mvmvif->dbgfs_slink) |
| 1010 | IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n", |
| 1011 | dbgfs_dir->d_name.name); |
| 1012 | return; |
| 1013 | err: |
| 1014 | IWL_ERR(mvm, "Can't create debugfs entity\n"); |
| 1015 | } |
| 1016 | |
| 1017 | void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1018 | { |
| 1019 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1020 | |
| 1021 | debugfs_remove(mvmvif->dbgfs_slink); |
| 1022 | mvmvif->dbgfs_slink = NULL; |
| 1023 | |
| 1024 | debugfs_remove_recursive(mvmvif->dbgfs_dir); |
| 1025 | mvmvif->dbgfs_dir = NULL; |
| 1026 | } |