blob: 744dc069ff23a9dbcf4fb61416da2dd1766e5064 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eliad Pellerc7792732015-04-19 11:41:04 +03009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Bergaab69302017-03-22 22:05:12 +010010 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eliad Pellerc7792732015-04-19 11:41:04 +030036 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Bergaab69302017-03-22 22:05:12 +010037 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020067#include <linux/vmalloc.h>
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +020068#include <linux/ieee80211.h>
Sara Sharon854d7732016-03-22 15:55:58 +020069#include <linux/netdevice.h>
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020070
Johannes Berg8ca151b2013-01-24 14:25:36 +010071#include "mvm.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020072#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010073#include "sta.h"
74#include "iwl-io.h"
Johannes Berg820a1a52013-11-12 16:58:41 +010075#include "debugfs.h"
Johannes Berg4d075002014-04-24 10:41:31 +020076#include "iwl-fw-error-dump.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010077
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +020078static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
79 char __user *user_buf,
80 size_t count, loff_t *ppos)
81{
82 struct iwl_mvm *mvm = file->private_data;
83 char buf[16];
84 int pos, budget;
85
Johannes Bergaab69302017-03-22 22:05:12 +010086 if (!iwl_mvm_firmware_running(mvm) ||
87 mvm->cur_ucode != IWL_UCODE_REGULAR)
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +020088 return -EIO;
89
90 mutex_lock(&mvm->mutex);
91 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
92 mutex_unlock(&mvm->mutex);
93
94 if (budget < 0)
95 return budget;
96
97 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
98
99 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
100}
101
102static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
103 size_t count, loff_t *ppos)
104{
105 int ret;
106
Johannes Bergaab69302017-03-22 22:05:12 +0100107 if (!iwl_mvm_firmware_running(mvm) ||
108 mvm->cur_ucode != IWL_UCODE_REGULAR)
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +0200109 return -EIO;
110
111 mutex_lock(&mvm->mutex);
112 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
113 mutex_unlock(&mvm->mutex);
114
115 return ret ?: count;
116}
117
Johannes Berg1fa3f572013-11-13 09:10:21 +0100118static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119 size_t count, loff_t *ppos)
120{
Johannes Berg8a0bd162013-11-12 16:48:03 +0100121 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100122 u32 scd_q_msk;
123
Johannes Bergaab69302017-03-22 22:05:12 +0100124 if (!iwl_mvm_firmware_running(mvm) ||
125 mvm->cur_ucode != IWL_UCODE_REGULAR)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100126 return -EIO;
127
Johannes Berg8ca151b2013-01-24 14:25:36 +0100128 if (sscanf(buf, "%x", &scd_q_msk) != 1)
129 return -EINVAL;
130
131 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
132
133 mutex_lock(&mvm->mutex);
Luca Coelho5888a402015-10-06 09:54:57 +0300134 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100135 mutex_unlock(&mvm->mutex);
136
137 return ret;
138}
139
Johannes Berg1fa3f572013-11-13 09:10:21 +0100140static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141 size_t count, loff_t *ppos)
142{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200143 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +0100144 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145
Johannes Bergaab69302017-03-22 22:05:12 +0100146 if (!iwl_mvm_firmware_running(mvm) ||
147 mvm->cur_ucode != IWL_UCODE_REGULAR)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100148 return -EIO;
149
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
151 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200152 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
153 return -EINVAL;
154 if (drain < 0 || drain > 1)
155 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100156
157 mutex_lock(&mvm->mutex);
158
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200159 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
160
161 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100162 ret = -ENOENT;
163 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200164 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100165
166 mutex_unlock(&mvm->mutex);
167
168 return ret;
169}
170
171static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
172 size_t count, loff_t *ppos)
173{
174 struct iwl_mvm *mvm = file->private_data;
175 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200176 unsigned int ofs, len;
177 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100178 u8 *ptr;
179
Johannes Bergaab69302017-03-22 22:05:12 +0100180 if (!iwl_mvm_firmware_running(mvm))
Johannes Berg60191d92013-05-15 13:08:51 +0200181 return -EINVAL;
182
Johannes Berg8ca151b2013-01-24 14:25:36 +0100183 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200184 img = &mvm->fw->img[mvm->cur_ucode];
185 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
186 len = img->sec[IWL_UCODE_SECTION_DATA].len;
187
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200188 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200189 ofs = mvm->dbgfs_sram_offset;
190 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100192
Johannes Berg8ca151b2013-01-24 14:25:36 +0100193 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200194 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100195 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100196
Johannes Berg60191d92013-05-15 13:08:51 +0200197 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100198
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200199 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100200
Johannes Berg8ca151b2013-01-24 14:25:36 +0100201 kfree(ptr);
202
203 return ret;
204}
205
Johannes Berg1fa3f572013-11-13 09:10:21 +0100206static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
207 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100208{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200209 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100210 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200211 u32 img_offset, img_len;
212
Johannes Bergaab69302017-03-22 22:05:12 +0100213 if (!iwl_mvm_firmware_running(mvm))
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200214 return -EINVAL;
215
216 img = &mvm->fw->img[mvm->cur_ucode];
217 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
218 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219
Johannes Berg8ca151b2013-01-24 14:25:36 +0100220 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
221 if ((offset & 0x3) || (len & 0x3))
222 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200223
224 if (offset + len > img_offset + img_len)
225 return -EINVAL;
226
Johannes Berg8ca151b2013-01-24 14:25:36 +0100227 mvm->dbgfs_sram_offset = offset;
228 mvm->dbgfs_sram_len = len;
229 } else {
230 mvm->dbgfs_sram_offset = 0;
231 mvm->dbgfs_sram_len = 0;
232 }
233
234 return count;
235}
236
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300237static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
238 char __user *user_buf,
239 size_t count, loff_t *ppos)
240{
241 struct iwl_mvm *mvm = file->private_data;
242 char buf[16];
243 int pos;
244
245 if (!mvm->temperature_test)
246 pos = scnprintf(buf , sizeof(buf), "disabled\n");
247 else
248 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
249
250 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
251}
252
253/*
254 * Set NIC Temperature
255 * Cause the driver to ignore the actual NIC temperature reported by the FW
256 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
257 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
258 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
259 */
260static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
261 char *buf, size_t count,
262 loff_t *ppos)
263{
264 int temperature;
265
Johannes Bergaab69302017-03-22 22:05:12 +0100266 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
Luciano Coelhoa26d4e72014-08-20 10:21:07 +0300267 return -EIO;
268
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300269 if (kstrtoint(buf, 10, &temperature))
270 return -EINVAL;
271 /* not a legal temperature */
272 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
273 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
274 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
275 return -EINVAL;
276
277 mutex_lock(&mvm->mutex);
278 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
Luciano Coelhob689fa72014-08-20 17:26:58 +0300279 if (!mvm->temperature_test)
280 goto out;
281
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300282 mvm->temperature_test = false;
Luciano Coelhob689fa72014-08-20 17:26:58 +0300283 /* Since we can't read the temp while awake, just set
284 * it to zero until we get the next RX stats from the
285 * firmware.
286 */
287 mvm->temperature = 0;
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300288 } else {
289 mvm->temperature_test = true;
290 mvm->temperature = temperature;
291 }
292 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
293 mvm->temperature_test ? "En" : "Dis" ,
294 mvm->temperature);
295 /* handle the temperature change */
296 iwl_mvm_tt_handler(mvm);
Luciano Coelhob689fa72014-08-20 17:26:58 +0300297
298out:
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300299 mutex_unlock(&mvm->mutex);
300
301 return count;
302}
303
Luciano Coelhoc549e392014-09-04 15:58:47 +0300304static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
305 char __user *user_buf,
306 size_t count, loff_t *ppos)
307{
308 struct iwl_mvm *mvm = file->private_data;
309 char buf[16];
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200310 int pos, ret;
311 s32 temp;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300312
Johannes Bergaab69302017-03-22 22:05:12 +0100313 if (!iwl_mvm_firmware_running(mvm))
Luciano Coelhoc549e392014-09-04 15:58:47 +0300314 return -EIO;
315
316 mutex_lock(&mvm->mutex);
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200317 ret = iwl_mvm_get_temp(mvm, &temp);
Luciano Coelhoc549e392014-09-04 15:58:47 +0300318 mutex_unlock(&mvm->mutex);
319
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200320 if (ret)
321 return -EIO;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300322
323 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
324
325 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
326}
327
Johannes Berg8ca151b2013-01-24 14:25:36 +0100328static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
329 size_t count, loff_t *ppos)
330{
331 struct iwl_mvm *mvm = file->private_data;
332 struct ieee80211_sta *sta;
333 char buf[400];
334 int i, pos = 0, bufsz = sizeof(buf);
335
336 mutex_lock(&mvm->mutex);
337
Sara Sharon0ae98812017-01-04 14:53:58 +0200338 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100339 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
340 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
341 lockdep_is_held(&mvm->mutex));
342 if (!sta)
343 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
344 else if (IS_ERR(sta))
345 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
346 PTR_ERR(sta));
347 else
348 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
349 sta->addr);
350 }
351
352 mutex_unlock(&mvm->mutex);
353
354 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
355}
356
Alexander Bondar64b928c2013-09-03 14:18:03 +0300357static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
358 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100359 size_t count, loff_t *ppos)
360{
361 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300362 char buf[64];
363 int bufsz = sizeof(buf);
364 int pos = 0;
365
366 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
367 mvm->disable_power_off);
368 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
369 mvm->disable_power_off_d3);
370
371 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
372}
373
Johannes Berg1fa3f572013-11-13 09:10:21 +0100374static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300375 size_t count, loff_t *ppos)
376{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100377 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100378
Johannes Bergaab69302017-03-22 22:05:12 +0100379 if (!iwl_mvm_firmware_running(mvm))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100380 return -EIO;
381
Alexander Bondar64b928c2013-09-03 14:18:03 +0300382 if (!strncmp("disable_power_off_d0=", buf, 21)) {
383 if (sscanf(buf + 21, "%d", &val) != 1)
384 return -EINVAL;
385 mvm->disable_power_off = val;
386 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
387 if (sscanf(buf + 21, "%d", &val) != 1)
388 return -EINVAL;
389 mvm->disable_power_off_d3 = val;
390 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100391 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300392 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100393
Alexander Bondar64b928c2013-09-03 14:18:03 +0300394 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200395 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300396 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100397
Alexander Bondar64b928c2013-09-03 14:18:03 +0300398 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100399}
400
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200401#define BT_MBOX_MSG(_notif, _num, _field) \
402 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
403 >> BT_MBOX##_num##_##_field##_POS)
404
405
406#define BT_MBOX_PRINT(_num, _field, _end) \
407 pos += scnprintf(buf + pos, bufsz - pos, \
408 "\t%s: %d%s", \
409 #_field, \
410 BT_MBOX_MSG(notif, _num, _field), \
411 true ? "\n" : ", ");
412
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300413static
414int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
415 int pos, int bufsz)
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200416{
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200417 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
418
419 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
420 BT_MBOX_PRINT(0, LE_PROF1, false);
421 BT_MBOX_PRINT(0, LE_PROF2, false);
422 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
423 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
424 BT_MBOX_PRINT(0, INBAND_S, false);
425 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
426 BT_MBOX_PRINT(0, LE_SCAN, false);
427 BT_MBOX_PRINT(0, LE_ADV, false);
428 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
429 BT_MBOX_PRINT(0, OPEN_CON_1, true);
430
431 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
432
433 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
434 BT_MBOX_PRINT(1, IP_SR, false);
435 BT_MBOX_PRINT(1, LE_MSTR, false);
436 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
437 BT_MBOX_PRINT(1, MSG_TYPE, false);
438 BT_MBOX_PRINT(1, SSN, true);
439
440 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
441
442 BT_MBOX_PRINT(2, SNIFF_ACT, false);
443 BT_MBOX_PRINT(2, PAG, false);
444 BT_MBOX_PRINT(2, INQUIRY, false);
445 BT_MBOX_PRINT(2, CONN, false);
446 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
447 BT_MBOX_PRINT(2, DISC, false);
448 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
449 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
450 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
451 BT_MBOX_PRINT(2, SCO_DURATION, true);
452
453 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
454
455 BT_MBOX_PRINT(3, SCO_STATE, false);
456 BT_MBOX_PRINT(3, SNIFF_STATE, false);
457 BT_MBOX_PRINT(3, A2DP_STATE, false);
458 BT_MBOX_PRINT(3, ACL_STATE, false);
459 BT_MBOX_PRINT(3, MSTR_STATE, false);
460 BT_MBOX_PRINT(3, OBX_STATE, false);
461 BT_MBOX_PRINT(3, OPEN_CON_2, false);
462 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
463 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
464 BT_MBOX_PRINT(3, INBAND_P, false);
465 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
466 BT_MBOX_PRINT(3, SSN_2, false);
467 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
468
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300469 return pos;
470}
471
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300472static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
473 size_t count, loff_t *ppos)
474{
475 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200476 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300477 char *buf;
478 int ret, pos = 0, bufsz = sizeof(char) * 1024;
479
480 buf = kmalloc(bufsz, GFP_KERNEL);
481 if (!buf)
482 return -ENOMEM;
483
484 mutex_lock(&mvm->mutex);
485
Sara Sharon97f95c92016-03-07 16:55:20 +0200486 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300487
Sara Sharon97f95c92016-03-07 16:55:20 +0200488 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
489 notif->bt_ci_compliance);
490 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
491 le32_to_cpu(notif->primary_ch_lut));
492 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
493 le32_to_cpu(notif->secondary_ch_lut));
494 pos += scnprintf(buf + pos,
495 bufsz - pos, "bt_activity_grading = %d\n",
496 le32_to_cpu(notif->bt_activity_grading));
497 pos += scnprintf(buf + pos, bufsz - pos,
498 "antenna isolation = %d CORUN LUT index = %d\n",
499 mvm->last_ant_isol, mvm->last_corun_lut);
500 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
501 (notif->ttc_rrc_status >> 4) & 0xF);
502 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
503 notif->ttc_rrc_status & 0xF);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200504
Moshe Harelc725a462015-10-27 14:04:12 +0200505 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
506 IWL_MVM_BT_COEX_SYNC2SCO);
507 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
508 IWL_MVM_BT_COEX_MPLUT);
509 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
510 IWL_MVM_BT_COEX_CORUNNING);
511
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200512 mutex_unlock(&mvm->mutex);
513
514 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
515 kfree(buf);
516
517 return ret;
518}
519#undef BT_MBOX_PRINT
520
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300521static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
522 size_t count, loff_t *ppos)
523{
524 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200525 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300526 char buf[256];
527 int bufsz = sizeof(buf);
528 int pos = 0;
529
530 mutex_lock(&mvm->mutex);
531
Sara Sharon97f95c92016-03-07 16:55:20 +0200532 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
533 pos += scnprintf(buf + pos, bufsz - pos,
534 "\tPrimary Channel Bitmap 0x%016llx\n",
535 le64_to_cpu(cmd->bt_primary_ci));
536 pos += scnprintf(buf + pos, bufsz - pos,
537 "\tSecondary Channel Bitmap 0x%016llx\n",
538 le64_to_cpu(cmd->bt_secondary_ci));
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300539
540 mutex_unlock(&mvm->mutex);
541
542 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
543}
544
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200545static ssize_t
546iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
547 size_t count, loff_t *ppos)
548{
549 u32 bt_tx_prio;
550
551 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
552 return -EINVAL;
553 if (bt_tx_prio > 4)
554 return -EINVAL;
555
556 mvm->bt_tx_prio = bt_tx_prio;
557
558 return count;
559}
560
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300561static ssize_t
562iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
563 size_t count, loff_t *ppos)
564{
565 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
566 [BT_FORCE_ANT_DIS] = "dis",
567 [BT_FORCE_ANT_AUTO] = "auto",
568 [BT_FORCE_ANT_BT] = "bt",
569 [BT_FORCE_ANT_WIFI] = "wifi",
570 };
571 int ret, bt_force_ant_mode;
572
573 for (bt_force_ant_mode = 0;
574 bt_force_ant_mode < ARRAY_SIZE(modes_str);
575 bt_force_ant_mode++) {
576 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
577 break;
578 }
579
580 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
581 return -EINVAL;
582
583 ret = 0;
584 mutex_lock(&mvm->mutex);
585 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
586 goto out;
587
588 mvm->bt_force_ant_mode = bt_force_ant_mode;
589 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
590 modes_str[mvm->bt_force_ant_mode]);
Johannes Berg504bd622017-03-22 22:19:41 +0100591
592 if (iwl_mvm_firmware_running(mvm))
593 ret = iwl_send_bt_init_conf(mvm);
594 else
595 ret = 0;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300596
597out:
598 mutex_unlock(&mvm->mutex);
599 return ret ?: count;
600}
601
Johannes Berg93d17cc2015-01-15 12:59:26 +0100602#define PRINT_STATS_LE32(_struct, _memb) \
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300603 pos += scnprintf(buf + pos, bufsz - pos, \
Johannes Berg93d17cc2015-01-15 12:59:26 +0100604 fmt_table, #_memb, \
605 le32_to_cpu(_struct->_memb))
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300606
607static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
608 char __user *user_buf, size_t count,
609 loff_t *ppos)
610{
611 struct iwl_mvm *mvm = file->private_data;
612 static const char *fmt_table = "\t%-30s %10u\n";
613 static const char *fmt_header = "%-32s\n";
614 int pos = 0;
615 char *buf;
616 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300617 /* 43 is the size of each data line, 33 is the size of each header */
618 size_t bufsz =
619 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
620 (4 * 33) + 1;
621
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300622 struct mvm_statistics_rx_phy *ofdm;
623 struct mvm_statistics_rx_phy *cck;
624 struct mvm_statistics_rx_non_phy *general;
625 struct mvm_statistics_rx_ht_phy *ht;
626
627 buf = kzalloc(bufsz, GFP_KERNEL);
628 if (!buf)
629 return -ENOMEM;
630
631 mutex_lock(&mvm->mutex);
632
633 ofdm = &mvm->rx_stats.ofdm;
634 cck = &mvm->rx_stats.cck;
635 general = &mvm->rx_stats.general;
636 ht = &mvm->rx_stats.ofdm_ht;
637
638 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
639 "Statistics_Rx - OFDM");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100640 PRINT_STATS_LE32(ofdm, ina_cnt);
641 PRINT_STATS_LE32(ofdm, fina_cnt);
642 PRINT_STATS_LE32(ofdm, plcp_err);
643 PRINT_STATS_LE32(ofdm, crc32_err);
644 PRINT_STATS_LE32(ofdm, overrun_err);
645 PRINT_STATS_LE32(ofdm, early_overrun_err);
646 PRINT_STATS_LE32(ofdm, crc32_good);
647 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
648 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
649 PRINT_STATS_LE32(ofdm, sfd_timeout);
650 PRINT_STATS_LE32(ofdm, fina_timeout);
651 PRINT_STATS_LE32(ofdm, unresponded_rts);
652 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
653 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
654 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
655 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
656 PRINT_STATS_LE32(ofdm, dsp_self_kill);
657 PRINT_STATS_LE32(ofdm, mh_format_err);
658 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
659 PRINT_STATS_LE32(ofdm, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300660
661 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
662 "Statistics_Rx - CCK");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100663 PRINT_STATS_LE32(cck, ina_cnt);
664 PRINT_STATS_LE32(cck, fina_cnt);
665 PRINT_STATS_LE32(cck, plcp_err);
666 PRINT_STATS_LE32(cck, crc32_err);
667 PRINT_STATS_LE32(cck, overrun_err);
668 PRINT_STATS_LE32(cck, early_overrun_err);
669 PRINT_STATS_LE32(cck, crc32_good);
670 PRINT_STATS_LE32(cck, false_alarm_cnt);
671 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
672 PRINT_STATS_LE32(cck, sfd_timeout);
673 PRINT_STATS_LE32(cck, fina_timeout);
674 PRINT_STATS_LE32(cck, unresponded_rts);
675 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
676 PRINT_STATS_LE32(cck, sent_ack_cnt);
677 PRINT_STATS_LE32(cck, sent_cts_cnt);
678 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
679 PRINT_STATS_LE32(cck, dsp_self_kill);
680 PRINT_STATS_LE32(cck, mh_format_err);
681 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
682 PRINT_STATS_LE32(cck, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300683
684 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
685 "Statistics_Rx - GENERAL");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100686 PRINT_STATS_LE32(general, bogus_cts);
687 PRINT_STATS_LE32(general, bogus_ack);
688 PRINT_STATS_LE32(general, non_bssid_frames);
689 PRINT_STATS_LE32(general, filtered_frames);
690 PRINT_STATS_LE32(general, non_channel_beacons);
691 PRINT_STATS_LE32(general, channel_beacons);
692 PRINT_STATS_LE32(general, num_missed_bcon);
693 PRINT_STATS_LE32(general, adc_rx_saturation_time);
694 PRINT_STATS_LE32(general, ina_detection_search_time);
695 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
696 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
697 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
698 PRINT_STATS_LE32(general, interference_data_flag);
699 PRINT_STATS_LE32(general, channel_load);
700 PRINT_STATS_LE32(general, dsp_false_alarms);
701 PRINT_STATS_LE32(general, beacon_rssi_a);
702 PRINT_STATS_LE32(general, beacon_rssi_b);
703 PRINT_STATS_LE32(general, beacon_rssi_c);
704 PRINT_STATS_LE32(general, beacon_energy_a);
705 PRINT_STATS_LE32(general, beacon_energy_b);
706 PRINT_STATS_LE32(general, beacon_energy_c);
707 PRINT_STATS_LE32(general, num_bt_kills);
708 PRINT_STATS_LE32(general, mac_id);
709 PRINT_STATS_LE32(general, directed_data_mpdu);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300710
711 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
712 "Statistics_Rx - HT");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100713 PRINT_STATS_LE32(ht, plcp_err);
714 PRINT_STATS_LE32(ht, overrun_err);
715 PRINT_STATS_LE32(ht, early_overrun_err);
716 PRINT_STATS_LE32(ht, crc32_good);
717 PRINT_STATS_LE32(ht, crc32_err);
718 PRINT_STATS_LE32(ht, mh_format_err);
719 PRINT_STATS_LE32(ht, agg_crc32_good);
720 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
721 PRINT_STATS_LE32(ht, agg_cnt);
722 PRINT_STATS_LE32(ht, unsupport_mcs);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300723
724 mutex_unlock(&mvm->mutex);
725
726 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
727 kfree(buf);
728
729 return ret;
730}
731#undef PRINT_STAT_LE32
732
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200733static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
734 char __user *user_buf, size_t count,
735 loff_t *ppos,
736 struct iwl_mvm_frame_stats *stats)
737{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200738 char *buff, *pos, *endpos;
739 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200740 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200741 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200742
743 buff = kmalloc(bufsz, GFP_KERNEL);
744 if (!buff)
745 return -ENOMEM;
746
747 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200748
749 pos = buff;
750 endpos = pos + bufsz;
751
752 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200753 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
754 stats->legacy_frames,
755 stats->ht_frames,
756 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200757 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200758 stats->bw_20_frames,
759 stats->bw_40_frames,
760 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200761 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200762 stats->ngi_frames,
763 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200764 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200765 stats->siso_frames,
766 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200767 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200768 stats->fail_frames,
769 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200770 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200771 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200772 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200773 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200774 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200775 stats->ampdu_count > 0 ?
776 (stats->agg_frames / stats->ampdu_count) : 0);
777
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200778 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200779
780 idx = stats->last_frame_idx - 1;
781 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
782 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
783 if (stats->last_rates[idx] == 0)
784 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200785 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200786 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200787 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200788 }
789 spin_unlock_bh(&mvm->drv_stats_lock);
790
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200791 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200792 kfree(buff);
793
794 return ret;
795}
796
797static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
798 char __user *user_buf, size_t count,
799 loff_t *ppos)
800{
801 struct iwl_mvm *mvm = file->private_data;
802
803 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
804 &mvm->drv_rx_stats);
805}
806
Johannes Berg1fa3f572013-11-13 09:10:21 +0100807static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200808 size_t count, loff_t *ppos)
809{
Luca Coelho758d1a82016-11-09 10:02:46 +0200810 int __maybe_unused ret;
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200811
Johannes Berg504bd622017-03-22 22:19:41 +0100812 if (!iwl_mvm_firmware_running(mvm))
813 return -EIO;
814
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200815 mutex_lock(&mvm->mutex);
816
Eran Harary291aa7c2013-07-03 11:00:06 +0300817 /* allow one more restart that we're provoking here */
818 if (mvm->restart_fw >= 0)
819 mvm->restart_fw++;
820
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200821 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300822 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200823
824 mutex_unlock(&mvm->mutex);
825
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200826 return count;
827}
828
Johannes Berg1fa3f572013-11-13 09:10:21 +0100829static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200830 size_t count, loff_t *ppos)
831{
Johannes Berg504bd622017-03-22 22:19:41 +0100832 int ret;
833
834 if (!iwl_mvm_firmware_running(mvm))
835 return -EIO;
836
837 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
Eliad Peller576eeee2014-07-01 18:38:38 +0300838 if (ret)
839 return ret;
840
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300841 iwl_force_nmi(mvm->trans);
Alexander Bondar119663c2013-10-17 14:26:50 +0200842
Eliad Peller576eeee2014-07-01 18:38:38 +0300843 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
844
Alexander Bondar119663c2013-10-17 14:26:50 +0200845 return count;
846}
847
Oren Givon91b05d12013-08-19 08:36:48 +0300848static ssize_t
849iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
850 char __user *user_buf,
851 size_t count, loff_t *ppos)
852{
853 struct iwl_mvm *mvm = file->private_data;
854 int pos = 0;
855 char buf[32];
856 const size_t bufsz = sizeof(buf);
857
858 /* print which antennas were set for the scan command by the user */
859 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
860 if (mvm->scan_rx_ant & ANT_A)
861 pos += scnprintf(buf + pos, bufsz - pos, "A");
862 if (mvm->scan_rx_ant & ANT_B)
863 pos += scnprintf(buf + pos, bufsz - pos, "B");
864 if (mvm->scan_rx_ant & ANT_C)
865 pos += scnprintf(buf + pos, bufsz - pos, "C");
866 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
867
868 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
869}
870
871static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100872iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300873 size_t count, loff_t *ppos)
874{
Oren Givon91b05d12013-08-19 08:36:48 +0300875 u8 scan_rx_ant;
876
Johannes Berg504bd622017-03-22 22:19:41 +0100877 if (!iwl_mvm_firmware_running(mvm))
878 return -EIO;
879
Oren Givon91b05d12013-08-19 08:36:48 +0300880 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
881 return -EINVAL;
882 if (scan_rx_ant > ANT_ABC)
883 return -EINVAL;
Moshe Harela0544272014-12-08 21:13:14 +0200884 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
Oren Givon91b05d12013-08-19 08:36:48 +0300885 return -EINVAL;
886
David Spinadeld2496222014-05-20 12:46:37 +0300887 if (mvm->scan_rx_ant != scan_rx_ant) {
888 mvm->scan_rx_ant = scan_rx_ant;
Johannes Berg859d9142015-06-01 17:11:11 +0200889 if (fw_has_capa(&mvm->fw->ucode_capa,
890 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
David Spinadeld2496222014-05-20 12:46:37 +0300891 iwl_mvm_config_scan(mvm);
892 }
Oren Givon91b05d12013-08-19 08:36:48 +0300893
894 return count;
895}
896
Sara Sharon43413a92015-12-31 11:49:18 +0200897static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
898 char *buf, size_t count,
899 loff_t *ppos)
900{
901 struct iwl_rss_config_cmd cmd = {
902 .flags = cpu_to_le32(IWL_RSS_ENABLE),
903 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200904 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200905 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
906 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200907 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200908 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
909 };
910 int ret, i, num_repeats, nbytes = count / 2;
911
912 ret = hex2bin(cmd.indirection_table, buf, nbytes);
913 if (ret)
914 return ret;
915
916 /*
917 * The input is the redirection table, partial or full.
918 * Repeat the pattern if needed.
919 * For example, input of 01020F will be repeated 42 times,
920 * indirecting RSS hash results to queues 1, 2, 15 (skipping
921 * queues 3 - 14).
922 */
923 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
924 for (i = 1; i < num_repeats; i++)
925 memcpy(&cmd.indirection_table[i * nbytes],
926 cmd.indirection_table, nbytes);
927 /* handle cut in the middle pattern for the last places */
928 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
929 ARRAY_SIZE(cmd.indirection_table) % nbytes);
930
Sara Sharon854d7732016-03-22 15:55:58 +0200931 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200932
933 mutex_lock(&mvm->mutex);
Johannes Berg504bd622017-03-22 22:19:41 +0100934 if (iwl_mvm_firmware_running(mvm))
935 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
936 sizeof(cmd), &cmd);
937 else
938 ret = 0;
Sara Sharon43413a92015-12-31 11:49:18 +0200939 mutex_unlock(&mvm->mutex);
940
941 return ret ?: count;
942}
943
Sara Sharon4857d6c2016-08-09 20:03:52 +0300944static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
945 char *buf, size_t count,
946 loff_t *ppos)
947{
948 struct iwl_rx_cmd_buffer rxb = {
949 ._rx_page_order = 0,
950 .truesize = 0, /* not used */
951 ._offset = 0,
952 };
953 struct iwl_rx_packet *pkt;
954 struct iwl_rx_mpdu_desc *desc;
955 int bin_len = count / 2;
956 int ret = -EINVAL;
957
Johannes Berg504bd622017-03-22 22:19:41 +0100958 if (!iwl_mvm_firmware_running(mvm))
959 return -EIO;
960
Sara Sharon4857d6c2016-08-09 20:03:52 +0300961 /* supporting only 9000 descriptor */
962 if (!mvm->trans->cfg->mq_rx_supported)
963 return -ENOTSUPP;
964
965 rxb._page = alloc_pages(GFP_ATOMIC, 0);
966 if (!rxb._page)
967 return -ENOMEM;
968 pkt = rxb_addr(&rxb);
969
970 ret = hex2bin(page_address(rxb._page), buf, bin_len);
971 if (ret)
972 goto out;
973
974 /* avoid invalid memory access */
975 if (bin_len < sizeof(*pkt) + sizeof(*desc))
976 goto out;
977
978 /* check this is RX packet */
979 if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
980 WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
981 goto out;
982
983 /* check the length in metadata matches actual received length */
984 desc = (void *)pkt->data;
985 if (le16_to_cpu(desc->mpdu_len) !=
986 (bin_len - sizeof(*desc) - sizeof(*pkt)))
987 goto out;
988
989 local_bh_disable();
990 iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
991 local_bh_enable();
992 ret = 0;
993
994out:
995 iwl_free_rxb(&rxb);
996
997 return ret ?: count;
998}
999
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001000static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1001 char __user *user_buf,
1002 size_t count, loff_t *ppos)
1003{
1004 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001005 int conf;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001006 char buf[8];
1007 const size_t bufsz = sizeof(buf);
1008 int pos = 0;
1009
1010 mutex_lock(&mvm->mutex);
1011 conf = mvm->fw_dbg_conf;
1012 mutex_unlock(&mvm->mutex);
1013
1014 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1015
1016 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1017}
1018
Golan Ben Ami321c2102015-07-27 17:02:35 +03001019/*
1020 * Enable / Disable continuous recording.
1021 * Cause the FW to start continuous recording, by sending the relevant hcmd.
1022 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
1023 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
1024 */
1025static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
1026 char *buf, size_t count,
1027 loff_t *ppos)
1028{
1029 struct iwl_trans *trans = mvm->trans;
1030 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
1031 struct iwl_continuous_record_cmd cont_rec = {};
1032 int ret, rec_mode;
1033
Johannes Berg504bd622017-03-22 22:19:41 +01001034 if (!iwl_mvm_firmware_running(mvm))
1035 return -EIO;
1036
Golan Ben Ami321c2102015-07-27 17:02:35 +03001037 if (!dest)
1038 return -EOPNOTSUPP;
1039
1040 if (dest->monitor_mode != SMEM_MODE ||
Sara Sharon6e584872017-03-22 14:07:50 +02001041 trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
Golan Ben Ami321c2102015-07-27 17:02:35 +03001042 return -EOPNOTSUPP;
1043
Johannes Berg27e070d2016-01-14 10:55:22 +01001044 ret = kstrtoint(buf, 0, &rec_mode);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001045 if (ret)
1046 return ret;
1047
1048 cont_rec.record_mode.enable_recording = rec_mode ?
1049 cpu_to_le16(ENABLE_CONT_RECORDING) :
1050 cpu_to_le16(DISABLE_CONT_RECORDING);
1051
1052 mutex_lock(&mvm->mutex);
1053 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1054 sizeof(cont_rec), &cont_rec);
1055 mutex_unlock(&mvm->mutex);
1056
1057 return ret ?: count;
1058}
1059
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001060static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1061 char *buf, size_t count,
1062 loff_t *ppos)
1063{
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001064 unsigned int conf_id;
1065 int ret;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001066
Johannes Berg504bd622017-03-22 22:19:41 +01001067 if (!iwl_mvm_firmware_running(mvm))
1068 return -EIO;
1069
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001070 ret = kstrtouint(buf, 0, &conf_id);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001071 if (ret)
1072 return ret;
1073
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001074 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001075 return -EINVAL;
1076
1077 mutex_lock(&mvm->mutex);
1078 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1079 mutex_unlock(&mvm->mutex);
1080
1081 return ret ?: count;
1082}
1083
1084static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1085 char *buf, size_t count,
1086 loff_t *ppos)
1087{
Johannes Berg504bd622017-03-22 22:19:41 +01001088 int ret;
Liad Kaufmane93475a2015-01-04 11:03:13 +02001089
Johannes Berg504bd622017-03-22 22:19:41 +01001090 if (!iwl_mvm_firmware_running(mvm))
1091 return -EIO;
1092
1093 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001094 if (ret)
1095 return ret;
Dan Carpenter251fe092017-03-23 13:40:00 +03001096 if (count == 0)
1097 return 0;
Liad Kaufmane93475a2015-01-04 11:03:13 +02001098
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001099 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1100 (count - 1), NULL);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001101
1102 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001103
1104 return count;
1105}
1106
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001107static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1108 char *buf, size_t count,
1109 loff_t *ppos)
1110{
1111 unsigned int max_amsdu_len;
1112 int ret;
1113
1114 ret = kstrtouint(buf, 0, &max_amsdu_len);
Dan Carpenter32afd152016-05-04 09:19:54 +03001115 if (ret)
1116 return ret;
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001117
1118 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1119 return -EINVAL;
1120 mvm->max_amsdu_len = max_amsdu_len;
1121
1122 return count;
1123}
1124
Eliad Pellerde06a592014-01-08 10:11:12 +02001125#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1126#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1127static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1128 char __user *user_buf,
1129 size_t count, loff_t *ppos)
1130{
1131 struct iwl_mvm *mvm = file->private_data;
1132 struct iwl_bcast_filter_cmd cmd;
1133 const struct iwl_fw_bcast_filter *filter;
1134 char *buf;
1135 int bufsz = 1024;
1136 int i, j, pos = 0;
1137 ssize_t ret;
1138
1139 buf = kzalloc(bufsz, GFP_KERNEL);
1140 if (!buf)
1141 return -ENOMEM;
1142
1143 mutex_lock(&mvm->mutex);
1144 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1145 ADD_TEXT("None\n");
1146 mutex_unlock(&mvm->mutex);
1147 goto out;
1148 }
1149 mutex_unlock(&mvm->mutex);
1150
1151 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1152 filter = &cmd.filters[i];
1153
1154 ADD_TEXT("Filter [%d]:\n", i);
1155 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1156 ADD_TEXT("\tFrame Type: %s\n",
1157 filter->frame_type ? "IPv4" : "Generic");
1158
1159 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1160 const struct iwl_fw_bcast_filter_attr *attr;
1161
1162 attr = &filter->attrs[j];
1163 if (!attr->mask)
1164 break;
1165
1166 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1167 j, attr->offset,
1168 attr->offset_type ? "IP End" :
1169 "Payload Start",
1170 be32_to_cpu(attr->mask),
1171 be32_to_cpu(attr->val),
1172 le16_to_cpu(attr->reserved1));
1173 }
1174 }
1175out:
1176 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1177 kfree(buf);
1178 return ret;
1179}
1180
1181static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1182 size_t count, loff_t *ppos)
1183{
1184 int pos, next_pos;
1185 struct iwl_fw_bcast_filter filter = {};
1186 struct iwl_bcast_filter_cmd cmd;
1187 u32 filter_id, attr_id, mask, value;
1188 int err = 0;
1189
1190 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1191 &filter.frame_type, &pos) != 3)
1192 return -EINVAL;
1193
1194 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1195 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1196 return -EINVAL;
1197
1198 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1199 attr_id++) {
1200 struct iwl_fw_bcast_filter_attr *attr =
1201 &filter.attrs[attr_id];
1202
1203 if (pos >= count)
1204 break;
1205
1206 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1207 &attr->offset, &attr->offset_type,
1208 &mask, &value, &next_pos) != 4)
1209 return -EINVAL;
1210
1211 attr->mask = cpu_to_be32(mask);
1212 attr->val = cpu_to_be32(value);
1213 if (mask)
1214 filter.num_attrs++;
1215
1216 pos += next_pos;
1217 }
1218
1219 mutex_lock(&mvm->mutex);
1220 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1221 &filter, sizeof(filter));
1222
1223 /* send updated bcast filtering configuration */
Johannes Berg504bd622017-03-22 22:19:41 +01001224 if (iwl_mvm_firmware_running(mvm) &&
1225 mvm->dbgfs_bcast_filtering.override &&
Eliad Pellerde06a592014-01-08 10:11:12 +02001226 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001227 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001228 sizeof(cmd), &cmd);
1229 mutex_unlock(&mvm->mutex);
1230
1231 return err ?: count;
1232}
1233
1234static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1235 char __user *user_buf,
1236 size_t count, loff_t *ppos)
1237{
1238 struct iwl_mvm *mvm = file->private_data;
1239 struct iwl_bcast_filter_cmd cmd;
1240 char *buf;
1241 int bufsz = 1024;
1242 int i, pos = 0;
1243 ssize_t ret;
1244
1245 buf = kzalloc(bufsz, GFP_KERNEL);
1246 if (!buf)
1247 return -ENOMEM;
1248
1249 mutex_lock(&mvm->mutex);
1250 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1251 ADD_TEXT("None\n");
1252 mutex_unlock(&mvm->mutex);
1253 goto out;
1254 }
1255 mutex_unlock(&mvm->mutex);
1256
1257 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1258 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1259
1260 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1261 i, mac->default_discard, mac->attached_filters);
1262 }
1263out:
1264 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1265 kfree(buf);
1266 return ret;
1267}
1268
1269static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1270 char *buf, size_t count,
1271 loff_t *ppos)
1272{
1273 struct iwl_bcast_filter_cmd cmd;
1274 struct iwl_fw_bcast_mac mac = {};
1275 u32 mac_id, attached_filters;
1276 int err = 0;
1277
1278 if (!mvm->bcast_filters)
1279 return -ENOENT;
1280
1281 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1282 &attached_filters) != 3)
1283 return -EINVAL;
1284
1285 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1286 mac.default_discard > 1 ||
1287 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1288 return -EINVAL;
1289
1290 mac.attached_filters = cpu_to_le16(attached_filters);
1291
1292 mutex_lock(&mvm->mutex);
1293 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1294 &mac, sizeof(mac));
1295
1296 /* send updated bcast filtering configuration */
Johannes Berg504bd622017-03-22 22:19:41 +01001297 if (iwl_mvm_firmware_running(mvm) &&
1298 mvm->dbgfs_bcast_filtering.override &&
Eliad Pellerde06a592014-01-08 10:11:12 +02001299 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001300 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001301 sizeof(cmd), &cmd);
1302 mutex_unlock(&mvm->mutex);
1303
1304 return err ?: count;
1305}
1306#endif
1307
Johannes Bergafc66bb2013-05-03 11:44:16 +02001308#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001309static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +02001310 size_t count, loff_t *ppos)
1311{
Johannes Bergafc66bb2013-05-03 11:44:16 +02001312 int store;
1313
Johannes Bergafc66bb2013-05-03 11:44:16 +02001314 if (sscanf(buf, "%d", &store) != 1)
1315 return -EINVAL;
1316
1317 mvm->store_d3_resume_sram = store;
1318
1319 return count;
1320}
1321
1322static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1323 size_t count, loff_t *ppos)
1324{
1325 struct iwl_mvm *mvm = file->private_data;
1326 const struct fw_img *img;
1327 int ofs, len, pos = 0;
1328 size_t bufsz, ret;
1329 char *buf;
1330 u8 *ptr = mvm->d3_resume_sram;
1331
1332 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1333 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1334
1335 bufsz = len * 4 + 256;
1336 buf = kzalloc(bufsz, GFP_KERNEL);
1337 if (!buf)
1338 return -ENOMEM;
1339
1340 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1341 mvm->store_d3_resume_sram ? "en" : "dis");
1342
1343 if (ptr) {
1344 for (ofs = 0; ofs < len; ofs += 16) {
1345 pos += scnprintf(buf + pos, bufsz - pos,
Andy Shevchenko3cd6e2f2015-07-16 15:42:14 +03001346 "0x%.4x %16ph\n", ofs, ptr + ofs);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001347 }
1348 } else {
1349 pos += scnprintf(buf + pos, bufsz - pos,
1350 "(no data captured)\n");
1351 }
1352
1353 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1354
1355 kfree(buf);
1356
1357 return ret;
1358}
1359#endif
1360
Eliad Peller576eeee2014-07-01 18:38:38 +03001361#define PRINT_MVM_REF(ref) do { \
1362 if (mvm->refs[ref]) \
1363 pos += scnprintf(buf + pos, bufsz - pos, \
1364 "\t(0x%lx): %d %s\n", \
1365 BIT(ref), mvm->refs[ref], #ref); \
Eliad Peller70d6bab2013-11-05 14:45:16 +02001366} while (0)
1367
1368static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1369 char __user *user_buf,
1370 size_t count, loff_t *ppos)
1371{
1372 struct iwl_mvm *mvm = file->private_data;
Eliad Peller576eeee2014-07-01 18:38:38 +03001373 int i, pos = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001374 char buf[256];
1375 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001376 u32 refs = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001377
Eliad Peller576eeee2014-07-01 18:38:38 +03001378 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1379 if (mvm->refs[i])
1380 refs |= BIT(i);
1381
1382 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1383 refs);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001384
1385 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1386 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1387 PRINT_MVM_REF(IWL_MVM_REF_ROC);
Eliad Pellerc7792732015-04-19 11:41:04 +03001388 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001389 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1390 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +02001391 PRINT_MVM_REF(IWL_MVM_REF_USER);
Johannes Berg34e611e2014-09-12 10:28:01 +02001392 PRINT_MVM_REF(IWL_MVM_REF_TX);
1393 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1394 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1395 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1396 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1397 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1398 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1399 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1400 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1401 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1402 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1403 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
Eliad Pellerd15a7472014-03-27 18:53:12 +02001404 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
Eliad Peller160acc02014-11-25 12:34:45 +02001405 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
Liad Kaufmanfb2380a2015-01-01 17:42:46 +02001406 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
Eliad Peller08f0d232015-12-10 15:47:11 +02001407 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
Luca Coelho71b12302016-03-11 12:12:16 +02001408 PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
Luca Coelho16e4dd82016-03-30 15:05:56 +03001409 PRINT_MVM_REF(IWL_MVM_REF_RX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001410
1411 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1412}
1413
Eliad Peller0eb83652013-11-11 18:56:35 +02001414static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1415 size_t count, loff_t *ppos)
1416{
1417 unsigned long value;
1418 int ret;
1419 bool taken;
1420
1421 ret = kstrtoul(buf, 10, &value);
1422 if (ret < 0)
1423 return ret;
1424
1425 mutex_lock(&mvm->mutex);
1426
Eliad Peller576eeee2014-07-01 18:38:38 +03001427 taken = mvm->refs[IWL_MVM_REF_USER];
Eliad Peller0eb83652013-11-11 18:56:35 +02001428 if (value == 1 && !taken)
1429 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1430 else if (value == 0 && taken)
1431 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1432 else
1433 ret = -EINVAL;
1434
1435 mutex_unlock(&mvm->mutex);
1436
1437 if (ret < 0)
1438 return ret;
1439 return count;
1440}
1441
Johannes Berg1fa3f572013-11-13 09:10:21 +01001442#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1443 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1444#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1445 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001446#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1447 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001448 &iwl_dbgfs_##name##_ops)) \
1449 goto err; \
1450 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +02001451#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1452 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001453
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001454static ssize_t
1455iwl_dbgfs_prph_reg_read(struct file *file,
1456 char __user *user_buf,
1457 size_t count, loff_t *ppos)
1458{
1459 struct iwl_mvm *mvm = file->private_data;
1460 int pos = 0;
1461 char buf[32];
1462 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001463 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001464
1465 if (!mvm->dbgfs_prph_reg_addr)
1466 return -EINVAL;
1467
Eliad Peller576eeee2014-07-01 18:38:38 +03001468 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1469 if (ret)
1470 return ret;
1471
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001472 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1473 mvm->dbgfs_prph_reg_addr,
1474 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1475
Eliad Peller576eeee2014-07-01 18:38:38 +03001476 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1477
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001478 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1479}
1480
1481static ssize_t
1482iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1483 size_t count, loff_t *ppos)
1484{
1485 u8 args;
1486 u32 value;
Eliad Peller576eeee2014-07-01 18:38:38 +03001487 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001488
1489 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1490 /* if we only want to set the reg address - nothing more to do */
1491 if (args == 1)
1492 goto out;
1493
1494 /* otherwise, make sure we have both address and value */
1495 if (args != 2)
1496 return -EINVAL;
1497
Eliad Peller576eeee2014-07-01 18:38:38 +03001498 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1499 if (ret)
1500 return ret;
1501
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001502 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
Eliad Peller576eeee2014-07-01 18:38:38 +03001503
1504 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001505out:
1506 return count;
1507}
1508
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001509static ssize_t
1510iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1511 size_t count, loff_t *ppos)
1512{
1513 int ret;
1514
Johannes Berg504bd622017-03-22 22:19:41 +01001515 if (!iwl_mvm_firmware_running(mvm))
1516 return -EIO;
1517
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001518 mutex_lock(&mvm->mutex);
1519 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1520 mutex_unlock(&mvm->mutex);
1521
1522 return ret ?: count;
1523}
1524
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001525MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1526
Johannes Berg8ca151b2013-01-24 14:25:36 +01001527/* Device wide debugfs entries */
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001528MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1529MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001530MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1531MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001532MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001533MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001534MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001535MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001536MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001537MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001538MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001539MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001540MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001541MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001542MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1543MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001544MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001545MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001546MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001547MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001548MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001549MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001550MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001551MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
Sara Sharondd4d3162016-02-07 12:50:35 +02001552MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1553 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
Sara Sharon4857d6c2016-08-09 20:03:52 +03001554MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
Oren Givon91b05d12013-08-19 08:36:48 +03001555
Eliad Pellerde06a592014-01-08 10:11:12 +02001556#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1557MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1558MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1559#endif
1560
Johannes Bergafc66bb2013-05-03 11:44:16 +02001561#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001562MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001563#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001564
Ido Yariv2b55f432016-08-23 14:44:59 -04001565static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1566 size_t count, loff_t *ppos)
1567{
1568 struct iwl_mvm *mvm = file->private_data;
1569 struct iwl_dbg_mem_access_cmd cmd = {};
1570 struct iwl_dbg_mem_access_rsp *rsp;
1571 struct iwl_host_cmd hcmd = {
1572 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1573 .data = { &cmd, },
1574 .len = { sizeof(cmd) },
1575 };
Luca Coelho276c4b42016-09-28 11:32:35 +03001576 size_t delta;
1577 ssize_t ret, len;
Ido Yariv2b55f432016-08-23 14:44:59 -04001578
Johannes Berg504bd622017-03-22 22:19:41 +01001579 if (!iwl_mvm_firmware_running(mvm))
1580 return -EIO;
1581
Ido Yariv2b55f432016-08-23 14:44:59 -04001582 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1583 DEBUG_GROUP, 0);
1584 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1585
1586 /* Take care of alignment of both the position and the length */
1587 delta = *ppos & 0x3;
1588 cmd.addr = cpu_to_le32(*ppos - delta);
1589 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1590 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1591
1592 mutex_lock(&mvm->mutex);
1593 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1594 mutex_unlock(&mvm->mutex);
1595
1596 if (ret < 0)
1597 return ret;
1598
1599 rsp = (void *)hcmd.resp_pkt->data;
1600 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1601 ret = -ENXIO;
1602 goto out;
1603 }
1604
1605 len = min((size_t)le32_to_cpu(rsp->len) << 2,
1606 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1607 len = min(len - delta, count);
1608 if (len < 0) {
1609 ret = -EFAULT;
1610 goto out;
1611 }
1612
1613 ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1614 *ppos += ret;
1615
1616out:
1617 iwl_free_resp(&hcmd);
1618 return ret;
1619}
1620
1621static ssize_t iwl_dbgfs_mem_write(struct file *file,
1622 const char __user *user_buf, size_t count,
1623 loff_t *ppos)
1624{
1625 struct iwl_mvm *mvm = file->private_data;
1626 struct iwl_dbg_mem_access_cmd *cmd;
1627 struct iwl_dbg_mem_access_rsp *rsp;
1628 struct iwl_host_cmd hcmd = {};
1629 size_t cmd_size;
1630 size_t data_size;
1631 u32 op, len;
1632 ssize_t ret;
1633
Johannes Berg504bd622017-03-22 22:19:41 +01001634 if (!iwl_mvm_firmware_running(mvm))
1635 return -EIO;
1636
Ido Yariv2b55f432016-08-23 14:44:59 -04001637 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1638 DEBUG_GROUP, 0);
1639
1640 if (*ppos & 0x3 || count < 4) {
1641 op = DEBUG_MEM_OP_WRITE_BYTES;
1642 len = min(count, (size_t)(4 - (*ppos & 0x3)));
1643 data_size = len;
1644 } else {
1645 op = DEBUG_MEM_OP_WRITE;
1646 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1647 data_size = len << 2;
1648 }
1649
1650 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1651 cmd = kzalloc(cmd_size, GFP_KERNEL);
1652 if (!cmd)
1653 return -ENOMEM;
1654
1655 cmd->op = cpu_to_le32(op);
1656 cmd->len = cpu_to_le32(len);
1657 cmd->addr = cpu_to_le32(*ppos);
1658 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1659 kfree(cmd);
1660 return -EFAULT;
1661 }
1662
1663 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1664 hcmd.data[0] = (void *)cmd;
1665 hcmd.len[0] = cmd_size;
1666
1667 mutex_lock(&mvm->mutex);
1668 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1669 mutex_unlock(&mvm->mutex);
1670
1671 kfree(cmd);
1672
1673 if (ret < 0)
1674 return ret;
1675
1676 rsp = (void *)hcmd.resp_pkt->data;
1677 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1678 ret = -ENXIO;
1679 goto out;
1680 }
1681
1682 ret = data_size;
1683 *ppos += ret;
1684
1685out:
1686 iwl_free_resp(&hcmd);
1687 return ret;
1688}
1689
1690static const struct file_operations iwl_dbgfs_mem_ops = {
1691 .read = iwl_dbgfs_mem_read,
1692 .write = iwl_dbgfs_mem_write,
1693 .open = simple_open,
1694 .llseek = default_llseek,
1695};
1696
Johannes Berg8ca151b2013-01-24 14:25:36 +01001697int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1698{
Eliad Pellerde06a592014-01-08 10:11:12 +02001699 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001700 char buf[100];
1701
Johannes Bergd07913a2014-02-26 11:25:58 +01001702 spin_lock_init(&mvm->drv_stats_lock);
1703
Johannes Berg8ca151b2013-01-24 14:25:36 +01001704 mvm->debugfs_dir = dbgfs_dir;
1705
1706 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1707 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1708 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001709 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1710 S_IWUSR | S_IRUSR);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001711 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001712 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1713 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001714 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001715 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001716 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach639eaba2014-03-30 10:11:13 +03001717 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1718 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001719 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001720 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001721 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001722 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001723 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001724 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001725 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1726 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001727 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001728 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001729 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1730 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001731 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001732 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001733 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
Sara Sharon43413a92015-12-31 11:49:18 +02001734 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
Sara Sharon4857d6c2016-08-09 20:03:52 +03001735 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
Luciano Coelhocb2513b2015-02-27 16:26:57 +02001736 if (!debugfs_create_bool("enable_scan_iteration_notif",
1737 S_IRUSR | S_IWUSR,
1738 mvm->debugfs_dir,
1739 &mvm->scan_iter_notif_enabled))
1740 goto err;
Andrei Otcheretianskic89e3332016-01-26 18:12:28 +02001741 if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
1742 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1743 goto err;
Eliad Pellerde06a592014-01-08 10:11:12 +02001744
1745#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1746 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1747 bcast_dir = debugfs_create_dir("bcast_filtering",
1748 mvm->debugfs_dir);
1749 if (!bcast_dir)
1750 goto err;
1751
1752 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1753 bcast_dir,
1754 &mvm->dbgfs_bcast_filtering.override))
1755 goto err;
1756
1757 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1758 bcast_dir, S_IWUSR | S_IRUSR);
1759 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1760 bcast_dir, S_IWUSR | S_IRUSR);
1761 }
1762#endif
1763
Johannes Bergafc66bb2013-05-03 11:44:16 +02001764#ifdef CONFIG_PM_SLEEP
1765 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001766 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001767 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1768 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1769 goto err;
Luciano Coelho484b3d12015-03-30 20:46:32 +03001770 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1771 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1772 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001773#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001774
Luciano Coelhobdd54832014-08-07 18:08:56 +03001775 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1776 mvm->debugfs_dir, &mvm->ps_disabled))
1777 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001778 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1779 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1780 goto err;
1781 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1782 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1783 goto err;
1784 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1785 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1786 goto err;
1787 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1788 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1789 goto err;
Moshe Harel91fac942015-09-02 12:45:12 +03001790 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1791 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1792 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001793
Ido Yariv2b55f432016-08-23 14:44:59 -04001794 debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
1795 &iwl_dbgfs_mem_ops);
1796
Johannes Berg8ca151b2013-01-24 14:25:36 +01001797 /*
1798 * Create a symlink with mac80211. It will be removed when mac80211
1799 * exists (before the opmode exists which removes the target.)
1800 */
Al Viro27a22092016-08-07 12:21:25 -04001801 snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001802 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1803 goto err;
1804
1805 return 0;
1806err:
1807 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1808 return -ENOMEM;
1809}