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 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Eliad Peller | c779273 | 2015-04-19 11:41:04 +0300 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
| 29 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Eliad Peller | c779273 | 2015-04-19 11:41:04 +0300 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
Emmanuel Grumbach | 192c80a | 2014-03-19 08:25:05 +0200 | [diff] [blame] | 65 | #include <linux/vmalloc.h> |
| 66 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 67 | #include "mvm.h" |
Golan Ben-Ami | 2f89a5d | 2015-10-27 19:17:14 +0200 | [diff] [blame^] | 68 | #include "fw-dbg.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 69 | #include "sta.h" |
| 70 | #include "iwl-io.h" |
Johannes Berg | 820a1a5 | 2013-11-12 16:58:41 +0100 | [diff] [blame] | 71 | #include "debugfs.h" |
Johannes Berg | 4d07500 | 2014-04-24 10:41:31 +0200 | [diff] [blame] | 72 | #include "iwl-fw-error-dump.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 74 | static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 75 | size_t count, loff_t *ppos) |
| 76 | { |
Johannes Berg | 8a0bd16 | 2013-11-12 16:48:03 +0100 | [diff] [blame] | 77 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 78 | u32 scd_q_msk; |
| 79 | |
| 80 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 81 | return -EIO; |
| 82 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 83 | if (sscanf(buf, "%x", &scd_q_msk) != 1) |
| 84 | return -EINVAL; |
| 85 | |
| 86 | IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk); |
| 87 | |
| 88 | mutex_lock(&mvm->mutex); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 89 | ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 90 | mutex_unlock(&mvm->mutex); |
| 91 | |
| 92 | return ret; |
| 93 | } |
| 94 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 95 | static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 96 | size_t count, loff_t *ppos) |
| 97 | { |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 98 | struct iwl_mvm_sta *mvmsta; |
Johannes Berg | 8a0bd16 | 2013-11-12 16:48:03 +0100 | [diff] [blame] | 99 | int sta_id, drain, ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 100 | |
| 101 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 102 | return -EIO; |
| 103 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 104 | if (sscanf(buf, "%d %d", &sta_id, &drain) != 2) |
| 105 | return -EINVAL; |
Johannes Berg | 60765a4 | 2013-10-25 13:06:06 +0200 | [diff] [blame] | 106 | if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT) |
| 107 | return -EINVAL; |
| 108 | if (drain < 0 || drain > 1) |
| 109 | return -EINVAL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 110 | |
| 111 | mutex_lock(&mvm->mutex); |
| 112 | |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 113 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
| 114 | |
| 115 | if (!mvmsta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 116 | ret = -ENOENT; |
| 117 | else |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 118 | ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 119 | |
| 120 | mutex_unlock(&mvm->mutex); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, |
| 126 | size_t count, loff_t *ppos) |
| 127 | { |
| 128 | struct iwl_mvm *mvm = file->private_data; |
| 129 | const struct fw_img *img; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 130 | unsigned int ofs, len; |
| 131 | size_t ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 132 | u8 *ptr; |
| 133 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 134 | if (!mvm->ucode_loaded) |
| 135 | return -EINVAL; |
| 136 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 137 | /* default is to dump the entire data segment */ |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 138 | img = &mvm->fw->img[mvm->cur_ucode]; |
| 139 | ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 140 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 141 | |
Emmanuel Grumbach | 01e0efe | 2014-01-06 09:05:54 +0200 | [diff] [blame] | 142 | if (mvm->dbgfs_sram_len) { |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 143 | ofs = mvm->dbgfs_sram_offset; |
| 144 | len = mvm->dbgfs_sram_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 145 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 146 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 147 | ptr = kzalloc(len, GFP_KERNEL); |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 148 | if (!ptr) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 149 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 150 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 151 | iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 152 | |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 153 | ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 154 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 155 | kfree(ptr); |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 160 | static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf, |
| 161 | size_t count, loff_t *ppos) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 162 | { |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 163 | const struct fw_img *img; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 164 | u32 offset, len; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 165 | u32 img_offset, img_len; |
| 166 | |
| 167 | if (!mvm->ucode_loaded) |
| 168 | return -EINVAL; |
| 169 | |
| 170 | img = &mvm->fw->img[mvm->cur_ucode]; |
| 171 | img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 172 | img_len = img->sec[IWL_UCODE_SECTION_DATA].len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 173 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 174 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { |
| 175 | if ((offset & 0x3) || (len & 0x3)) |
| 176 | return -EINVAL; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 177 | |
| 178 | if (offset + len > img_offset + img_len) |
| 179 | return -EINVAL; |
| 180 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 181 | mvm->dbgfs_sram_offset = offset; |
| 182 | mvm->dbgfs_sram_len = len; |
| 183 | } else { |
| 184 | mvm->dbgfs_sram_offset = 0; |
| 185 | mvm->dbgfs_sram_len = 0; |
| 186 | } |
| 187 | |
| 188 | return count; |
| 189 | } |
| 190 | |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 191 | static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file, |
| 192 | char __user *user_buf, |
| 193 | size_t count, loff_t *ppos) |
| 194 | { |
| 195 | struct iwl_mvm *mvm = file->private_data; |
| 196 | char buf[16]; |
| 197 | int pos; |
| 198 | |
| 199 | if (!mvm->temperature_test) |
| 200 | pos = scnprintf(buf , sizeof(buf), "disabled\n"); |
| 201 | else |
| 202 | pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature); |
| 203 | |
| 204 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Set NIC Temperature |
| 209 | * Cause the driver to ignore the actual NIC temperature reported by the FW |
| 210 | * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN - |
| 211 | * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX |
| 212 | * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE |
| 213 | */ |
| 214 | static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm, |
| 215 | char *buf, size_t count, |
| 216 | loff_t *ppos) |
| 217 | { |
| 218 | int temperature; |
| 219 | |
Luciano Coelho | a26d4e7 | 2014-08-20 10:21:07 +0300 | [diff] [blame] | 220 | if (!mvm->ucode_loaded && !mvm->temperature_test) |
| 221 | return -EIO; |
| 222 | |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 223 | if (kstrtoint(buf, 10, &temperature)) |
| 224 | return -EINVAL; |
| 225 | /* not a legal temperature */ |
| 226 | if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX && |
| 227 | temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) || |
| 228 | temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN) |
| 229 | return -EINVAL; |
| 230 | |
| 231 | mutex_lock(&mvm->mutex); |
| 232 | if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) { |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 233 | if (!mvm->temperature_test) |
| 234 | goto out; |
| 235 | |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 236 | mvm->temperature_test = false; |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 237 | /* Since we can't read the temp while awake, just set |
| 238 | * it to zero until we get the next RX stats from the |
| 239 | * firmware. |
| 240 | */ |
| 241 | mvm->temperature = 0; |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 242 | } else { |
| 243 | mvm->temperature_test = true; |
| 244 | mvm->temperature = temperature; |
| 245 | } |
| 246 | IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n", |
| 247 | mvm->temperature_test ? "En" : "Dis" , |
| 248 | mvm->temperature); |
| 249 | /* handle the temperature change */ |
| 250 | iwl_mvm_tt_handler(mvm); |
Luciano Coelho | b689fa7 | 2014-08-20 17:26:58 +0300 | [diff] [blame] | 251 | |
| 252 | out: |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 253 | mutex_unlock(&mvm->mutex); |
| 254 | |
| 255 | return count; |
| 256 | } |
| 257 | |
Luciano Coelho | c549e39 | 2014-09-04 15:58:47 +0300 | [diff] [blame] | 258 | static ssize_t iwl_dbgfs_nic_temp_read(struct file *file, |
| 259 | char __user *user_buf, |
| 260 | size_t count, loff_t *ppos) |
| 261 | { |
| 262 | struct iwl_mvm *mvm = file->private_data; |
| 263 | char buf[16]; |
| 264 | int pos, temp; |
| 265 | |
| 266 | if (!mvm->ucode_loaded) |
| 267 | return -EIO; |
| 268 | |
| 269 | mutex_lock(&mvm->mutex); |
| 270 | temp = iwl_mvm_get_temp(mvm); |
| 271 | mutex_unlock(&mvm->mutex); |
| 272 | |
| 273 | if (temp < 0) |
| 274 | return temp; |
| 275 | |
| 276 | pos = scnprintf(buf , sizeof(buf), "%d\n", temp); |
| 277 | |
| 278 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 279 | } |
| 280 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 281 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, |
| 282 | size_t count, loff_t *ppos) |
| 283 | { |
| 284 | struct iwl_mvm *mvm = file->private_data; |
| 285 | struct ieee80211_sta *sta; |
| 286 | char buf[400]; |
| 287 | int i, pos = 0, bufsz = sizeof(buf); |
| 288 | |
| 289 | mutex_lock(&mvm->mutex); |
| 290 | |
| 291 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 292 | pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); |
| 293 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 294 | lockdep_is_held(&mvm->mutex)); |
| 295 | if (!sta) |
| 296 | pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); |
| 297 | else if (IS_ERR(sta)) |
| 298 | pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", |
| 299 | PTR_ERR(sta)); |
| 300 | else |
| 301 | pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", |
| 302 | sta->addr); |
| 303 | } |
| 304 | |
| 305 | mutex_unlock(&mvm->mutex); |
| 306 | |
| 307 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 308 | } |
| 309 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 310 | static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file, |
| 311 | char __user *user_buf, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 312 | size_t count, loff_t *ppos) |
| 313 | { |
| 314 | struct iwl_mvm *mvm = file->private_data; |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 315 | char buf[64]; |
| 316 | int bufsz = sizeof(buf); |
| 317 | int pos = 0; |
| 318 | |
| 319 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n", |
| 320 | mvm->disable_power_off); |
| 321 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n", |
| 322 | mvm->disable_power_off_d3); |
| 323 | |
| 324 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 325 | } |
| 326 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 327 | static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf, |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 328 | size_t count, loff_t *ppos) |
| 329 | { |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 330 | int ret, val; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 331 | |
| 332 | if (!mvm->ucode_loaded) |
| 333 | return -EIO; |
| 334 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 335 | if (!strncmp("disable_power_off_d0=", buf, 21)) { |
| 336 | if (sscanf(buf + 21, "%d", &val) != 1) |
| 337 | return -EINVAL; |
| 338 | mvm->disable_power_off = val; |
| 339 | } else if (!strncmp("disable_power_off_d3=", buf, 21)) { |
| 340 | if (sscanf(buf + 21, "%d", &val) != 1) |
| 341 | return -EINVAL; |
| 342 | mvm->disable_power_off_d3 = val; |
| 343 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 344 | return -EINVAL; |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 345 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 346 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 347 | mutex_lock(&mvm->mutex); |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 348 | ret = iwl_mvm_power_update_device(mvm); |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 349 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 350 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 351 | return ret ?: count; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 354 | #define BT_MBOX_MSG(_notif, _num, _field) \ |
| 355 | ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\ |
| 356 | >> BT_MBOX##_num##_##_field##_POS) |
| 357 | |
| 358 | |
| 359 | #define BT_MBOX_PRINT(_num, _field, _end) \ |
| 360 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 361 | "\t%s: %d%s", \ |
| 362 | #_field, \ |
| 363 | BT_MBOX_MSG(notif, _num, _field), \ |
| 364 | true ? "\n" : ", "); |
| 365 | |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 366 | static |
| 367 | int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf, |
| 368 | int pos, int bufsz) |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 369 | { |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 370 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); |
| 371 | |
| 372 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); |
| 373 | BT_MBOX_PRINT(0, LE_PROF1, false); |
| 374 | BT_MBOX_PRINT(0, LE_PROF2, false); |
| 375 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); |
| 376 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); |
| 377 | BT_MBOX_PRINT(0, INBAND_S, false); |
| 378 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); |
| 379 | BT_MBOX_PRINT(0, LE_SCAN, false); |
| 380 | BT_MBOX_PRINT(0, LE_ADV, false); |
| 381 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); |
| 382 | BT_MBOX_PRINT(0, OPEN_CON_1, true); |
| 383 | |
| 384 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); |
| 385 | |
| 386 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); |
| 387 | BT_MBOX_PRINT(1, IP_SR, false); |
| 388 | BT_MBOX_PRINT(1, LE_MSTR, false); |
| 389 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); |
| 390 | BT_MBOX_PRINT(1, MSG_TYPE, false); |
| 391 | BT_MBOX_PRINT(1, SSN, true); |
| 392 | |
| 393 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); |
| 394 | |
| 395 | BT_MBOX_PRINT(2, SNIFF_ACT, false); |
| 396 | BT_MBOX_PRINT(2, PAG, false); |
| 397 | BT_MBOX_PRINT(2, INQUIRY, false); |
| 398 | BT_MBOX_PRINT(2, CONN, false); |
| 399 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); |
| 400 | BT_MBOX_PRINT(2, DISC, false); |
| 401 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); |
| 402 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); |
| 403 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); |
| 404 | BT_MBOX_PRINT(2, SCO_DURATION, true); |
| 405 | |
| 406 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); |
| 407 | |
| 408 | BT_MBOX_PRINT(3, SCO_STATE, false); |
| 409 | BT_MBOX_PRINT(3, SNIFF_STATE, false); |
| 410 | BT_MBOX_PRINT(3, A2DP_STATE, false); |
| 411 | BT_MBOX_PRINT(3, ACL_STATE, false); |
| 412 | BT_MBOX_PRINT(3, MSTR_STATE, false); |
| 413 | BT_MBOX_PRINT(3, OBX_STATE, false); |
| 414 | BT_MBOX_PRINT(3, OPEN_CON_2, false); |
| 415 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); |
| 416 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); |
| 417 | BT_MBOX_PRINT(3, INBAND_P, false); |
| 418 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); |
| 419 | BT_MBOX_PRINT(3, SSN_2, false); |
| 420 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); |
| 421 | |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 422 | return pos; |
| 423 | } |
| 424 | |
| 425 | static |
| 426 | int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif, |
| 427 | char *buf, int pos, int bufsz) |
| 428 | { |
| 429 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); |
| 430 | |
| 431 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); |
| 432 | BT_MBOX_PRINT(0, LE_PROF1, false); |
| 433 | BT_MBOX_PRINT(0, LE_PROF2, false); |
| 434 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); |
| 435 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); |
| 436 | BT_MBOX_PRINT(0, INBAND_S, false); |
| 437 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); |
| 438 | BT_MBOX_PRINT(0, LE_SCAN, false); |
| 439 | BT_MBOX_PRINT(0, LE_ADV, false); |
| 440 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); |
| 441 | BT_MBOX_PRINT(0, OPEN_CON_1, true); |
| 442 | |
| 443 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); |
| 444 | |
| 445 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); |
| 446 | BT_MBOX_PRINT(1, IP_SR, false); |
| 447 | BT_MBOX_PRINT(1, LE_MSTR, false); |
| 448 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); |
| 449 | BT_MBOX_PRINT(1, MSG_TYPE, false); |
| 450 | BT_MBOX_PRINT(1, SSN, true); |
| 451 | |
| 452 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); |
| 453 | |
| 454 | BT_MBOX_PRINT(2, SNIFF_ACT, false); |
| 455 | BT_MBOX_PRINT(2, PAG, false); |
| 456 | BT_MBOX_PRINT(2, INQUIRY, false); |
| 457 | BT_MBOX_PRINT(2, CONN, false); |
| 458 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); |
| 459 | BT_MBOX_PRINT(2, DISC, false); |
| 460 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); |
| 461 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); |
| 462 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); |
| 463 | BT_MBOX_PRINT(2, SCO_DURATION, true); |
| 464 | |
| 465 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); |
| 466 | |
| 467 | BT_MBOX_PRINT(3, SCO_STATE, false); |
| 468 | BT_MBOX_PRINT(3, SNIFF_STATE, false); |
| 469 | BT_MBOX_PRINT(3, A2DP_STATE, false); |
| 470 | BT_MBOX_PRINT(3, ACL_STATE, false); |
| 471 | BT_MBOX_PRINT(3, MSTR_STATE, false); |
| 472 | BT_MBOX_PRINT(3, OBX_STATE, false); |
| 473 | BT_MBOX_PRINT(3, OPEN_CON_2, false); |
| 474 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); |
| 475 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); |
| 476 | BT_MBOX_PRINT(3, INBAND_P, false); |
| 477 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); |
| 478 | BT_MBOX_PRINT(3, SSN_2, false); |
| 479 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); |
| 480 | |
| 481 | return pos; |
| 482 | } |
| 483 | |
| 484 | static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, |
| 485 | size_t count, loff_t *ppos) |
| 486 | { |
| 487 | struct iwl_mvm *mvm = file->private_data; |
| 488 | char *buf; |
| 489 | int ret, pos = 0, bufsz = sizeof(char) * 1024; |
| 490 | |
| 491 | buf = kmalloc(bufsz, GFP_KERNEL); |
| 492 | if (!buf) |
| 493 | return -ENOMEM; |
| 494 | |
| 495 | mutex_lock(&mvm->mutex); |
| 496 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 497 | if (!fw_has_api(&mvm->fw->ucode_capa, |
| 498 | IWL_UCODE_TLV_API_BT_COEX_SPLIT)) { |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 499 | struct iwl_bt_coex_profile_notif_old *notif = |
| 500 | &mvm->last_bt_notif_old; |
| 501 | |
| 502 | pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz); |
| 503 | |
| 504 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", |
| 505 | notif->bt_ci_compliance); |
| 506 | pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n", |
| 507 | le32_to_cpu(notif->primary_ch_lut)); |
| 508 | pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n", |
| 509 | le32_to_cpu(notif->secondary_ch_lut)); |
| 510 | pos += scnprintf(buf+pos, |
| 511 | bufsz-pos, "bt_activity_grading = %d\n", |
| 512 | le32_to_cpu(notif->bt_activity_grading)); |
| 513 | pos += scnprintf(buf+pos, bufsz-pos, |
| 514 | "antenna isolation = %d CORUN LUT index = %d\n", |
| 515 | mvm->last_ant_isol, mvm->last_corun_lut); |
Moshe Harel | 48f0a03 | 2015-10-26 11:33:49 +0200 | [diff] [blame] | 516 | pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n", |
| 517 | notif->rrc_enabled); |
| 518 | pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n", |
| 519 | notif->ttc_enabled); |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 520 | } else { |
| 521 | struct iwl_bt_coex_profile_notif *notif = |
| 522 | &mvm->last_bt_notif; |
| 523 | |
| 524 | pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz); |
| 525 | |
| 526 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", |
| 527 | notif->bt_ci_compliance); |
| 528 | pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n", |
| 529 | le32_to_cpu(notif->primary_ch_lut)); |
| 530 | pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n", |
| 531 | le32_to_cpu(notif->secondary_ch_lut)); |
| 532 | pos += scnprintf(buf+pos, |
| 533 | bufsz-pos, "bt_activity_grading = %d\n", |
| 534 | le32_to_cpu(notif->bt_activity_grading)); |
| 535 | pos += scnprintf(buf+pos, bufsz-pos, |
| 536 | "antenna isolation = %d CORUN LUT index = %d\n", |
| 537 | mvm->last_ant_isol, mvm->last_corun_lut); |
Moshe Harel | 48f0a03 | 2015-10-26 11:33:49 +0200 | [diff] [blame] | 538 | pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n", |
| 539 | (notif->ttc_rrc_status >> 4) & 0xF); |
| 540 | pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n", |
| 541 | notif->ttc_rrc_status & 0xF); |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 542 | } |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 543 | |
Moshe Harel | c725a46 | 2015-10-27 14:04:12 +0200 | [diff] [blame] | 544 | pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n", |
| 545 | IWL_MVM_BT_COEX_SYNC2SCO); |
| 546 | pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n", |
| 547 | IWL_MVM_BT_COEX_MPLUT); |
| 548 | pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n", |
| 549 | IWL_MVM_BT_COEX_CORUNNING); |
| 550 | |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 551 | mutex_unlock(&mvm->mutex); |
| 552 | |
| 553 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 554 | kfree(buf); |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | #undef BT_MBOX_PRINT |
| 559 | |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 560 | static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf, |
| 561 | size_t count, loff_t *ppos) |
| 562 | { |
| 563 | struct iwl_mvm *mvm = file->private_data; |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 564 | char buf[256]; |
| 565 | int bufsz = sizeof(buf); |
| 566 | int pos = 0; |
| 567 | |
| 568 | mutex_lock(&mvm->mutex); |
| 569 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 570 | if (!fw_has_api(&mvm->fw->ucode_capa, |
| 571 | IWL_UCODE_TLV_API_BT_COEX_SPLIT)) { |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 572 | struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old; |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 573 | |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 574 | pos += scnprintf(buf+pos, bufsz-pos, |
| 575 | "Channel inhibition CMD\n"); |
| 576 | pos += scnprintf(buf+pos, bufsz-pos, |
| 577 | "\tPrimary Channel Bitmap 0x%016llx\n", |
| 578 | le64_to_cpu(cmd->bt_primary_ci)); |
| 579 | pos += scnprintf(buf+pos, bufsz-pos, |
| 580 | "\tSecondary Channel Bitmap 0x%016llx\n", |
| 581 | le64_to_cpu(cmd->bt_secondary_ci)); |
| 582 | |
Emmanuel Grumbach | aee8bf5 | 2015-02-19 15:00:18 +0200 | [diff] [blame] | 583 | pos += scnprintf(buf+pos, bufsz-pos, |
| 584 | "BT Configuration CMD - 0=default, 1=never, 2=always\n"); |
| 585 | pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill msk idx %d\n", |
| 586 | mvm->bt_ack_kill_msk[0]); |
| 587 | pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill msk idx %d\n", |
| 588 | mvm->bt_cts_kill_msk[0]); |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 589 | |
| 590 | } else { |
| 591 | struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd; |
| 592 | |
| 593 | pos += scnprintf(buf+pos, bufsz-pos, |
| 594 | "Channel inhibition CMD\n"); |
| 595 | pos += scnprintf(buf+pos, bufsz-pos, |
| 596 | "\tPrimary Channel Bitmap 0x%016llx\n", |
| 597 | le64_to_cpu(cmd->bt_primary_ci)); |
| 598 | pos += scnprintf(buf+pos, bufsz-pos, |
| 599 | "\tSecondary Channel Bitmap 0x%016llx\n", |
| 600 | le64_to_cpu(cmd->bt_secondary_ci)); |
Emmanuel Grumbach | 160be57 | 2014-07-02 17:33:52 +0300 | [diff] [blame] | 601 | } |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 602 | |
| 603 | mutex_unlock(&mvm->mutex); |
| 604 | |
| 605 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 606 | } |
| 607 | |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 608 | static ssize_t |
| 609 | iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf, |
| 610 | size_t count, loff_t *ppos) |
| 611 | { |
| 612 | u32 bt_tx_prio; |
| 613 | |
| 614 | if (sscanf(buf, "%u", &bt_tx_prio) != 1) |
| 615 | return -EINVAL; |
| 616 | if (bt_tx_prio > 4) |
| 617 | return -EINVAL; |
| 618 | |
| 619 | mvm->bt_tx_prio = bt_tx_prio; |
| 620 | |
| 621 | return count; |
| 622 | } |
| 623 | |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 624 | static ssize_t |
| 625 | iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf, |
| 626 | size_t count, loff_t *ppos) |
| 627 | { |
| 628 | static const char * const modes_str[BT_FORCE_ANT_MAX] = { |
| 629 | [BT_FORCE_ANT_DIS] = "dis", |
| 630 | [BT_FORCE_ANT_AUTO] = "auto", |
| 631 | [BT_FORCE_ANT_BT] = "bt", |
| 632 | [BT_FORCE_ANT_WIFI] = "wifi", |
| 633 | }; |
| 634 | int ret, bt_force_ant_mode; |
| 635 | |
| 636 | for (bt_force_ant_mode = 0; |
| 637 | bt_force_ant_mode < ARRAY_SIZE(modes_str); |
| 638 | bt_force_ant_mode++) { |
| 639 | if (!strcmp(buf, modes_str[bt_force_ant_mode])) |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | if (bt_force_ant_mode >= ARRAY_SIZE(modes_str)) |
| 644 | return -EINVAL; |
| 645 | |
| 646 | ret = 0; |
| 647 | mutex_lock(&mvm->mutex); |
| 648 | if (mvm->bt_force_ant_mode == bt_force_ant_mode) |
| 649 | goto out; |
| 650 | |
| 651 | mvm->bt_force_ant_mode = bt_force_ant_mode; |
| 652 | IWL_DEBUG_COEX(mvm, "Force mode: %s\n", |
| 653 | modes_str[mvm->bt_force_ant_mode]); |
| 654 | ret = iwl_send_bt_init_conf(mvm); |
| 655 | |
| 656 | out: |
| 657 | mutex_unlock(&mvm->mutex); |
| 658 | return ret ?: count; |
| 659 | } |
| 660 | |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 661 | #define PRINT_STATS_LE32(_struct, _memb) \ |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 662 | pos += scnprintf(buf + pos, bufsz - pos, \ |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 663 | fmt_table, #_memb, \ |
| 664 | le32_to_cpu(_struct->_memb)) |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 665 | |
| 666 | static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file, |
| 667 | char __user *user_buf, size_t count, |
| 668 | loff_t *ppos) |
| 669 | { |
| 670 | struct iwl_mvm *mvm = file->private_data; |
| 671 | static const char *fmt_table = "\t%-30s %10u\n"; |
| 672 | static const char *fmt_header = "%-32s\n"; |
| 673 | int pos = 0; |
| 674 | char *buf; |
| 675 | int ret; |
Luciano Coelho | 3f61728 | 2013-10-14 13:18:41 +0300 | [diff] [blame] | 676 | /* 43 is the size of each data line, 33 is the size of each header */ |
| 677 | size_t bufsz = |
| 678 | ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) + |
| 679 | (4 * 33) + 1; |
| 680 | |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 681 | struct mvm_statistics_rx_phy *ofdm; |
| 682 | struct mvm_statistics_rx_phy *cck; |
| 683 | struct mvm_statistics_rx_non_phy *general; |
| 684 | struct mvm_statistics_rx_ht_phy *ht; |
| 685 | |
| 686 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 687 | if (!buf) |
| 688 | return -ENOMEM; |
| 689 | |
| 690 | mutex_lock(&mvm->mutex); |
| 691 | |
| 692 | ofdm = &mvm->rx_stats.ofdm; |
| 693 | cck = &mvm->rx_stats.cck; |
| 694 | general = &mvm->rx_stats.general; |
| 695 | ht = &mvm->rx_stats.ofdm_ht; |
| 696 | |
| 697 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 698 | "Statistics_Rx - OFDM"); |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 699 | PRINT_STATS_LE32(ofdm, ina_cnt); |
| 700 | PRINT_STATS_LE32(ofdm, fina_cnt); |
| 701 | PRINT_STATS_LE32(ofdm, plcp_err); |
| 702 | PRINT_STATS_LE32(ofdm, crc32_err); |
| 703 | PRINT_STATS_LE32(ofdm, overrun_err); |
| 704 | PRINT_STATS_LE32(ofdm, early_overrun_err); |
| 705 | PRINT_STATS_LE32(ofdm, crc32_good); |
| 706 | PRINT_STATS_LE32(ofdm, false_alarm_cnt); |
| 707 | PRINT_STATS_LE32(ofdm, fina_sync_err_cnt); |
| 708 | PRINT_STATS_LE32(ofdm, sfd_timeout); |
| 709 | PRINT_STATS_LE32(ofdm, fina_timeout); |
| 710 | PRINT_STATS_LE32(ofdm, unresponded_rts); |
| 711 | PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun); |
| 712 | PRINT_STATS_LE32(ofdm, sent_ack_cnt); |
| 713 | PRINT_STATS_LE32(ofdm, sent_cts_cnt); |
| 714 | PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt); |
| 715 | PRINT_STATS_LE32(ofdm, dsp_self_kill); |
| 716 | PRINT_STATS_LE32(ofdm, mh_format_err); |
| 717 | PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum); |
| 718 | PRINT_STATS_LE32(ofdm, reserved); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 719 | |
| 720 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 721 | "Statistics_Rx - CCK"); |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 722 | PRINT_STATS_LE32(cck, ina_cnt); |
| 723 | PRINT_STATS_LE32(cck, fina_cnt); |
| 724 | PRINT_STATS_LE32(cck, plcp_err); |
| 725 | PRINT_STATS_LE32(cck, crc32_err); |
| 726 | PRINT_STATS_LE32(cck, overrun_err); |
| 727 | PRINT_STATS_LE32(cck, early_overrun_err); |
| 728 | PRINT_STATS_LE32(cck, crc32_good); |
| 729 | PRINT_STATS_LE32(cck, false_alarm_cnt); |
| 730 | PRINT_STATS_LE32(cck, fina_sync_err_cnt); |
| 731 | PRINT_STATS_LE32(cck, sfd_timeout); |
| 732 | PRINT_STATS_LE32(cck, fina_timeout); |
| 733 | PRINT_STATS_LE32(cck, unresponded_rts); |
| 734 | PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun); |
| 735 | PRINT_STATS_LE32(cck, sent_ack_cnt); |
| 736 | PRINT_STATS_LE32(cck, sent_cts_cnt); |
| 737 | PRINT_STATS_LE32(cck, sent_ba_rsp_cnt); |
| 738 | PRINT_STATS_LE32(cck, dsp_self_kill); |
| 739 | PRINT_STATS_LE32(cck, mh_format_err); |
| 740 | PRINT_STATS_LE32(cck, re_acq_main_rssi_sum); |
| 741 | PRINT_STATS_LE32(cck, reserved); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 742 | |
| 743 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 744 | "Statistics_Rx - GENERAL"); |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 745 | PRINT_STATS_LE32(general, bogus_cts); |
| 746 | PRINT_STATS_LE32(general, bogus_ack); |
| 747 | PRINT_STATS_LE32(general, non_bssid_frames); |
| 748 | PRINT_STATS_LE32(general, filtered_frames); |
| 749 | PRINT_STATS_LE32(general, non_channel_beacons); |
| 750 | PRINT_STATS_LE32(general, channel_beacons); |
| 751 | PRINT_STATS_LE32(general, num_missed_bcon); |
| 752 | PRINT_STATS_LE32(general, adc_rx_saturation_time); |
| 753 | PRINT_STATS_LE32(general, ina_detection_search_time); |
| 754 | PRINT_STATS_LE32(general, beacon_silence_rssi_a); |
| 755 | PRINT_STATS_LE32(general, beacon_silence_rssi_b); |
| 756 | PRINT_STATS_LE32(general, beacon_silence_rssi_c); |
| 757 | PRINT_STATS_LE32(general, interference_data_flag); |
| 758 | PRINT_STATS_LE32(general, channel_load); |
| 759 | PRINT_STATS_LE32(general, dsp_false_alarms); |
| 760 | PRINT_STATS_LE32(general, beacon_rssi_a); |
| 761 | PRINT_STATS_LE32(general, beacon_rssi_b); |
| 762 | PRINT_STATS_LE32(general, beacon_rssi_c); |
| 763 | PRINT_STATS_LE32(general, beacon_energy_a); |
| 764 | PRINT_STATS_LE32(general, beacon_energy_b); |
| 765 | PRINT_STATS_LE32(general, beacon_energy_c); |
| 766 | PRINT_STATS_LE32(general, num_bt_kills); |
| 767 | PRINT_STATS_LE32(general, mac_id); |
| 768 | PRINT_STATS_LE32(general, directed_data_mpdu); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 769 | |
| 770 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 771 | "Statistics_Rx - HT"); |
Johannes Berg | 93d17cc | 2015-01-15 12:59:26 +0100 | [diff] [blame] | 772 | PRINT_STATS_LE32(ht, plcp_err); |
| 773 | PRINT_STATS_LE32(ht, overrun_err); |
| 774 | PRINT_STATS_LE32(ht, early_overrun_err); |
| 775 | PRINT_STATS_LE32(ht, crc32_good); |
| 776 | PRINT_STATS_LE32(ht, crc32_err); |
| 777 | PRINT_STATS_LE32(ht, mh_format_err); |
| 778 | PRINT_STATS_LE32(ht, agg_crc32_good); |
| 779 | PRINT_STATS_LE32(ht, agg_mpdu_cnt); |
| 780 | PRINT_STATS_LE32(ht, agg_cnt); |
| 781 | PRINT_STATS_LE32(ht, unsupport_mcs); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 782 | |
| 783 | mutex_unlock(&mvm->mutex); |
| 784 | |
| 785 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 786 | kfree(buf); |
| 787 | |
| 788 | return ret; |
| 789 | } |
| 790 | #undef PRINT_STAT_LE32 |
| 791 | |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 792 | static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm, |
| 793 | char __user *user_buf, size_t count, |
| 794 | loff_t *ppos, |
| 795 | struct iwl_mvm_frame_stats *stats) |
| 796 | { |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 797 | char *buff, *pos, *endpos; |
| 798 | int idx, i; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 799 | int ret; |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 800 | static const size_t bufsz = 1024; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 801 | |
| 802 | buff = kmalloc(bufsz, GFP_KERNEL); |
| 803 | if (!buff) |
| 804 | return -ENOMEM; |
| 805 | |
| 806 | spin_lock_bh(&mvm->drv_stats_lock); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 807 | |
| 808 | pos = buff; |
| 809 | endpos = pos + bufsz; |
| 810 | |
| 811 | pos += scnprintf(pos, endpos - pos, |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 812 | "Legacy/HT/VHT\t:\t%d/%d/%d\n", |
| 813 | stats->legacy_frames, |
| 814 | stats->ht_frames, |
| 815 | stats->vht_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 816 | pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 817 | stats->bw_20_frames, |
| 818 | stats->bw_40_frames, |
| 819 | stats->bw_80_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 820 | pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 821 | stats->ngi_frames, |
| 822 | stats->sgi_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 823 | pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 824 | stats->siso_frames, |
| 825 | stats->mimo2_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 826 | pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 827 | stats->fail_frames, |
| 828 | stats->success_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 829 | pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 830 | stats->agg_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 831 | pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 832 | stats->ampdu_count); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 833 | pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 834 | stats->ampdu_count > 0 ? |
| 835 | (stats->agg_frames / stats->ampdu_count) : 0); |
| 836 | |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 837 | pos += scnprintf(pos, endpos - pos, "Last Rates\n"); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 838 | |
| 839 | idx = stats->last_frame_idx - 1; |
| 840 | for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) { |
| 841 | idx = (idx + 1) % ARRAY_SIZE(stats->last_rates); |
| 842 | if (stats->last_rates[idx] == 0) |
| 843 | continue; |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 844 | pos += scnprintf(pos, endpos - pos, "Rate[%d]: ", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 845 | (int)(ARRAY_SIZE(stats->last_rates) - i)); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 846 | pos += rs_pretty_print_rate(pos, stats->last_rates[idx]); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 847 | } |
| 848 | spin_unlock_bh(&mvm->drv_stats_lock); |
| 849 | |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 850 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 851 | kfree(buff); |
| 852 | |
| 853 | return ret; |
| 854 | } |
| 855 | |
| 856 | static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file, |
| 857 | char __user *user_buf, size_t count, |
| 858 | loff_t *ppos) |
| 859 | { |
| 860 | struct iwl_mvm *mvm = file->private_data; |
| 861 | |
| 862 | return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos, |
| 863 | &mvm->drv_rx_stats); |
| 864 | } |
| 865 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 866 | static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf, |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 867 | size_t count, loff_t *ppos) |
| 868 | { |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 869 | int ret; |
| 870 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 871 | mutex_lock(&mvm->mutex); |
| 872 | |
Eran Harary | 291aa7c | 2013-07-03 11:00:06 +0300 | [diff] [blame] | 873 | /* allow one more restart that we're provoking here */ |
| 874 | if (mvm->restart_fw >= 0) |
| 875 | mvm->restart_fw++; |
| 876 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 877 | /* take the return value to make compiler happy - it will fail anyway */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 878 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 879 | |
| 880 | mutex_unlock(&mvm->mutex); |
| 881 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 882 | return count; |
| 883 | } |
| 884 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 885 | static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf, |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 886 | size_t count, loff_t *ppos) |
| 887 | { |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 888 | int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI); |
| 889 | if (ret) |
| 890 | return ret; |
| 891 | |
Liad Kaufman | 4c9706d | 2014-04-27 16:46:09 +0300 | [diff] [blame] | 892 | iwl_force_nmi(mvm->trans); |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 893 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 894 | iwl_mvm_unref(mvm, IWL_MVM_REF_NMI); |
| 895 | |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 896 | return count; |
| 897 | } |
| 898 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 899 | static ssize_t |
| 900 | iwl_dbgfs_scan_ant_rxchain_read(struct file *file, |
| 901 | char __user *user_buf, |
| 902 | size_t count, loff_t *ppos) |
| 903 | { |
| 904 | struct iwl_mvm *mvm = file->private_data; |
| 905 | int pos = 0; |
| 906 | char buf[32]; |
| 907 | const size_t bufsz = sizeof(buf); |
| 908 | |
| 909 | /* print which antennas were set for the scan command by the user */ |
| 910 | pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: "); |
| 911 | if (mvm->scan_rx_ant & ANT_A) |
| 912 | pos += scnprintf(buf + pos, bufsz - pos, "A"); |
| 913 | if (mvm->scan_rx_ant & ANT_B) |
| 914 | pos += scnprintf(buf + pos, bufsz - pos, "B"); |
| 915 | if (mvm->scan_rx_ant & ANT_C) |
| 916 | pos += scnprintf(buf + pos, bufsz - pos, "C"); |
| 917 | pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant); |
| 918 | |
| 919 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 920 | } |
| 921 | |
| 922 | static ssize_t |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 923 | iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf, |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 924 | size_t count, loff_t *ppos) |
| 925 | { |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 926 | u8 scan_rx_ant; |
| 927 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 928 | if (sscanf(buf, "%hhx", &scan_rx_ant) != 1) |
| 929 | return -EINVAL; |
| 930 | if (scan_rx_ant > ANT_ABC) |
| 931 | return -EINVAL; |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 932 | if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm))) |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 933 | return -EINVAL; |
| 934 | |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 935 | if (mvm->scan_rx_ant != scan_rx_ant) { |
| 936 | mvm->scan_rx_ant = scan_rx_ant; |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 937 | if (fw_has_capa(&mvm->fw->ucode_capa, |
| 938 | IWL_UCODE_TLV_CAPA_UMAC_SCAN)) |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 939 | iwl_mvm_config_scan(mvm); |
| 940 | } |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 941 | |
| 942 | return count; |
| 943 | } |
| 944 | |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 945 | static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file, |
| 946 | char __user *user_buf, |
| 947 | size_t count, loff_t *ppos) |
| 948 | { |
| 949 | struct iwl_mvm *mvm = file->private_data; |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 950 | int conf; |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 951 | char buf[8]; |
| 952 | const size_t bufsz = sizeof(buf); |
| 953 | int pos = 0; |
| 954 | |
| 955 | mutex_lock(&mvm->mutex); |
| 956 | conf = mvm->fw_dbg_conf; |
| 957 | mutex_unlock(&mvm->mutex); |
| 958 | |
| 959 | pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf); |
| 960 | |
| 961 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 962 | } |
| 963 | |
| 964 | static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm, |
| 965 | char *buf, size_t count, |
| 966 | loff_t *ppos) |
| 967 | { |
Dan Carpenter | 8e8114d | 2015-08-21 11:48:21 +0300 | [diff] [blame] | 968 | unsigned int conf_id; |
| 969 | int ret; |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 970 | |
Dan Carpenter | 8e8114d | 2015-08-21 11:48:21 +0300 | [diff] [blame] | 971 | ret = kstrtouint(buf, 0, &conf_id); |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 972 | if (ret) |
| 973 | return ret; |
| 974 | |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 975 | if (WARN_ON(conf_id >= FW_DBG_CONF_MAX)) |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 976 | return -EINVAL; |
| 977 | |
| 978 | mutex_lock(&mvm->mutex); |
| 979 | ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id); |
| 980 | mutex_unlock(&mvm->mutex); |
| 981 | |
| 982 | return ret ?: count; |
| 983 | } |
| 984 | |
| 985 | static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm, |
| 986 | char *buf, size_t count, |
| 987 | loff_t *ppos) |
| 988 | { |
Liad Kaufman | e93475a | 2015-01-04 11:03:13 +0200 | [diff] [blame] | 989 | int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE); |
| 990 | |
| 991 | if (ret) |
| 992 | return ret; |
| 993 | |
Oren Givon | 36fb901 | 2015-07-15 15:47:28 +0300 | [diff] [blame] | 994 | iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, NULL, 0, NULL); |
Liad Kaufman | e93475a | 2015-01-04 11:03:13 +0200 | [diff] [blame] | 995 | |
| 996 | iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE); |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 997 | |
| 998 | return count; |
| 999 | } |
| 1000 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1001 | #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__) |
| 1002 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1003 | static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file, |
| 1004 | char __user *user_buf, |
| 1005 | size_t count, loff_t *ppos) |
| 1006 | { |
| 1007 | struct iwl_mvm *mvm = file->private_data; |
| 1008 | struct iwl_bcast_filter_cmd cmd; |
| 1009 | const struct iwl_fw_bcast_filter *filter; |
| 1010 | char *buf; |
| 1011 | int bufsz = 1024; |
| 1012 | int i, j, pos = 0; |
| 1013 | ssize_t ret; |
| 1014 | |
| 1015 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 1016 | if (!buf) |
| 1017 | return -ENOMEM; |
| 1018 | |
| 1019 | mutex_lock(&mvm->mutex); |
| 1020 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) { |
| 1021 | ADD_TEXT("None\n"); |
| 1022 | mutex_unlock(&mvm->mutex); |
| 1023 | goto out; |
| 1024 | } |
| 1025 | mutex_unlock(&mvm->mutex); |
| 1026 | |
| 1027 | for (i = 0; cmd.filters[i].attrs[0].mask; i++) { |
| 1028 | filter = &cmd.filters[i]; |
| 1029 | |
| 1030 | ADD_TEXT("Filter [%d]:\n", i); |
| 1031 | ADD_TEXT("\tDiscard=%d\n", filter->discard); |
| 1032 | ADD_TEXT("\tFrame Type: %s\n", |
| 1033 | filter->frame_type ? "IPv4" : "Generic"); |
| 1034 | |
| 1035 | for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) { |
| 1036 | const struct iwl_fw_bcast_filter_attr *attr; |
| 1037 | |
| 1038 | attr = &filter->attrs[j]; |
| 1039 | if (!attr->mask) |
| 1040 | break; |
| 1041 | |
| 1042 | ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n", |
| 1043 | j, attr->offset, |
| 1044 | attr->offset_type ? "IP End" : |
| 1045 | "Payload Start", |
| 1046 | be32_to_cpu(attr->mask), |
| 1047 | be32_to_cpu(attr->val), |
| 1048 | le16_to_cpu(attr->reserved1)); |
| 1049 | } |
| 1050 | } |
| 1051 | out: |
| 1052 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1053 | kfree(buf); |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf, |
| 1058 | size_t count, loff_t *ppos) |
| 1059 | { |
| 1060 | int pos, next_pos; |
| 1061 | struct iwl_fw_bcast_filter filter = {}; |
| 1062 | struct iwl_bcast_filter_cmd cmd; |
| 1063 | u32 filter_id, attr_id, mask, value; |
| 1064 | int err = 0; |
| 1065 | |
| 1066 | if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard, |
| 1067 | &filter.frame_type, &pos) != 3) |
| 1068 | return -EINVAL; |
| 1069 | |
| 1070 | if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) || |
| 1071 | filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4) |
| 1072 | return -EINVAL; |
| 1073 | |
| 1074 | for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs); |
| 1075 | attr_id++) { |
| 1076 | struct iwl_fw_bcast_filter_attr *attr = |
| 1077 | &filter.attrs[attr_id]; |
| 1078 | |
| 1079 | if (pos >= count) |
| 1080 | break; |
| 1081 | |
| 1082 | if (sscanf(&buf[pos], "%hhi %hhi %i %i %n", |
| 1083 | &attr->offset, &attr->offset_type, |
| 1084 | &mask, &value, &next_pos) != 4) |
| 1085 | return -EINVAL; |
| 1086 | |
| 1087 | attr->mask = cpu_to_be32(mask); |
| 1088 | attr->val = cpu_to_be32(value); |
| 1089 | if (mask) |
| 1090 | filter.num_attrs++; |
| 1091 | |
| 1092 | pos += next_pos; |
| 1093 | } |
| 1094 | |
| 1095 | mutex_lock(&mvm->mutex); |
| 1096 | memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id], |
| 1097 | &filter, sizeof(filter)); |
| 1098 | |
| 1099 | /* send updated bcast filtering configuration */ |
| 1100 | if (mvm->dbgfs_bcast_filtering.override && |
| 1101 | iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1102 | err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1103 | sizeof(cmd), &cmd); |
| 1104 | mutex_unlock(&mvm->mutex); |
| 1105 | |
| 1106 | return err ?: count; |
| 1107 | } |
| 1108 | |
| 1109 | static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file, |
| 1110 | char __user *user_buf, |
| 1111 | size_t count, loff_t *ppos) |
| 1112 | { |
| 1113 | struct iwl_mvm *mvm = file->private_data; |
| 1114 | struct iwl_bcast_filter_cmd cmd; |
| 1115 | char *buf; |
| 1116 | int bufsz = 1024; |
| 1117 | int i, pos = 0; |
| 1118 | ssize_t ret; |
| 1119 | |
| 1120 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 1121 | if (!buf) |
| 1122 | return -ENOMEM; |
| 1123 | |
| 1124 | mutex_lock(&mvm->mutex); |
| 1125 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) { |
| 1126 | ADD_TEXT("None\n"); |
| 1127 | mutex_unlock(&mvm->mutex); |
| 1128 | goto out; |
| 1129 | } |
| 1130 | mutex_unlock(&mvm->mutex); |
| 1131 | |
| 1132 | for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) { |
| 1133 | const struct iwl_fw_bcast_mac *mac = &cmd.macs[i]; |
| 1134 | |
| 1135 | ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n", |
| 1136 | i, mac->default_discard, mac->attached_filters); |
| 1137 | } |
| 1138 | out: |
| 1139 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1140 | kfree(buf); |
| 1141 | return ret; |
| 1142 | } |
| 1143 | |
| 1144 | static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm, |
| 1145 | char *buf, size_t count, |
| 1146 | loff_t *ppos) |
| 1147 | { |
| 1148 | struct iwl_bcast_filter_cmd cmd; |
| 1149 | struct iwl_fw_bcast_mac mac = {}; |
| 1150 | u32 mac_id, attached_filters; |
| 1151 | int err = 0; |
| 1152 | |
| 1153 | if (!mvm->bcast_filters) |
| 1154 | return -ENOENT; |
| 1155 | |
| 1156 | if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard, |
| 1157 | &attached_filters) != 3) |
| 1158 | return -EINVAL; |
| 1159 | |
| 1160 | if (mac_id >= ARRAY_SIZE(cmd.macs) || |
| 1161 | mac.default_discard > 1 || |
| 1162 | attached_filters >= BIT(ARRAY_SIZE(cmd.filters))) |
| 1163 | return -EINVAL; |
| 1164 | |
| 1165 | mac.attached_filters = cpu_to_le16(attached_filters); |
| 1166 | |
| 1167 | mutex_lock(&mvm->mutex); |
| 1168 | memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id], |
| 1169 | &mac, sizeof(mac)); |
| 1170 | |
| 1171 | /* send updated bcast filtering configuration */ |
| 1172 | if (mvm->dbgfs_bcast_filtering.override && |
| 1173 | iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1174 | err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1175 | sizeof(cmd), &cmd); |
| 1176 | mutex_unlock(&mvm->mutex); |
| 1177 | |
| 1178 | return err ?: count; |
| 1179 | } |
| 1180 | #endif |
| 1181 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1182 | #ifdef CONFIG_PM_SLEEP |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1183 | static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf, |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1184 | size_t count, loff_t *ppos) |
| 1185 | { |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1186 | int store; |
| 1187 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1188 | if (sscanf(buf, "%d", &store) != 1) |
| 1189 | return -EINVAL; |
| 1190 | |
| 1191 | mvm->store_d3_resume_sram = store; |
| 1192 | |
| 1193 | return count; |
| 1194 | } |
| 1195 | |
| 1196 | static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf, |
| 1197 | size_t count, loff_t *ppos) |
| 1198 | { |
| 1199 | struct iwl_mvm *mvm = file->private_data; |
| 1200 | const struct fw_img *img; |
| 1201 | int ofs, len, pos = 0; |
| 1202 | size_t bufsz, ret; |
| 1203 | char *buf; |
| 1204 | u8 *ptr = mvm->d3_resume_sram; |
| 1205 | |
| 1206 | img = &mvm->fw->img[IWL_UCODE_WOWLAN]; |
| 1207 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 1208 | |
| 1209 | bufsz = len * 4 + 256; |
| 1210 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 1211 | if (!buf) |
| 1212 | return -ENOMEM; |
| 1213 | |
| 1214 | pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n", |
| 1215 | mvm->store_d3_resume_sram ? "en" : "dis"); |
| 1216 | |
| 1217 | if (ptr) { |
| 1218 | for (ofs = 0; ofs < len; ofs += 16) { |
| 1219 | pos += scnprintf(buf + pos, bufsz - pos, |
Andy Shevchenko | 3cd6e2f | 2015-07-16 15:42:14 +0300 | [diff] [blame] | 1220 | "0x%.4x %16ph\n", ofs, ptr + ofs); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1221 | } |
| 1222 | } else { |
| 1223 | pos += scnprintf(buf + pos, bufsz - pos, |
| 1224 | "(no data captured)\n"); |
| 1225 | } |
| 1226 | |
| 1227 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1228 | |
| 1229 | kfree(buf); |
| 1230 | |
| 1231 | return ret; |
| 1232 | } |
| 1233 | #endif |
| 1234 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1235 | #define PRINT_MVM_REF(ref) do { \ |
| 1236 | if (mvm->refs[ref]) \ |
| 1237 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 1238 | "\t(0x%lx): %d %s\n", \ |
| 1239 | BIT(ref), mvm->refs[ref], #ref); \ |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1240 | } while (0) |
| 1241 | |
| 1242 | static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file, |
| 1243 | char __user *user_buf, |
| 1244 | size_t count, loff_t *ppos) |
| 1245 | { |
| 1246 | struct iwl_mvm *mvm = file->private_data; |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1247 | int i, pos = 0; |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1248 | char buf[256]; |
| 1249 | const size_t bufsz = sizeof(buf); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1250 | u32 refs = 0; |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1251 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1252 | for (i = 0; i < IWL_MVM_REF_COUNT; i++) |
| 1253 | if (mvm->refs[i]) |
| 1254 | refs |= BIT(i); |
| 1255 | |
| 1256 | pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n", |
| 1257 | refs); |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1258 | |
| 1259 | PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN); |
| 1260 | PRINT_MVM_REF(IWL_MVM_REF_SCAN); |
| 1261 | PRINT_MVM_REF(IWL_MVM_REF_ROC); |
Eliad Peller | c779273 | 2015-04-19 11:41:04 +0300 | [diff] [blame] | 1262 | PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX); |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1263 | PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT); |
| 1264 | PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS); |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1265 | PRINT_MVM_REF(IWL_MVM_REF_USER); |
Johannes Berg | 34e611e | 2014-09-12 10:28:01 +0200 | [diff] [blame] | 1266 | PRINT_MVM_REF(IWL_MVM_REF_TX); |
| 1267 | PRINT_MVM_REF(IWL_MVM_REF_TX_AGG); |
| 1268 | PRINT_MVM_REF(IWL_MVM_REF_ADD_IF); |
| 1269 | PRINT_MVM_REF(IWL_MVM_REF_START_AP); |
| 1270 | PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED); |
| 1271 | PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX); |
| 1272 | PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS); |
| 1273 | PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL); |
| 1274 | PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ); |
| 1275 | PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE); |
| 1276 | PRINT_MVM_REF(IWL_MVM_REF_NMI); |
| 1277 | PRINT_MVM_REF(IWL_MVM_REF_TM_CMD); |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1278 | PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK); |
Eliad Peller | 160acc0 | 2014-11-25 12:34:45 +0200 | [diff] [blame] | 1279 | PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA); |
Liad Kaufman | fb2380a | 2015-01-01 17:42:46 +0200 | [diff] [blame] | 1280 | PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT); |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1281 | |
| 1282 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1283 | } |
| 1284 | |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1285 | static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf, |
| 1286 | size_t count, loff_t *ppos) |
| 1287 | { |
| 1288 | unsigned long value; |
| 1289 | int ret; |
| 1290 | bool taken; |
| 1291 | |
| 1292 | ret = kstrtoul(buf, 10, &value); |
| 1293 | if (ret < 0) |
| 1294 | return ret; |
| 1295 | |
| 1296 | mutex_lock(&mvm->mutex); |
| 1297 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1298 | taken = mvm->refs[IWL_MVM_REF_USER]; |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1299 | if (value == 1 && !taken) |
| 1300 | iwl_mvm_ref(mvm, IWL_MVM_REF_USER); |
| 1301 | else if (value == 0 && taken) |
| 1302 | iwl_mvm_unref(mvm, IWL_MVM_REF_USER); |
| 1303 | else |
| 1304 | ret = -EINVAL; |
| 1305 | |
| 1306 | mutex_unlock(&mvm->mutex); |
| 1307 | |
| 1308 | if (ret < 0) |
| 1309 | return ret; |
| 1310 | return count; |
| 1311 | } |
| 1312 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1313 | #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \ |
| 1314 | _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) |
| 1315 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \ |
| 1316 | _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1317 | #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \ |
| 1318 | if (!debugfs_create_file(alias, mode, parent, mvm, \ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1319 | &iwl_dbgfs_##name##_ops)) \ |
| 1320 | goto err; \ |
| 1321 | } while (0) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1322 | #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \ |
| 1323 | MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1324 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1325 | static ssize_t |
| 1326 | iwl_dbgfs_prph_reg_read(struct file *file, |
| 1327 | char __user *user_buf, |
| 1328 | size_t count, loff_t *ppos) |
| 1329 | { |
| 1330 | struct iwl_mvm *mvm = file->private_data; |
| 1331 | int pos = 0; |
| 1332 | char buf[32]; |
| 1333 | const size_t bufsz = sizeof(buf); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1334 | int ret; |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1335 | |
| 1336 | if (!mvm->dbgfs_prph_reg_addr) |
| 1337 | return -EINVAL; |
| 1338 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1339 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ); |
| 1340 | if (ret) |
| 1341 | return ret; |
| 1342 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1343 | pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n", |
| 1344 | mvm->dbgfs_prph_reg_addr, |
| 1345 | iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr)); |
| 1346 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1347 | iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ); |
| 1348 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1349 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1350 | } |
| 1351 | |
| 1352 | static ssize_t |
| 1353 | iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf, |
| 1354 | size_t count, loff_t *ppos) |
| 1355 | { |
| 1356 | u8 args; |
| 1357 | u32 value; |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1358 | int ret; |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1359 | |
| 1360 | args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value); |
| 1361 | /* if we only want to set the reg address - nothing more to do */ |
| 1362 | if (args == 1) |
| 1363 | goto out; |
| 1364 | |
| 1365 | /* otherwise, make sure we have both address and value */ |
| 1366 | if (args != 2) |
| 1367 | return -EINVAL; |
| 1368 | |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1369 | ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE); |
| 1370 | if (ret) |
| 1371 | return ret; |
| 1372 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1373 | iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value); |
Eliad Peller | 576eeee | 2014-07-01 18:38:38 +0300 | [diff] [blame] | 1374 | |
| 1375 | iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE); |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1376 | out: |
| 1377 | return count; |
| 1378 | } |
| 1379 | |
Emmanuel Grumbach | e504601 | 2015-08-17 10:45:50 +0300 | [diff] [blame] | 1380 | static ssize_t |
| 1381 | iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf, |
| 1382 | size_t count, loff_t *ppos) |
| 1383 | { |
| 1384 | int ret; |
| 1385 | |
| 1386 | mutex_lock(&mvm->mutex); |
| 1387 | ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); |
| 1388 | mutex_unlock(&mvm->mutex); |
| 1389 | |
| 1390 | return ret ?: count; |
| 1391 | } |
| 1392 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1393 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64); |
| 1394 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1395 | /* Device wide debugfs entries */ |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1396 | MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16); |
| 1397 | MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8); |
Emmanuel Grumbach | e504601 | 2015-08-17 10:45:50 +0300 | [diff] [blame] | 1398 | MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1399 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64); |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 1400 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64); |
Luciano Coelho | c549e39 | 2014-09-04 15:58:47 +0300 | [diff] [blame] | 1401 | MVM_DEBUGFS_READ_FILE_OPS(nic_temp); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1402 | MVM_DEBUGFS_READ_FILE_OPS(stations); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 1403 | MVM_DEBUGFS_READ_FILE_OPS(bt_notif); |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 1404 | MVM_DEBUGFS_READ_FILE_OPS(bt_cmd); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1405 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 1406 | MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 1407 | MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1408 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10); |
| 1409 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 1410 | MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10); |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 1411 | MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1412 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8); |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1413 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8); |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 1414 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8); |
| 1415 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 8); |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 1416 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1417 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1418 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256); |
| 1419 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256); |
| 1420 | #endif |
| 1421 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1422 | #ifdef CONFIG_PM_SLEEP |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1423 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1424 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1425 | |
| 1426 | int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) |
| 1427 | { |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1428 | struct dentry *bcast_dir __maybe_unused; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1429 | char buf[100]; |
| 1430 | |
Johannes Berg | d07913a | 2014-02-26 11:25:58 +0100 | [diff] [blame] | 1431 | spin_lock_init(&mvm->drv_stats_lock); |
| 1432 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1433 | mvm->debugfs_dir = dbgfs_dir; |
| 1434 | |
| 1435 | MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR); |
| 1436 | MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR); |
| 1437 | MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR); |
Matti Gottlieb | 7280d1f | 2014-07-17 16:41:14 +0300 | [diff] [blame] | 1438 | MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, |
| 1439 | S_IWUSR | S_IRUSR); |
Luciano Coelho | c549e39 | 2014-09-04 15:58:47 +0300 | [diff] [blame] | 1440 | MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1441 | MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 1442 | MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 1443 | MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 639eaba | 2014-03-30 10:11:13 +0300 | [diff] [blame] | 1444 | MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, |
| 1445 | S_IRUSR | S_IWUSR); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 1446 | MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 1447 | MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 1448 | MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR); |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 1449 | MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 1450 | MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR); |
Emmanuel Grumbach | a39979a | 2014-05-28 12:06:41 +0300 | [diff] [blame] | 1451 | MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR); |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 1452 | MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, |
| 1453 | S_IWUSR | S_IRUSR); |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1454 | MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR); |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1455 | MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR); |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 1456 | MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR); |
| 1457 | MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR); |
Emmanuel Grumbach | e504601 | 2015-08-17 10:45:50 +0300 | [diff] [blame] | 1458 | MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR); |
Luciano Coelho | cb2513b | 2015-02-27 16:26:57 +0200 | [diff] [blame] | 1459 | if (!debugfs_create_bool("enable_scan_iteration_notif", |
| 1460 | S_IRUSR | S_IWUSR, |
| 1461 | mvm->debugfs_dir, |
| 1462 | &mvm->scan_iter_notif_enabled)) |
| 1463 | goto err; |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1464 | |
| 1465 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1466 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) { |
| 1467 | bcast_dir = debugfs_create_dir("bcast_filtering", |
| 1468 | mvm->debugfs_dir); |
| 1469 | if (!bcast_dir) |
| 1470 | goto err; |
| 1471 | |
| 1472 | if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR, |
| 1473 | bcast_dir, |
| 1474 | &mvm->dbgfs_bcast_filtering.override)) |
| 1475 | goto err; |
| 1476 | |
| 1477 | MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters, |
| 1478 | bcast_dir, S_IWUSR | S_IRUSR); |
| 1479 | MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs, |
| 1480 | bcast_dir, S_IWUSR | S_IRUSR); |
| 1481 | } |
| 1482 | #endif |
| 1483 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1484 | #ifdef CONFIG_PM_SLEEP |
| 1485 | 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] | 1486 | MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR); |
Johannes Berg | b011471 | 2013-06-12 14:55:40 +0200 | [diff] [blame] | 1487 | if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR, |
| 1488 | mvm->debugfs_dir, &mvm->d3_wake_sysassert)) |
| 1489 | goto err; |
Luciano Coelho | 484b3d1 | 2015-03-30 20:46:32 +0300 | [diff] [blame] | 1490 | if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR, |
| 1491 | mvm->debugfs_dir, &mvm->last_netdetect_scans)) |
| 1492 | goto err; |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1493 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1494 | |
Luciano Coelho | bdd5483 | 2014-08-07 18:08:56 +0300 | [diff] [blame] | 1495 | if (!debugfs_create_u8("ps_disabled", S_IRUSR, |
| 1496 | mvm->debugfs_dir, &mvm->ps_disabled)) |
| 1497 | goto err; |
Emmanuel Grumbach | 086f736 | 2013-11-18 17:00:03 +0200 | [diff] [blame] | 1498 | if (!debugfs_create_blob("nvm_hw", S_IRUSR, |
| 1499 | mvm->debugfs_dir, &mvm->nvm_hw_blob)) |
| 1500 | goto err; |
| 1501 | if (!debugfs_create_blob("nvm_sw", S_IRUSR, |
| 1502 | mvm->debugfs_dir, &mvm->nvm_sw_blob)) |
| 1503 | goto err; |
| 1504 | if (!debugfs_create_blob("nvm_calib", S_IRUSR, |
| 1505 | mvm->debugfs_dir, &mvm->nvm_calib_blob)) |
| 1506 | goto err; |
| 1507 | if (!debugfs_create_blob("nvm_prod", S_IRUSR, |
| 1508 | mvm->debugfs_dir, &mvm->nvm_prod_blob)) |
| 1509 | goto err; |
Moshe Harel | 91fac94 | 2015-09-02 12:45:12 +0300 | [diff] [blame] | 1510 | if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR, |
| 1511 | mvm->debugfs_dir, &mvm->nvm_phy_sku_blob)) |
| 1512 | goto err; |
Emmanuel Grumbach | 086f736 | 2013-11-18 17:00:03 +0200 | [diff] [blame] | 1513 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1514 | /* |
| 1515 | * Create a symlink with mac80211. It will be removed when mac80211 |
| 1516 | * exists (before the opmode exists which removes the target.) |
| 1517 | */ |
| 1518 | snprintf(buf, 100, "../../%s/%s", |
| 1519 | dbgfs_dir->d_parent->d_parent->d_name.name, |
| 1520 | dbgfs_dir->d_parent->d_name.name); |
| 1521 | if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf)) |
| 1522 | goto err; |
| 1523 | |
| 1524 | return 0; |
| 1525 | err: |
| 1526 | IWL_ERR(mvm, "Can't create the mvm debugfs directory\n"); |
| 1527 | return -ENOMEM; |
| 1528 | } |