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. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 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 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 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 | *****************************************************************************/ |
Emmanuel Grumbach | 192c80a | 2014-03-19 08:25:05 +0200 | [diff] [blame] | 63 | #include <linux/vmalloc.h> |
| 64 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 65 | #include "mvm.h" |
| 66 | #include "sta.h" |
| 67 | #include "iwl-io.h" |
Johannes Berg | 820a1a5 | 2013-11-12 16:58:41 +0100 | [diff] [blame] | 68 | #include "debugfs.h" |
Johannes Berg | 4d07500 | 2014-04-24 10:41:31 +0200 | [diff] [blame] | 69 | #include "iwl-fw-error-dump.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 71 | 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] | 72 | size_t count, loff_t *ppos) |
| 73 | { |
Johannes Berg | 8a0bd16 | 2013-11-12 16:48:03 +0100 | [diff] [blame] | 74 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 75 | u32 scd_q_msk; |
| 76 | |
| 77 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 78 | return -EIO; |
| 79 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 80 | if (sscanf(buf, "%x", &scd_q_msk) != 1) |
| 81 | return -EINVAL; |
| 82 | |
| 83 | IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk); |
| 84 | |
| 85 | mutex_lock(&mvm->mutex); |
| 86 | ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count; |
| 87 | mutex_unlock(&mvm->mutex); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 92 | 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] | 93 | size_t count, loff_t *ppos) |
| 94 | { |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 95 | struct iwl_mvm_sta *mvmsta; |
Johannes Berg | 8a0bd16 | 2013-11-12 16:48:03 +0100 | [diff] [blame] | 96 | int sta_id, drain, ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 97 | |
| 98 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) |
| 99 | return -EIO; |
| 100 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 101 | if (sscanf(buf, "%d %d", &sta_id, &drain) != 2) |
| 102 | return -EINVAL; |
Johannes Berg | 60765a4 | 2013-10-25 13:06:06 +0200 | [diff] [blame] | 103 | if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT) |
| 104 | return -EINVAL; |
| 105 | if (drain < 0 || drain > 1) |
| 106 | return -EINVAL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 107 | |
| 108 | mutex_lock(&mvm->mutex); |
| 109 | |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 110 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
| 111 | |
| 112 | if (!mvmsta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 113 | ret = -ENOENT; |
| 114 | else |
Emmanuel Grumbach | f327b04 | 2014-01-14 08:30:32 +0200 | [diff] [blame] | 115 | ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 116 | |
| 117 | mutex_unlock(&mvm->mutex); |
| 118 | |
| 119 | return ret; |
| 120 | } |
| 121 | |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 122 | static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file) |
| 123 | { |
| 124 | struct iwl_mvm *mvm = inode->i_private; |
| 125 | int ret; |
| 126 | |
| 127 | if (!mvm) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | mutex_lock(&mvm->mutex); |
| 131 | if (!mvm->fw_error_dump) { |
| 132 | ret = -ENODATA; |
| 133 | goto out; |
| 134 | } |
| 135 | |
| 136 | file->private_data = mvm->fw_error_dump; |
| 137 | mvm->fw_error_dump = NULL; |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 138 | ret = 0; |
| 139 | |
| 140 | out: |
| 141 | mutex_unlock(&mvm->mutex); |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file, |
| 146 | char __user *user_buf, |
| 147 | size_t count, loff_t *ppos) |
| 148 | { |
| 149 | struct iwl_fw_error_dump_file *dump_file = file->private_data; |
| 150 | |
| 151 | return simple_read_from_buffer(user_buf, count, ppos, |
| 152 | dump_file, |
| 153 | le32_to_cpu(dump_file->file_len)); |
| 154 | } |
| 155 | |
| 156 | static int iwl_dbgfs_fw_error_dump_release(struct inode *inode, |
| 157 | struct file *file) |
| 158 | { |
| 159 | vfree(file->private_data); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 164 | static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, |
| 165 | size_t count, loff_t *ppos) |
| 166 | { |
| 167 | struct iwl_mvm *mvm = file->private_data; |
| 168 | const struct fw_img *img; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 169 | unsigned int ofs, len; |
| 170 | size_t ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 171 | u8 *ptr; |
| 172 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 173 | if (!mvm->ucode_loaded) |
| 174 | return -EINVAL; |
| 175 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 176 | /* default is to dump the entire data segment */ |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 177 | img = &mvm->fw->img[mvm->cur_ucode]; |
| 178 | ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 179 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 180 | |
Emmanuel Grumbach | 01e0efe | 2014-01-06 09:05:54 +0200 | [diff] [blame] | 181 | if (mvm->dbgfs_sram_len) { |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 182 | ofs = mvm->dbgfs_sram_offset; |
| 183 | len = mvm->dbgfs_sram_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 184 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 185 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 186 | ptr = kzalloc(len, GFP_KERNEL); |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 187 | if (!ptr) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 188 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 189 | |
Johannes Berg | 60191d9 | 2013-05-15 13:08:51 +0200 | [diff] [blame] | 190 | iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 191 | |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 192 | ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 193 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 194 | kfree(ptr); |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 199 | static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf, |
| 200 | size_t count, loff_t *ppos) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 201 | { |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 202 | const struct fw_img *img; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 203 | u32 offset, len; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 204 | u32 img_offset, img_len; |
| 205 | |
| 206 | if (!mvm->ucode_loaded) |
| 207 | return -EINVAL; |
| 208 | |
| 209 | img = &mvm->fw->img[mvm->cur_ucode]; |
| 210 | img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 211 | img_len = img->sec[IWL_UCODE_SECTION_DATA].len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 212 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 213 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { |
| 214 | if ((offset & 0x3) || (len & 0x3)) |
| 215 | return -EINVAL; |
Emmanuel Grumbach | d510342 | 2013-12-24 14:58:29 +0200 | [diff] [blame] | 216 | |
| 217 | if (offset + len > img_offset + img_len) |
| 218 | return -EINVAL; |
| 219 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 220 | mvm->dbgfs_sram_offset = offset; |
| 221 | mvm->dbgfs_sram_len = len; |
| 222 | } else { |
| 223 | mvm->dbgfs_sram_offset = 0; |
| 224 | mvm->dbgfs_sram_len = 0; |
| 225 | } |
| 226 | |
| 227 | return count; |
| 228 | } |
| 229 | |
| 230 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, |
| 231 | size_t count, loff_t *ppos) |
| 232 | { |
| 233 | struct iwl_mvm *mvm = file->private_data; |
| 234 | struct ieee80211_sta *sta; |
| 235 | char buf[400]; |
| 236 | int i, pos = 0, bufsz = sizeof(buf); |
| 237 | |
| 238 | mutex_lock(&mvm->mutex); |
| 239 | |
| 240 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 241 | pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); |
| 242 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 243 | lockdep_is_held(&mvm->mutex)); |
| 244 | if (!sta) |
| 245 | pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); |
| 246 | else if (IS_ERR(sta)) |
| 247 | pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", |
| 248 | PTR_ERR(sta)); |
| 249 | else |
| 250 | pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", |
| 251 | sta->addr); |
| 252 | } |
| 253 | |
| 254 | mutex_unlock(&mvm->mutex); |
| 255 | |
| 256 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 257 | } |
| 258 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 259 | static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file, |
| 260 | char __user *user_buf, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 261 | size_t count, loff_t *ppos) |
| 262 | { |
| 263 | struct iwl_mvm *mvm = file->private_data; |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 264 | char buf[64]; |
| 265 | int bufsz = sizeof(buf); |
| 266 | int pos = 0; |
| 267 | |
| 268 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n", |
| 269 | mvm->disable_power_off); |
| 270 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n", |
| 271 | mvm->disable_power_off_d3); |
| 272 | |
| 273 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 274 | } |
| 275 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 276 | 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] | 277 | size_t count, loff_t *ppos) |
| 278 | { |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 279 | int ret, val; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 280 | |
| 281 | if (!mvm->ucode_loaded) |
| 282 | return -EIO; |
| 283 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 284 | if (!strncmp("disable_power_off_d0=", buf, 21)) { |
| 285 | if (sscanf(buf + 21, "%d", &val) != 1) |
| 286 | return -EINVAL; |
| 287 | mvm->disable_power_off = val; |
| 288 | } else if (!strncmp("disable_power_off_d3=", buf, 21)) { |
| 289 | if (sscanf(buf + 21, "%d", &val) != 1) |
| 290 | return -EINVAL; |
| 291 | mvm->disable_power_off_d3 = val; |
| 292 | } else { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 293 | return -EINVAL; |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 294 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 295 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 296 | mutex_lock(&mvm->mutex); |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 297 | ret = iwl_mvm_power_update_device(mvm); |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 298 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 299 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 300 | return ret ?: count; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 303 | #define BT_MBOX_MSG(_notif, _num, _field) \ |
| 304 | ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\ |
| 305 | >> BT_MBOX##_num##_##_field##_POS) |
| 306 | |
| 307 | |
| 308 | #define BT_MBOX_PRINT(_num, _field, _end) \ |
| 309 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 310 | "\t%s: %d%s", \ |
| 311 | #_field, \ |
| 312 | BT_MBOX_MSG(notif, _num, _field), \ |
| 313 | true ? "\n" : ", "); |
| 314 | |
| 315 | static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, |
| 316 | size_t count, loff_t *ppos) |
| 317 | { |
| 318 | struct iwl_mvm *mvm = file->private_data; |
| 319 | struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; |
| 320 | char *buf; |
| 321 | int ret, pos = 0, bufsz = sizeof(char) * 1024; |
| 322 | |
| 323 | buf = kmalloc(bufsz, GFP_KERNEL); |
| 324 | if (!buf) |
| 325 | return -ENOMEM; |
| 326 | |
| 327 | mutex_lock(&mvm->mutex); |
| 328 | |
| 329 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); |
| 330 | |
| 331 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); |
| 332 | BT_MBOX_PRINT(0, LE_PROF1, false); |
| 333 | BT_MBOX_PRINT(0, LE_PROF2, false); |
| 334 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); |
| 335 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); |
| 336 | BT_MBOX_PRINT(0, INBAND_S, false); |
| 337 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); |
| 338 | BT_MBOX_PRINT(0, LE_SCAN, false); |
| 339 | BT_MBOX_PRINT(0, LE_ADV, false); |
| 340 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); |
| 341 | BT_MBOX_PRINT(0, OPEN_CON_1, true); |
| 342 | |
| 343 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); |
| 344 | |
| 345 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); |
| 346 | BT_MBOX_PRINT(1, IP_SR, false); |
| 347 | BT_MBOX_PRINT(1, LE_MSTR, false); |
| 348 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); |
| 349 | BT_MBOX_PRINT(1, MSG_TYPE, false); |
| 350 | BT_MBOX_PRINT(1, SSN, true); |
| 351 | |
| 352 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); |
| 353 | |
| 354 | BT_MBOX_PRINT(2, SNIFF_ACT, false); |
| 355 | BT_MBOX_PRINT(2, PAG, false); |
| 356 | BT_MBOX_PRINT(2, INQUIRY, false); |
| 357 | BT_MBOX_PRINT(2, CONN, false); |
| 358 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); |
| 359 | BT_MBOX_PRINT(2, DISC, false); |
| 360 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); |
| 361 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); |
| 362 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); |
| 363 | BT_MBOX_PRINT(2, SCO_DURATION, true); |
| 364 | |
| 365 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); |
| 366 | |
| 367 | BT_MBOX_PRINT(3, SCO_STATE, false); |
| 368 | BT_MBOX_PRINT(3, SNIFF_STATE, false); |
| 369 | BT_MBOX_PRINT(3, A2DP_STATE, false); |
| 370 | BT_MBOX_PRINT(3, ACL_STATE, false); |
| 371 | BT_MBOX_PRINT(3, MSTR_STATE, false); |
| 372 | BT_MBOX_PRINT(3, OBX_STATE, false); |
| 373 | BT_MBOX_PRINT(3, OPEN_CON_2, false); |
| 374 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); |
| 375 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); |
| 376 | BT_MBOX_PRINT(3, INBAND_P, false); |
| 377 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); |
| 378 | BT_MBOX_PRINT(3, SSN_2, false); |
| 379 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); |
| 380 | |
| 381 | pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n", |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 382 | notif->bt_status); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 383 | pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n", |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 384 | notif->bt_open_conn); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 385 | pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n", |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 386 | notif->bt_traffic_load); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 387 | pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n", |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 388 | notif->bt_agg_traffic_load); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 389 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 390 | notif->bt_ci_compliance); |
| 391 | pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n", |
| 392 | le32_to_cpu(notif->primary_ch_lut)); |
| 393 | pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n", |
| 394 | le32_to_cpu(notif->secondary_ch_lut)); |
| 395 | pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n", |
| 396 | le32_to_cpu(notif->bt_activity_grading)); |
Emmanuel Grumbach | b9fae2d | 2014-02-17 11:24:10 +0200 | [diff] [blame] | 397 | pos += scnprintf(buf+pos, bufsz-pos, |
| 398 | "antenna isolation = %d CORUN LUT index = %d\n", |
| 399 | mvm->last_ant_isol, mvm->last_corun_lut); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 400 | |
| 401 | mutex_unlock(&mvm->mutex); |
| 402 | |
| 403 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 404 | kfree(buf); |
| 405 | |
| 406 | return ret; |
| 407 | } |
| 408 | #undef BT_MBOX_PRINT |
| 409 | |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 410 | static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf, |
| 411 | size_t count, loff_t *ppos) |
| 412 | { |
| 413 | struct iwl_mvm *mvm = file->private_data; |
| 414 | struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd; |
| 415 | char buf[256]; |
| 416 | int bufsz = sizeof(buf); |
| 417 | int pos = 0; |
| 418 | |
| 419 | mutex_lock(&mvm->mutex); |
| 420 | |
| 421 | pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n"); |
| 422 | pos += scnprintf(buf+pos, bufsz-pos, |
| 423 | "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n", |
| 424 | le64_to_cpu(cmd->bt_primary_ci), |
| 425 | !!cmd->co_run_bw_primary); |
| 426 | pos += scnprintf(buf+pos, bufsz-pos, |
| 427 | "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n", |
| 428 | le64_to_cpu(cmd->bt_secondary_ci), |
| 429 | !!cmd->co_run_bw_secondary); |
| 430 | |
| 431 | pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n"); |
| 432 | pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n", |
| 433 | iwl_bt_ack_kill_msk[mvm->bt_kill_msk]); |
| 434 | pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n", |
| 435 | iwl_bt_cts_kill_msk[mvm->bt_kill_msk]); |
| 436 | |
| 437 | mutex_unlock(&mvm->mutex); |
| 438 | |
| 439 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 440 | } |
| 441 | |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 442 | static ssize_t |
| 443 | iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf, |
| 444 | size_t count, loff_t *ppos) |
| 445 | { |
| 446 | u32 bt_tx_prio; |
| 447 | |
| 448 | if (sscanf(buf, "%u", &bt_tx_prio) != 1) |
| 449 | return -EINVAL; |
| 450 | if (bt_tx_prio > 4) |
| 451 | return -EINVAL; |
| 452 | |
| 453 | mvm->bt_tx_prio = bt_tx_prio; |
| 454 | |
| 455 | return count; |
| 456 | } |
| 457 | |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 458 | #define PRINT_STATS_LE32(_str, _val) \ |
| 459 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 460 | fmt_table, _str, \ |
| 461 | le32_to_cpu(_val)) |
| 462 | |
| 463 | static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file, |
| 464 | char __user *user_buf, size_t count, |
| 465 | loff_t *ppos) |
| 466 | { |
| 467 | struct iwl_mvm *mvm = file->private_data; |
| 468 | static const char *fmt_table = "\t%-30s %10u\n"; |
| 469 | static const char *fmt_header = "%-32s\n"; |
| 470 | int pos = 0; |
| 471 | char *buf; |
| 472 | int ret; |
Luciano Coelho | 3f61728 | 2013-10-14 13:18:41 +0300 | [diff] [blame] | 473 | /* 43 is the size of each data line, 33 is the size of each header */ |
| 474 | size_t bufsz = |
| 475 | ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) + |
| 476 | (4 * 33) + 1; |
| 477 | |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 478 | struct mvm_statistics_rx_phy *ofdm; |
| 479 | struct mvm_statistics_rx_phy *cck; |
| 480 | struct mvm_statistics_rx_non_phy *general; |
| 481 | struct mvm_statistics_rx_ht_phy *ht; |
| 482 | |
| 483 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 484 | if (!buf) |
| 485 | return -ENOMEM; |
| 486 | |
| 487 | mutex_lock(&mvm->mutex); |
| 488 | |
| 489 | ofdm = &mvm->rx_stats.ofdm; |
| 490 | cck = &mvm->rx_stats.cck; |
| 491 | general = &mvm->rx_stats.general; |
| 492 | ht = &mvm->rx_stats.ofdm_ht; |
| 493 | |
| 494 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 495 | "Statistics_Rx - OFDM"); |
| 496 | PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt); |
| 497 | PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt); |
| 498 | PRINT_STATS_LE32("plcp_err", ofdm->plcp_err); |
| 499 | PRINT_STATS_LE32("crc32_err", ofdm->crc32_err); |
| 500 | PRINT_STATS_LE32("overrun_err", ofdm->overrun_err); |
| 501 | PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err); |
| 502 | PRINT_STATS_LE32("crc32_good", ofdm->crc32_good); |
| 503 | PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt); |
| 504 | PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt); |
| 505 | PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout); |
| 506 | PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout); |
| 507 | PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts); |
| 508 | PRINT_STATS_LE32("rxe_frame_lmt_overrun", |
| 509 | ofdm->rxe_frame_limit_overrun); |
| 510 | PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt); |
| 511 | PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt); |
| 512 | PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt); |
| 513 | PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill); |
| 514 | PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err); |
| 515 | PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum); |
| 516 | PRINT_STATS_LE32("reserved", ofdm->reserved); |
| 517 | |
| 518 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 519 | "Statistics_Rx - CCK"); |
| 520 | PRINT_STATS_LE32("ina_cnt", cck->ina_cnt); |
| 521 | PRINT_STATS_LE32("fina_cnt", cck->fina_cnt); |
| 522 | PRINT_STATS_LE32("plcp_err", cck->plcp_err); |
| 523 | PRINT_STATS_LE32("crc32_err", cck->crc32_err); |
| 524 | PRINT_STATS_LE32("overrun_err", cck->overrun_err); |
| 525 | PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err); |
| 526 | PRINT_STATS_LE32("crc32_good", cck->crc32_good); |
| 527 | PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt); |
| 528 | PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt); |
| 529 | PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout); |
| 530 | PRINT_STATS_LE32("fina_timeout", cck->fina_timeout); |
| 531 | PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts); |
| 532 | PRINT_STATS_LE32("rxe_frame_lmt_overrun", |
| 533 | cck->rxe_frame_limit_overrun); |
| 534 | PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt); |
| 535 | PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt); |
| 536 | PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt); |
| 537 | PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill); |
| 538 | PRINT_STATS_LE32("mh_format_err", cck->mh_format_err); |
| 539 | PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum); |
| 540 | PRINT_STATS_LE32("reserved", cck->reserved); |
| 541 | |
| 542 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 543 | "Statistics_Rx - GENERAL"); |
| 544 | PRINT_STATS_LE32("bogus_cts", general->bogus_cts); |
| 545 | PRINT_STATS_LE32("bogus_ack", general->bogus_ack); |
| 546 | PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames); |
| 547 | PRINT_STATS_LE32("filtered_frames", general->filtered_frames); |
| 548 | PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons); |
| 549 | PRINT_STATS_LE32("channel_beacons", general->channel_beacons); |
| 550 | PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon); |
| 551 | PRINT_STATS_LE32("adc_rx_saturation_time", |
| 552 | general->adc_rx_saturation_time); |
| 553 | PRINT_STATS_LE32("ina_detection_search_time", |
| 554 | general->ina_detection_search_time); |
| 555 | PRINT_STATS_LE32("beacon_silence_rssi_a", |
| 556 | general->beacon_silence_rssi_a); |
| 557 | PRINT_STATS_LE32("beacon_silence_rssi_b", |
| 558 | general->beacon_silence_rssi_b); |
| 559 | PRINT_STATS_LE32("beacon_silence_rssi_c", |
| 560 | general->beacon_silence_rssi_c); |
| 561 | PRINT_STATS_LE32("interference_data_flag", |
| 562 | general->interference_data_flag); |
| 563 | PRINT_STATS_LE32("channel_load", general->channel_load); |
| 564 | PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms); |
| 565 | PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a); |
| 566 | PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b); |
| 567 | PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c); |
| 568 | PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a); |
| 569 | PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b); |
| 570 | PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c); |
| 571 | PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills); |
Luciano Coelho | 3f61728 | 2013-10-14 13:18:41 +0300 | [diff] [blame] | 572 | PRINT_STATS_LE32("mac_id", general->mac_id); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 573 | PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu); |
| 574 | |
| 575 | pos += scnprintf(buf + pos, bufsz - pos, fmt_header, |
| 576 | "Statistics_Rx - HT"); |
| 577 | PRINT_STATS_LE32("plcp_err", ht->plcp_err); |
| 578 | PRINT_STATS_LE32("overrun_err", ht->overrun_err); |
| 579 | PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err); |
| 580 | PRINT_STATS_LE32("crc32_good", ht->crc32_good); |
| 581 | PRINT_STATS_LE32("crc32_err", ht->crc32_err); |
| 582 | PRINT_STATS_LE32("mh_format_err", ht->mh_format_err); |
| 583 | PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good); |
| 584 | PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt); |
| 585 | PRINT_STATS_LE32("agg_cnt", ht->agg_cnt); |
| 586 | PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs); |
| 587 | |
| 588 | mutex_unlock(&mvm->mutex); |
| 589 | |
| 590 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 591 | kfree(buf); |
| 592 | |
| 593 | return ret; |
| 594 | } |
| 595 | #undef PRINT_STAT_LE32 |
| 596 | |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 597 | static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm, |
| 598 | char __user *user_buf, size_t count, |
| 599 | loff_t *ppos, |
| 600 | struct iwl_mvm_frame_stats *stats) |
| 601 | { |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 602 | char *buff, *pos, *endpos; |
| 603 | int idx, i; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 604 | int ret; |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 605 | static const size_t bufsz = 1024; |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 606 | |
| 607 | buff = kmalloc(bufsz, GFP_KERNEL); |
| 608 | if (!buff) |
| 609 | return -ENOMEM; |
| 610 | |
| 611 | spin_lock_bh(&mvm->drv_stats_lock); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 612 | |
| 613 | pos = buff; |
| 614 | endpos = pos + bufsz; |
| 615 | |
| 616 | pos += scnprintf(pos, endpos - pos, |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 617 | "Legacy/HT/VHT\t:\t%d/%d/%d\n", |
| 618 | stats->legacy_frames, |
| 619 | stats->ht_frames, |
| 620 | stats->vht_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 621 | 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] | 622 | stats->bw_20_frames, |
| 623 | stats->bw_40_frames, |
| 624 | stats->bw_80_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 625 | 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] | 626 | stats->ngi_frames, |
| 627 | stats->sgi_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 628 | pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 629 | stats->siso_frames, |
| 630 | stats->mimo2_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 631 | pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 632 | stats->fail_frames, |
| 633 | stats->success_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 634 | pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 635 | stats->agg_frames); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 636 | pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 637 | stats->ampdu_count); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 638 | pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 639 | stats->ampdu_count > 0 ? |
| 640 | (stats->agg_frames / stats->ampdu_count) : 0); |
| 641 | |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 642 | pos += scnprintf(pos, endpos - pos, "Last Rates\n"); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 643 | |
| 644 | idx = stats->last_frame_idx - 1; |
| 645 | for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) { |
| 646 | idx = (idx + 1) % ARRAY_SIZE(stats->last_rates); |
| 647 | if (stats->last_rates[idx] == 0) |
| 648 | continue; |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 649 | pos += scnprintf(pos, endpos - pos, "Rate[%d]: ", |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 650 | (int)(ARRAY_SIZE(stats->last_rates) - i)); |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 651 | pos += rs_pretty_print_rate(pos, stats->last_rates[idx]); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 652 | } |
| 653 | spin_unlock_bh(&mvm->drv_stats_lock); |
| 654 | |
Eyal Shapira | f754b5c | 2014-02-24 10:24:34 +0200 | [diff] [blame] | 655 | ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 656 | kfree(buff); |
| 657 | |
| 658 | return ret; |
| 659 | } |
| 660 | |
| 661 | static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file, |
| 662 | char __user *user_buf, size_t count, |
| 663 | loff_t *ppos) |
| 664 | { |
| 665 | struct iwl_mvm *mvm = file->private_data; |
| 666 | |
| 667 | return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos, |
| 668 | &mvm->drv_rx_stats); |
| 669 | } |
| 670 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 671 | 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] | 672 | size_t count, loff_t *ppos) |
| 673 | { |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 674 | int ret; |
| 675 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 676 | mutex_lock(&mvm->mutex); |
| 677 | |
Eran Harary | 291aa7c | 2013-07-03 11:00:06 +0300 | [diff] [blame] | 678 | /* allow one more restart that we're provoking here */ |
| 679 | if (mvm->restart_fw >= 0) |
| 680 | mvm->restart_fw++; |
| 681 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 682 | /* take the return value to make compiler happy - it will fail anyway */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 683 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 684 | |
| 685 | mutex_unlock(&mvm->mutex); |
| 686 | |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 687 | return count; |
| 688 | } |
| 689 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 690 | 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] | 691 | size_t count, loff_t *ppos) |
| 692 | { |
Liad Kaufman | 4c9706d | 2014-04-27 16:46:09 +0300 | [diff] [blame] | 693 | iwl_force_nmi(mvm->trans); |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 694 | |
| 695 | return count; |
| 696 | } |
| 697 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 698 | static ssize_t |
| 699 | iwl_dbgfs_scan_ant_rxchain_read(struct file *file, |
| 700 | char __user *user_buf, |
| 701 | size_t count, loff_t *ppos) |
| 702 | { |
| 703 | struct iwl_mvm *mvm = file->private_data; |
| 704 | int pos = 0; |
| 705 | char buf[32]; |
| 706 | const size_t bufsz = sizeof(buf); |
| 707 | |
| 708 | /* print which antennas were set for the scan command by the user */ |
| 709 | pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: "); |
| 710 | if (mvm->scan_rx_ant & ANT_A) |
| 711 | pos += scnprintf(buf + pos, bufsz - pos, "A"); |
| 712 | if (mvm->scan_rx_ant & ANT_B) |
| 713 | pos += scnprintf(buf + pos, bufsz - pos, "B"); |
| 714 | if (mvm->scan_rx_ant & ANT_C) |
| 715 | pos += scnprintf(buf + pos, bufsz - pos, "C"); |
| 716 | pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant); |
| 717 | |
| 718 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 719 | } |
| 720 | |
| 721 | static ssize_t |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 722 | iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf, |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 723 | size_t count, loff_t *ppos) |
| 724 | { |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 725 | u8 scan_rx_ant; |
| 726 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 727 | if (sscanf(buf, "%hhx", &scan_rx_ant) != 1) |
| 728 | return -EINVAL; |
| 729 | if (scan_rx_ant > ANT_ABC) |
| 730 | return -EINVAL; |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 731 | if (scan_rx_ant & ~mvm->fw->valid_rx_ant) |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 732 | return -EINVAL; |
| 733 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 734 | mvm->scan_rx_ant = scan_rx_ant; |
| 735 | |
| 736 | return count; |
| 737 | } |
| 738 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 739 | #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__) |
| 740 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 741 | static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file, |
| 742 | char __user *user_buf, |
| 743 | size_t count, loff_t *ppos) |
| 744 | { |
| 745 | struct iwl_mvm *mvm = file->private_data; |
| 746 | struct iwl_bcast_filter_cmd cmd; |
| 747 | const struct iwl_fw_bcast_filter *filter; |
| 748 | char *buf; |
| 749 | int bufsz = 1024; |
| 750 | int i, j, pos = 0; |
| 751 | ssize_t ret; |
| 752 | |
| 753 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 754 | if (!buf) |
| 755 | return -ENOMEM; |
| 756 | |
| 757 | mutex_lock(&mvm->mutex); |
| 758 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) { |
| 759 | ADD_TEXT("None\n"); |
| 760 | mutex_unlock(&mvm->mutex); |
| 761 | goto out; |
| 762 | } |
| 763 | mutex_unlock(&mvm->mutex); |
| 764 | |
| 765 | for (i = 0; cmd.filters[i].attrs[0].mask; i++) { |
| 766 | filter = &cmd.filters[i]; |
| 767 | |
| 768 | ADD_TEXT("Filter [%d]:\n", i); |
| 769 | ADD_TEXT("\tDiscard=%d\n", filter->discard); |
| 770 | ADD_TEXT("\tFrame Type: %s\n", |
| 771 | filter->frame_type ? "IPv4" : "Generic"); |
| 772 | |
| 773 | for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) { |
| 774 | const struct iwl_fw_bcast_filter_attr *attr; |
| 775 | |
| 776 | attr = &filter->attrs[j]; |
| 777 | if (!attr->mask) |
| 778 | break; |
| 779 | |
| 780 | ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n", |
| 781 | j, attr->offset, |
| 782 | attr->offset_type ? "IP End" : |
| 783 | "Payload Start", |
| 784 | be32_to_cpu(attr->mask), |
| 785 | be32_to_cpu(attr->val), |
| 786 | le16_to_cpu(attr->reserved1)); |
| 787 | } |
| 788 | } |
| 789 | out: |
| 790 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 791 | kfree(buf); |
| 792 | return ret; |
| 793 | } |
| 794 | |
| 795 | static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf, |
| 796 | size_t count, loff_t *ppos) |
| 797 | { |
| 798 | int pos, next_pos; |
| 799 | struct iwl_fw_bcast_filter filter = {}; |
| 800 | struct iwl_bcast_filter_cmd cmd; |
| 801 | u32 filter_id, attr_id, mask, value; |
| 802 | int err = 0; |
| 803 | |
| 804 | if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard, |
| 805 | &filter.frame_type, &pos) != 3) |
| 806 | return -EINVAL; |
| 807 | |
| 808 | if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) || |
| 809 | filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs); |
| 813 | attr_id++) { |
| 814 | struct iwl_fw_bcast_filter_attr *attr = |
| 815 | &filter.attrs[attr_id]; |
| 816 | |
| 817 | if (pos >= count) |
| 818 | break; |
| 819 | |
| 820 | if (sscanf(&buf[pos], "%hhi %hhi %i %i %n", |
| 821 | &attr->offset, &attr->offset_type, |
| 822 | &mask, &value, &next_pos) != 4) |
| 823 | return -EINVAL; |
| 824 | |
| 825 | attr->mask = cpu_to_be32(mask); |
| 826 | attr->val = cpu_to_be32(value); |
| 827 | if (mask) |
| 828 | filter.num_attrs++; |
| 829 | |
| 830 | pos += next_pos; |
| 831 | } |
| 832 | |
| 833 | mutex_lock(&mvm->mutex); |
| 834 | memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id], |
| 835 | &filter, sizeof(filter)); |
| 836 | |
| 837 | /* send updated bcast filtering configuration */ |
| 838 | if (mvm->dbgfs_bcast_filtering.override && |
| 839 | iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 840 | err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 841 | sizeof(cmd), &cmd); |
| 842 | mutex_unlock(&mvm->mutex); |
| 843 | |
| 844 | return err ?: count; |
| 845 | } |
| 846 | |
| 847 | static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file, |
| 848 | char __user *user_buf, |
| 849 | size_t count, loff_t *ppos) |
| 850 | { |
| 851 | struct iwl_mvm *mvm = file->private_data; |
| 852 | struct iwl_bcast_filter_cmd cmd; |
| 853 | char *buf; |
| 854 | int bufsz = 1024; |
| 855 | int i, pos = 0; |
| 856 | ssize_t ret; |
| 857 | |
| 858 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 859 | if (!buf) |
| 860 | return -ENOMEM; |
| 861 | |
| 862 | mutex_lock(&mvm->mutex); |
| 863 | if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) { |
| 864 | ADD_TEXT("None\n"); |
| 865 | mutex_unlock(&mvm->mutex); |
| 866 | goto out; |
| 867 | } |
| 868 | mutex_unlock(&mvm->mutex); |
| 869 | |
| 870 | for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) { |
| 871 | const struct iwl_fw_bcast_mac *mac = &cmd.macs[i]; |
| 872 | |
| 873 | ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n", |
| 874 | i, mac->default_discard, mac->attached_filters); |
| 875 | } |
| 876 | out: |
| 877 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 878 | kfree(buf); |
| 879 | return ret; |
| 880 | } |
| 881 | |
| 882 | static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm, |
| 883 | char *buf, size_t count, |
| 884 | loff_t *ppos) |
| 885 | { |
| 886 | struct iwl_bcast_filter_cmd cmd; |
| 887 | struct iwl_fw_bcast_mac mac = {}; |
| 888 | u32 mac_id, attached_filters; |
| 889 | int err = 0; |
| 890 | |
| 891 | if (!mvm->bcast_filters) |
| 892 | return -ENOENT; |
| 893 | |
| 894 | if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard, |
| 895 | &attached_filters) != 3) |
| 896 | return -EINVAL; |
| 897 | |
| 898 | if (mac_id >= ARRAY_SIZE(cmd.macs) || |
| 899 | mac.default_discard > 1 || |
| 900 | attached_filters >= BIT(ARRAY_SIZE(cmd.filters))) |
| 901 | return -EINVAL; |
| 902 | |
| 903 | mac.attached_filters = cpu_to_le16(attached_filters); |
| 904 | |
| 905 | mutex_lock(&mvm->mutex); |
| 906 | memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id], |
| 907 | &mac, sizeof(mac)); |
| 908 | |
| 909 | /* send updated bcast filtering configuration */ |
| 910 | if (mvm->dbgfs_bcast_filtering.override && |
| 911 | iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 912 | err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 913 | sizeof(cmd), &cmd); |
| 914 | mutex_unlock(&mvm->mutex); |
| 915 | |
| 916 | return err ?: count; |
| 917 | } |
| 918 | #endif |
| 919 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 920 | #ifdef CONFIG_PM_SLEEP |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 921 | 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] | 922 | size_t count, loff_t *ppos) |
| 923 | { |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 924 | int store; |
| 925 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 926 | if (sscanf(buf, "%d", &store) != 1) |
| 927 | return -EINVAL; |
| 928 | |
| 929 | mvm->store_d3_resume_sram = store; |
| 930 | |
| 931 | return count; |
| 932 | } |
| 933 | |
| 934 | static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf, |
| 935 | size_t count, loff_t *ppos) |
| 936 | { |
| 937 | struct iwl_mvm *mvm = file->private_data; |
| 938 | const struct fw_img *img; |
| 939 | int ofs, len, pos = 0; |
| 940 | size_t bufsz, ret; |
| 941 | char *buf; |
| 942 | u8 *ptr = mvm->d3_resume_sram; |
| 943 | |
| 944 | img = &mvm->fw->img[IWL_UCODE_WOWLAN]; |
| 945 | len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 946 | |
| 947 | bufsz = len * 4 + 256; |
| 948 | buf = kzalloc(bufsz, GFP_KERNEL); |
| 949 | if (!buf) |
| 950 | return -ENOMEM; |
| 951 | |
| 952 | pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n", |
| 953 | mvm->store_d3_resume_sram ? "en" : "dis"); |
| 954 | |
| 955 | if (ptr) { |
| 956 | for (ofs = 0; ofs < len; ofs += 16) { |
| 957 | pos += scnprintf(buf + pos, bufsz - pos, |
| 958 | "0x%.4x ", ofs); |
| 959 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, |
| 960 | bufsz - pos, false); |
| 961 | pos += strlen(buf + pos); |
| 962 | if (bufsz - pos > 0) |
| 963 | buf[pos++] = '\n'; |
| 964 | } |
| 965 | } else { |
| 966 | pos += scnprintf(buf + pos, bufsz - pos, |
| 967 | "(no data captured)\n"); |
| 968 | } |
| 969 | |
| 970 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 971 | |
| 972 | kfree(buf); |
| 973 | |
| 974 | return ret; |
| 975 | } |
| 976 | #endif |
| 977 | |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 978 | #define PRINT_MVM_REF(ref) do { \ |
| 979 | if (test_bit(ref, mvm->ref_bitmap)) \ |
| 980 | pos += scnprintf(buf + pos, bufsz - pos, \ |
| 981 | "\t(0x%lx) %s\n", \ |
| 982 | BIT(ref), #ref); \ |
| 983 | } while (0) |
| 984 | |
| 985 | static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file, |
| 986 | char __user *user_buf, |
| 987 | size_t count, loff_t *ppos) |
| 988 | { |
| 989 | struct iwl_mvm *mvm = file->private_data; |
| 990 | int pos = 0; |
| 991 | char buf[256]; |
| 992 | const size_t bufsz = sizeof(buf); |
| 993 | |
| 994 | pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%lx\n", |
| 995 | mvm->ref_bitmap[0]); |
| 996 | |
| 997 | PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN); |
| 998 | PRINT_MVM_REF(IWL_MVM_REF_SCAN); |
| 999 | PRINT_MVM_REF(IWL_MVM_REF_ROC); |
| 1000 | PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT); |
| 1001 | PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS); |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1002 | PRINT_MVM_REF(IWL_MVM_REF_USER); |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1003 | PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK); |
Eliad Peller | 70d6bab | 2013-11-05 14:45:16 +0200 | [diff] [blame] | 1004 | |
| 1005 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1006 | } |
| 1007 | |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1008 | static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf, |
| 1009 | size_t count, loff_t *ppos) |
| 1010 | { |
| 1011 | unsigned long value; |
| 1012 | int ret; |
| 1013 | bool taken; |
| 1014 | |
| 1015 | ret = kstrtoul(buf, 10, &value); |
| 1016 | if (ret < 0) |
| 1017 | return ret; |
| 1018 | |
| 1019 | mutex_lock(&mvm->mutex); |
| 1020 | |
| 1021 | taken = test_bit(IWL_MVM_REF_USER, mvm->ref_bitmap); |
| 1022 | if (value == 1 && !taken) |
| 1023 | iwl_mvm_ref(mvm, IWL_MVM_REF_USER); |
| 1024 | else if (value == 0 && taken) |
| 1025 | iwl_mvm_unref(mvm, IWL_MVM_REF_USER); |
| 1026 | else |
| 1027 | ret = -EINVAL; |
| 1028 | |
| 1029 | mutex_unlock(&mvm->mutex); |
| 1030 | |
| 1031 | if (ret < 0) |
| 1032 | return ret; |
| 1033 | return count; |
| 1034 | } |
| 1035 | |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1036 | #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \ |
| 1037 | _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) |
| 1038 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \ |
| 1039 | _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1040 | #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \ |
| 1041 | if (!debugfs_create_file(alias, mode, parent, mvm, \ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1042 | &iwl_dbgfs_##name##_ops)) \ |
| 1043 | goto err; \ |
| 1044 | } while (0) |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1045 | #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \ |
| 1046 | MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1047 | |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1048 | static ssize_t |
| 1049 | iwl_dbgfs_prph_reg_read(struct file *file, |
| 1050 | char __user *user_buf, |
| 1051 | size_t count, loff_t *ppos) |
| 1052 | { |
| 1053 | struct iwl_mvm *mvm = file->private_data; |
| 1054 | int pos = 0; |
| 1055 | char buf[32]; |
| 1056 | const size_t bufsz = sizeof(buf); |
| 1057 | |
| 1058 | if (!mvm->dbgfs_prph_reg_addr) |
| 1059 | return -EINVAL; |
| 1060 | |
| 1061 | pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n", |
| 1062 | mvm->dbgfs_prph_reg_addr, |
| 1063 | iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr)); |
| 1064 | |
| 1065 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); |
| 1066 | } |
| 1067 | |
| 1068 | static ssize_t |
| 1069 | iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf, |
| 1070 | size_t count, loff_t *ppos) |
| 1071 | { |
| 1072 | u8 args; |
| 1073 | u32 value; |
| 1074 | |
| 1075 | args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value); |
| 1076 | /* if we only want to set the reg address - nothing more to do */ |
| 1077 | if (args == 1) |
| 1078 | goto out; |
| 1079 | |
| 1080 | /* otherwise, make sure we have both address and value */ |
| 1081 | if (args != 2) |
| 1082 | return -EINVAL; |
| 1083 | |
| 1084 | iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value); |
| 1085 | out: |
| 1086 | return count; |
| 1087 | } |
| 1088 | |
| 1089 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64); |
| 1090 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1091 | /* Device wide debugfs entries */ |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1092 | MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16); |
| 1093 | MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8); |
| 1094 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1095 | MVM_DEBUGFS_READ_FILE_OPS(stations); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 1096 | MVM_DEBUGFS_READ_FILE_OPS(bt_notif); |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 1097 | MVM_DEBUGFS_READ_FILE_OPS(bt_cmd); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1098 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 1099 | MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 1100 | MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1101 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10); |
| 1102 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 1103 | MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10); |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1104 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8); |
Eliad Peller | 0eb8365 | 2013-11-11 18:56:35 +0200 | [diff] [blame] | 1105 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8); |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 1106 | |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 1107 | static const struct file_operations iwl_dbgfs_fw_error_dump_ops = { |
Emmanuel Grumbach | 3a58d98e | 2014-04-13 09:38:48 +0300 | [diff] [blame] | 1108 | .open = iwl_dbgfs_fw_error_dump_open, |
| 1109 | .read = iwl_dbgfs_fw_error_dump_read, |
| 1110 | .release = iwl_dbgfs_fw_error_dump_release, |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 1111 | }; |
| 1112 | |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1113 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1114 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256); |
| 1115 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256); |
| 1116 | #endif |
| 1117 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1118 | #ifdef CONFIG_PM_SLEEP |
Johannes Berg | 1fa3f57 | 2013-11-13 09:10:21 +0100 | [diff] [blame] | 1119 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1120 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1121 | |
| 1122 | int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) |
| 1123 | { |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1124 | struct dentry *bcast_dir __maybe_unused; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1125 | char buf[100]; |
| 1126 | |
Johannes Berg | d07913a | 2014-02-26 11:25:58 +0100 | [diff] [blame] | 1127 | spin_lock_init(&mvm->drv_stats_lock); |
| 1128 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1129 | mvm->debugfs_dir = dbgfs_dir; |
| 1130 | |
| 1131 | MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR); |
| 1132 | MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR); |
| 1133 | MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR); |
| 1134 | MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 1bd3cbc | 2014-03-18 21:15:06 +0200 | [diff] [blame] | 1135 | MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 1094234 | 2013-02-19 11:02:36 +0200 | [diff] [blame] | 1136 | MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 2de13ca | 2013-06-30 07:43:28 +0300 | [diff] [blame] | 1137 | MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR); |
Emmanuel Grumbach | 639eaba | 2014-03-30 10:11:13 +0300 | [diff] [blame] | 1138 | MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, |
| 1139 | S_IRUSR | S_IWUSR); |
Matti Gottlieb | 3848ab6 | 2013-07-30 15:29:37 +0300 | [diff] [blame] | 1140 | MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR); |
Eyal Shapira | 5fc0f76 | 2014-01-28 01:35:32 +0200 | [diff] [blame] | 1141 | MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR); |
Emmanuel Grumbach | 490953a | 2013-03-04 08:53:07 +0200 | [diff] [blame] | 1142 | MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR); |
Alexander Bondar | 119663c | 2013-10-17 14:26:50 +0200 | [diff] [blame] | 1143 | MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR); |
Emmanuel Grumbach | cdb0056 | 2014-03-16 21:55:43 +0200 | [diff] [blame] | 1144 | MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR); |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 1145 | MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, |
| 1146 | S_IWUSR | S_IRUSR); |
Eliad Peller | f3c221f | 2014-01-09 13:12:54 +0200 | [diff] [blame] | 1147 | 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] | 1148 | MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR); |
Eliad Peller | de06a59 | 2014-01-08 10:11:12 +0200 | [diff] [blame] | 1149 | |
| 1150 | #ifdef CONFIG_IWLWIFI_BCAST_FILTERING |
| 1151 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) { |
| 1152 | bcast_dir = debugfs_create_dir("bcast_filtering", |
| 1153 | mvm->debugfs_dir); |
| 1154 | if (!bcast_dir) |
| 1155 | goto err; |
| 1156 | |
| 1157 | if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR, |
| 1158 | bcast_dir, |
| 1159 | &mvm->dbgfs_bcast_filtering.override)) |
| 1160 | goto err; |
| 1161 | |
| 1162 | MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters, |
| 1163 | bcast_dir, S_IWUSR | S_IRUSR); |
| 1164 | MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs, |
| 1165 | bcast_dir, S_IWUSR | S_IRUSR); |
| 1166 | } |
| 1167 | #endif |
| 1168 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1169 | #ifdef CONFIG_PM_SLEEP |
| 1170 | 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] | 1171 | MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR); |
Johannes Berg | b011471 | 2013-06-12 14:55:40 +0200 | [diff] [blame] | 1172 | if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR, |
| 1173 | mvm->debugfs_dir, &mvm->d3_wake_sysassert)) |
| 1174 | goto err; |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1175 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1176 | |
Emmanuel Grumbach | 086f736 | 2013-11-18 17:00:03 +0200 | [diff] [blame] | 1177 | if (!debugfs_create_blob("nvm_hw", S_IRUSR, |
| 1178 | mvm->debugfs_dir, &mvm->nvm_hw_blob)) |
| 1179 | goto err; |
| 1180 | if (!debugfs_create_blob("nvm_sw", S_IRUSR, |
| 1181 | mvm->debugfs_dir, &mvm->nvm_sw_blob)) |
| 1182 | goto err; |
| 1183 | if (!debugfs_create_blob("nvm_calib", S_IRUSR, |
| 1184 | mvm->debugfs_dir, &mvm->nvm_calib_blob)) |
| 1185 | goto err; |
| 1186 | if (!debugfs_create_blob("nvm_prod", S_IRUSR, |
| 1187 | mvm->debugfs_dir, &mvm->nvm_prod_blob)) |
| 1188 | goto err; |
| 1189 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1190 | /* |
| 1191 | * Create a symlink with mac80211. It will be removed when mac80211 |
| 1192 | * exists (before the opmode exists which removes the target.) |
| 1193 | */ |
| 1194 | snprintf(buf, 100, "../../%s/%s", |
| 1195 | dbgfs_dir->d_parent->d_parent->d_name.name, |
| 1196 | dbgfs_dir->d_parent->d_name.name); |
| 1197 | if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf)) |
| 1198 | goto err; |
| 1199 | |
| 1200 | return 0; |
| 1201 | err: |
| 1202 | IWL_ERR(mvm, "Can't create the mvm debugfs directory\n"); |
| 1203 | return -ENOMEM; |
| 1204 | } |