blob: c2a1aeef74eceaebf56d5ede512649964a9d1553 [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;
Mordechai Goodsteind167e812017-05-10 16:42:53 +0300122 u32 flush_arg;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100123
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
Mordechai Goodsteind167e812017-05-10 16:42:53 +0300128 if (kstrtou32(buf, 0, &flush_arg))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100129 return -EINVAL;
130
Mordechai Goodsteind167e812017-05-10 16:42:53 +0300131 if (iwl_mvm_has_new_tx_api(mvm)) {
132 IWL_DEBUG_TX_QUEUES(mvm,
133 "FLUSHING all tids queues on sta_id = %d\n",
134 flush_arg);
135 mutex_lock(&mvm->mutex);
136 ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFF, 0) ? : count;
137 mutex_unlock(&mvm->mutex);
138 return ret;
139 }
140
141 IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
142 flush_arg);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100143
144 mutex_lock(&mvm->mutex);
Mordechai Goodsteind167e812017-05-10 16:42:53 +0300145 ret = iwl_mvm_flush_tx_path(mvm, flush_arg, 0) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100146 mutex_unlock(&mvm->mutex);
147
148 return ret;
149}
150
Johannes Berg1fa3f572013-11-13 09:10:21 +0100151static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100152 size_t count, loff_t *ppos)
153{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200154 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +0100155 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100156
Johannes Bergaab69302017-03-22 22:05:12 +0100157 if (!iwl_mvm_firmware_running(mvm) ||
158 mvm->cur_ucode != IWL_UCODE_REGULAR)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159 return -EIO;
160
Johannes Berg8ca151b2013-01-24 14:25:36 +0100161 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
162 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200163 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
164 return -EINVAL;
165 if (drain < 0 || drain > 1)
166 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100167
168 mutex_lock(&mvm->mutex);
169
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200170 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
171
172 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100173 ret = -ENOENT;
174 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200175 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176
177 mutex_unlock(&mvm->mutex);
178
179 return ret;
180}
181
182static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
183 size_t count, loff_t *ppos)
184{
185 struct iwl_mvm *mvm = file->private_data;
186 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200187 unsigned int ofs, len;
188 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100189 u8 *ptr;
190
Johannes Bergaab69302017-03-22 22:05:12 +0100191 if (!iwl_mvm_firmware_running(mvm))
Johannes Berg60191d92013-05-15 13:08:51 +0200192 return -EINVAL;
193
Johannes Berg8ca151b2013-01-24 14:25:36 +0100194 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200195 img = &mvm->fw->img[mvm->cur_ucode];
196 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
197 len = img->sec[IWL_UCODE_SECTION_DATA].len;
198
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200199 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200200 ofs = mvm->dbgfs_sram_offset;
201 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100202 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203
Johannes Berg8ca151b2013-01-24 14:25:36 +0100204 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200205 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100206 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100207
Johannes Berg60191d92013-05-15 13:08:51 +0200208 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100209
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200210 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100211
Johannes Berg8ca151b2013-01-24 14:25:36 +0100212 kfree(ptr);
213
214 return ret;
215}
216
Johannes Berg1fa3f572013-11-13 09:10:21 +0100217static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
218 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200220 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100221 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200222 u32 img_offset, img_len;
223
Johannes Bergaab69302017-03-22 22:05:12 +0100224 if (!iwl_mvm_firmware_running(mvm))
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200225 return -EINVAL;
226
227 img = &mvm->fw->img[mvm->cur_ucode];
228 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
229 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100230
Johannes Berg8ca151b2013-01-24 14:25:36 +0100231 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
232 if ((offset & 0x3) || (len & 0x3))
233 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200234
235 if (offset + len > img_offset + img_len)
236 return -EINVAL;
237
Johannes Berg8ca151b2013-01-24 14:25:36 +0100238 mvm->dbgfs_sram_offset = offset;
239 mvm->dbgfs_sram_len = len;
240 } else {
241 mvm->dbgfs_sram_offset = 0;
242 mvm->dbgfs_sram_len = 0;
243 }
244
245 return count;
246}
247
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300248static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
249 char __user *user_buf,
250 size_t count, loff_t *ppos)
251{
252 struct iwl_mvm *mvm = file->private_data;
253 char buf[16];
254 int pos;
255
256 if (!mvm->temperature_test)
257 pos = scnprintf(buf , sizeof(buf), "disabled\n");
258 else
259 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
260
261 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
262}
263
264/*
265 * Set NIC Temperature
266 * Cause the driver to ignore the actual NIC temperature reported by the FW
267 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
268 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
269 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
270 */
271static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
272 char *buf, size_t count,
273 loff_t *ppos)
274{
275 int temperature;
276
Johannes Bergaab69302017-03-22 22:05:12 +0100277 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
Luciano Coelhoa26d4e72014-08-20 10:21:07 +0300278 return -EIO;
279
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300280 if (kstrtoint(buf, 10, &temperature))
281 return -EINVAL;
282 /* not a legal temperature */
283 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
284 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
285 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
286 return -EINVAL;
287
288 mutex_lock(&mvm->mutex);
289 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
Luciano Coelhob689fa72014-08-20 17:26:58 +0300290 if (!mvm->temperature_test)
291 goto out;
292
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300293 mvm->temperature_test = false;
Luciano Coelhob689fa72014-08-20 17:26:58 +0300294 /* Since we can't read the temp while awake, just set
295 * it to zero until we get the next RX stats from the
296 * firmware.
297 */
298 mvm->temperature = 0;
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300299 } else {
300 mvm->temperature_test = true;
301 mvm->temperature = temperature;
302 }
303 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
304 mvm->temperature_test ? "En" : "Dis" ,
305 mvm->temperature);
306 /* handle the temperature change */
307 iwl_mvm_tt_handler(mvm);
Luciano Coelhob689fa72014-08-20 17:26:58 +0300308
309out:
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300310 mutex_unlock(&mvm->mutex);
311
312 return count;
313}
314
Luciano Coelhoc549e392014-09-04 15:58:47 +0300315static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
316 char __user *user_buf,
317 size_t count, loff_t *ppos)
318{
319 struct iwl_mvm *mvm = file->private_data;
320 char buf[16];
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200321 int pos, ret;
322 s32 temp;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300323
Johannes Bergaab69302017-03-22 22:05:12 +0100324 if (!iwl_mvm_firmware_running(mvm))
Luciano Coelhoc549e392014-09-04 15:58:47 +0300325 return -EIO;
326
327 mutex_lock(&mvm->mutex);
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200328 ret = iwl_mvm_get_temp(mvm, &temp);
Luciano Coelhoc549e392014-09-04 15:58:47 +0300329 mutex_unlock(&mvm->mutex);
330
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200331 if (ret)
332 return -EIO;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300333
334 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
335
336 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
337}
338
Johannes Berg8ca151b2013-01-24 14:25:36 +0100339static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
340 size_t count, loff_t *ppos)
341{
342 struct iwl_mvm *mvm = file->private_data;
343 struct ieee80211_sta *sta;
344 char buf[400];
345 int i, pos = 0, bufsz = sizeof(buf);
346
347 mutex_lock(&mvm->mutex);
348
Sara Sharon0ae98812017-01-04 14:53:58 +0200349 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100350 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
351 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
352 lockdep_is_held(&mvm->mutex));
353 if (!sta)
354 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
355 else if (IS_ERR(sta))
356 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
357 PTR_ERR(sta));
358 else
359 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
360 sta->addr);
361 }
362
363 mutex_unlock(&mvm->mutex);
364
365 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
366}
367
Alexander Bondar64b928c2013-09-03 14:18:03 +0300368static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
369 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100370 size_t count, loff_t *ppos)
371{
372 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300373 char buf[64];
374 int bufsz = sizeof(buf);
375 int pos = 0;
376
377 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
378 mvm->disable_power_off);
379 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
380 mvm->disable_power_off_d3);
381
382 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
383}
384
Johannes Berg1fa3f572013-11-13 09:10:21 +0100385static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300386 size_t count, loff_t *ppos)
387{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100388 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100389
Johannes Bergaab69302017-03-22 22:05:12 +0100390 if (!iwl_mvm_firmware_running(mvm))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100391 return -EIO;
392
Alexander Bondar64b928c2013-09-03 14:18:03 +0300393 if (!strncmp("disable_power_off_d0=", buf, 21)) {
394 if (sscanf(buf + 21, "%d", &val) != 1)
395 return -EINVAL;
396 mvm->disable_power_off = val;
397 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
398 if (sscanf(buf + 21, "%d", &val) != 1)
399 return -EINVAL;
400 mvm->disable_power_off_d3 = val;
401 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300403 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100404
Alexander Bondar64b928c2013-09-03 14:18:03 +0300405 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200406 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300407 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408
Alexander Bondar64b928c2013-09-03 14:18:03 +0300409 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100410}
411
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200412#define BT_MBOX_MSG(_notif, _num, _field) \
413 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
414 >> BT_MBOX##_num##_##_field##_POS)
415
416
417#define BT_MBOX_PRINT(_num, _field, _end) \
418 pos += scnprintf(buf + pos, bufsz - pos, \
419 "\t%s: %d%s", \
420 #_field, \
421 BT_MBOX_MSG(notif, _num, _field), \
422 true ? "\n" : ", ");
423
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300424static
425int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
426 int pos, int bufsz)
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200427{
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200428 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
429
430 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
431 BT_MBOX_PRINT(0, LE_PROF1, false);
432 BT_MBOX_PRINT(0, LE_PROF2, false);
433 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
434 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
435 BT_MBOX_PRINT(0, INBAND_S, false);
436 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
437 BT_MBOX_PRINT(0, LE_SCAN, false);
438 BT_MBOX_PRINT(0, LE_ADV, false);
439 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
440 BT_MBOX_PRINT(0, OPEN_CON_1, true);
441
442 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
443
444 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
445 BT_MBOX_PRINT(1, IP_SR, false);
446 BT_MBOX_PRINT(1, LE_MSTR, false);
447 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
448 BT_MBOX_PRINT(1, MSG_TYPE, false);
449 BT_MBOX_PRINT(1, SSN, true);
450
451 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
452
453 BT_MBOX_PRINT(2, SNIFF_ACT, false);
454 BT_MBOX_PRINT(2, PAG, false);
455 BT_MBOX_PRINT(2, INQUIRY, false);
456 BT_MBOX_PRINT(2, CONN, false);
457 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
458 BT_MBOX_PRINT(2, DISC, false);
459 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
460 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
461 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
462 BT_MBOX_PRINT(2, SCO_DURATION, true);
463
464 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
465
466 BT_MBOX_PRINT(3, SCO_STATE, false);
467 BT_MBOX_PRINT(3, SNIFF_STATE, false);
468 BT_MBOX_PRINT(3, A2DP_STATE, false);
469 BT_MBOX_PRINT(3, ACL_STATE, false);
470 BT_MBOX_PRINT(3, MSTR_STATE, false);
471 BT_MBOX_PRINT(3, OBX_STATE, false);
472 BT_MBOX_PRINT(3, OPEN_CON_2, false);
473 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
474 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
475 BT_MBOX_PRINT(3, INBAND_P, false);
476 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
477 BT_MBOX_PRINT(3, SSN_2, false);
478 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
479
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300480 return pos;
481}
482
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300483static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
484 size_t count, loff_t *ppos)
485{
486 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200487 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300488 char *buf;
489 int ret, pos = 0, bufsz = sizeof(char) * 1024;
490
491 buf = kmalloc(bufsz, GFP_KERNEL);
492 if (!buf)
493 return -ENOMEM;
494
495 mutex_lock(&mvm->mutex);
496
Sara Sharon97f95c92016-03-07 16:55:20 +0200497 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300498
Sara Sharon97f95c92016-03-07 16:55:20 +0200499 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
500 notif->bt_ci_compliance);
501 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
502 le32_to_cpu(notif->primary_ch_lut));
503 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
504 le32_to_cpu(notif->secondary_ch_lut));
505 pos += scnprintf(buf + pos,
506 bufsz - pos, "bt_activity_grading = %d\n",
507 le32_to_cpu(notif->bt_activity_grading));
508 pos += scnprintf(buf + pos, bufsz - pos,
509 "antenna isolation = %d CORUN LUT index = %d\n",
510 mvm->last_ant_isol, mvm->last_corun_lut);
511 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
512 (notif->ttc_rrc_status >> 4) & 0xF);
513 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
514 notif->ttc_rrc_status & 0xF);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200515
Moshe Harelc725a462015-10-27 14:04:12 +0200516 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
517 IWL_MVM_BT_COEX_SYNC2SCO);
518 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
519 IWL_MVM_BT_COEX_MPLUT);
520 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
521 IWL_MVM_BT_COEX_CORUNNING);
522
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200523 mutex_unlock(&mvm->mutex);
524
525 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
526 kfree(buf);
527
528 return ret;
529}
530#undef BT_MBOX_PRINT
531
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300532static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
533 size_t count, loff_t *ppos)
534{
535 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200536 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300537 char buf[256];
538 int bufsz = sizeof(buf);
539 int pos = 0;
540
541 mutex_lock(&mvm->mutex);
542
Sara Sharon97f95c92016-03-07 16:55:20 +0200543 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
544 pos += scnprintf(buf + pos, bufsz - pos,
545 "\tPrimary Channel Bitmap 0x%016llx\n",
546 le64_to_cpu(cmd->bt_primary_ci));
547 pos += scnprintf(buf + pos, bufsz - pos,
548 "\tSecondary Channel Bitmap 0x%016llx\n",
549 le64_to_cpu(cmd->bt_secondary_ci));
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300550
551 mutex_unlock(&mvm->mutex);
552
553 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
554}
555
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200556static ssize_t
557iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
558 size_t count, loff_t *ppos)
559{
560 u32 bt_tx_prio;
561
562 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
563 return -EINVAL;
564 if (bt_tx_prio > 4)
565 return -EINVAL;
566
567 mvm->bt_tx_prio = bt_tx_prio;
568
569 return count;
570}
571
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300572static ssize_t
573iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
574 size_t count, loff_t *ppos)
575{
576 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
577 [BT_FORCE_ANT_DIS] = "dis",
578 [BT_FORCE_ANT_AUTO] = "auto",
579 [BT_FORCE_ANT_BT] = "bt",
580 [BT_FORCE_ANT_WIFI] = "wifi",
581 };
582 int ret, bt_force_ant_mode;
583
584 for (bt_force_ant_mode = 0;
585 bt_force_ant_mode < ARRAY_SIZE(modes_str);
586 bt_force_ant_mode++) {
587 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
588 break;
589 }
590
591 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
592 return -EINVAL;
593
594 ret = 0;
595 mutex_lock(&mvm->mutex);
596 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
597 goto out;
598
599 mvm->bt_force_ant_mode = bt_force_ant_mode;
600 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
601 modes_str[mvm->bt_force_ant_mode]);
Johannes Berg504bd622017-03-22 22:19:41 +0100602
603 if (iwl_mvm_firmware_running(mvm))
604 ret = iwl_send_bt_init_conf(mvm);
605 else
606 ret = 0;
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300607
608out:
609 mutex_unlock(&mvm->mutex);
610 return ret ?: count;
611}
612
Johannes Berg93d17cc2015-01-15 12:59:26 +0100613#define PRINT_STATS_LE32(_struct, _memb) \
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300614 pos += scnprintf(buf + pos, bufsz - pos, \
Johannes Berg93d17cc2015-01-15 12:59:26 +0100615 fmt_table, #_memb, \
616 le32_to_cpu(_struct->_memb))
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300617
618static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
619 char __user *user_buf, size_t count,
620 loff_t *ppos)
621{
622 struct iwl_mvm *mvm = file->private_data;
623 static const char *fmt_table = "\t%-30s %10u\n";
624 static const char *fmt_header = "%-32s\n";
625 int pos = 0;
626 char *buf;
627 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300628 /* 43 is the size of each data line, 33 is the size of each header */
629 size_t bufsz =
630 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
631 (4 * 33) + 1;
632
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300633 struct mvm_statistics_rx_phy *ofdm;
634 struct mvm_statistics_rx_phy *cck;
635 struct mvm_statistics_rx_non_phy *general;
636 struct mvm_statistics_rx_ht_phy *ht;
637
638 buf = kzalloc(bufsz, GFP_KERNEL);
639 if (!buf)
640 return -ENOMEM;
641
642 mutex_lock(&mvm->mutex);
643
644 ofdm = &mvm->rx_stats.ofdm;
645 cck = &mvm->rx_stats.cck;
646 general = &mvm->rx_stats.general;
647 ht = &mvm->rx_stats.ofdm_ht;
648
649 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
650 "Statistics_Rx - OFDM");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100651 PRINT_STATS_LE32(ofdm, ina_cnt);
652 PRINT_STATS_LE32(ofdm, fina_cnt);
653 PRINT_STATS_LE32(ofdm, plcp_err);
654 PRINT_STATS_LE32(ofdm, crc32_err);
655 PRINT_STATS_LE32(ofdm, overrun_err);
656 PRINT_STATS_LE32(ofdm, early_overrun_err);
657 PRINT_STATS_LE32(ofdm, crc32_good);
658 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
659 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
660 PRINT_STATS_LE32(ofdm, sfd_timeout);
661 PRINT_STATS_LE32(ofdm, fina_timeout);
662 PRINT_STATS_LE32(ofdm, unresponded_rts);
663 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
664 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
665 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
666 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
667 PRINT_STATS_LE32(ofdm, dsp_self_kill);
668 PRINT_STATS_LE32(ofdm, mh_format_err);
669 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
670 PRINT_STATS_LE32(ofdm, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300671
672 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
673 "Statistics_Rx - CCK");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100674 PRINT_STATS_LE32(cck, ina_cnt);
675 PRINT_STATS_LE32(cck, fina_cnt);
676 PRINT_STATS_LE32(cck, plcp_err);
677 PRINT_STATS_LE32(cck, crc32_err);
678 PRINT_STATS_LE32(cck, overrun_err);
679 PRINT_STATS_LE32(cck, early_overrun_err);
680 PRINT_STATS_LE32(cck, crc32_good);
681 PRINT_STATS_LE32(cck, false_alarm_cnt);
682 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
683 PRINT_STATS_LE32(cck, sfd_timeout);
684 PRINT_STATS_LE32(cck, fina_timeout);
685 PRINT_STATS_LE32(cck, unresponded_rts);
686 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
687 PRINT_STATS_LE32(cck, sent_ack_cnt);
688 PRINT_STATS_LE32(cck, sent_cts_cnt);
689 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
690 PRINT_STATS_LE32(cck, dsp_self_kill);
691 PRINT_STATS_LE32(cck, mh_format_err);
692 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
693 PRINT_STATS_LE32(cck, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300694
695 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
696 "Statistics_Rx - GENERAL");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100697 PRINT_STATS_LE32(general, bogus_cts);
698 PRINT_STATS_LE32(general, bogus_ack);
699 PRINT_STATS_LE32(general, non_bssid_frames);
700 PRINT_STATS_LE32(general, filtered_frames);
701 PRINT_STATS_LE32(general, non_channel_beacons);
702 PRINT_STATS_LE32(general, channel_beacons);
703 PRINT_STATS_LE32(general, num_missed_bcon);
704 PRINT_STATS_LE32(general, adc_rx_saturation_time);
705 PRINT_STATS_LE32(general, ina_detection_search_time);
706 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
707 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
708 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
709 PRINT_STATS_LE32(general, interference_data_flag);
710 PRINT_STATS_LE32(general, channel_load);
711 PRINT_STATS_LE32(general, dsp_false_alarms);
712 PRINT_STATS_LE32(general, beacon_rssi_a);
713 PRINT_STATS_LE32(general, beacon_rssi_b);
714 PRINT_STATS_LE32(general, beacon_rssi_c);
715 PRINT_STATS_LE32(general, beacon_energy_a);
716 PRINT_STATS_LE32(general, beacon_energy_b);
717 PRINT_STATS_LE32(general, beacon_energy_c);
718 PRINT_STATS_LE32(general, num_bt_kills);
719 PRINT_STATS_LE32(general, mac_id);
720 PRINT_STATS_LE32(general, directed_data_mpdu);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300721
722 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
723 "Statistics_Rx - HT");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100724 PRINT_STATS_LE32(ht, plcp_err);
725 PRINT_STATS_LE32(ht, overrun_err);
726 PRINT_STATS_LE32(ht, early_overrun_err);
727 PRINT_STATS_LE32(ht, crc32_good);
728 PRINT_STATS_LE32(ht, crc32_err);
729 PRINT_STATS_LE32(ht, mh_format_err);
730 PRINT_STATS_LE32(ht, agg_crc32_good);
731 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
732 PRINT_STATS_LE32(ht, agg_cnt);
733 PRINT_STATS_LE32(ht, unsupport_mcs);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300734
735 mutex_unlock(&mvm->mutex);
736
737 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
738 kfree(buf);
739
740 return ret;
741}
742#undef PRINT_STAT_LE32
743
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200744static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
745 char __user *user_buf, size_t count,
746 loff_t *ppos,
747 struct iwl_mvm_frame_stats *stats)
748{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200749 char *buff, *pos, *endpos;
750 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200751 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200752 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200753
754 buff = kmalloc(bufsz, GFP_KERNEL);
755 if (!buff)
756 return -ENOMEM;
757
758 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200759
760 pos = buff;
761 endpos = pos + bufsz;
762
763 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200764 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
765 stats->legacy_frames,
766 stats->ht_frames,
767 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200768 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200769 stats->bw_20_frames,
770 stats->bw_40_frames,
771 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200772 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200773 stats->ngi_frames,
774 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200775 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200776 stats->siso_frames,
777 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200778 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200779 stats->fail_frames,
780 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200781 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200782 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200783 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200784 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200785 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200786 stats->ampdu_count > 0 ?
787 (stats->agg_frames / stats->ampdu_count) : 0);
788
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200789 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200790
791 idx = stats->last_frame_idx - 1;
792 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
793 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
794 if (stats->last_rates[idx] == 0)
795 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200796 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200797 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200798 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200799 }
800 spin_unlock_bh(&mvm->drv_stats_lock);
801
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200802 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200803 kfree(buff);
804
805 return ret;
806}
807
808static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
809 char __user *user_buf, size_t count,
810 loff_t *ppos)
811{
812 struct iwl_mvm *mvm = file->private_data;
813
814 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
815 &mvm->drv_rx_stats);
816}
817
Johannes Berg1fa3f572013-11-13 09:10:21 +0100818static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200819 size_t count, loff_t *ppos)
820{
Luca Coelho758d1a82016-11-09 10:02:46 +0200821 int __maybe_unused ret;
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200822
Johannes Berg504bd622017-03-22 22:19:41 +0100823 if (!iwl_mvm_firmware_running(mvm))
824 return -EIO;
825
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200826 mutex_lock(&mvm->mutex);
827
Eran Harary291aa7c2013-07-03 11:00:06 +0300828 /* allow one more restart that we're provoking here */
829 if (mvm->restart_fw >= 0)
830 mvm->restart_fw++;
831
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200832 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300833 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200834
835 mutex_unlock(&mvm->mutex);
836
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200837 return count;
838}
839
Johannes Berg1fa3f572013-11-13 09:10:21 +0100840static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200841 size_t count, loff_t *ppos)
842{
Johannes Berg504bd622017-03-22 22:19:41 +0100843 int ret;
844
845 if (!iwl_mvm_firmware_running(mvm))
846 return -EIO;
847
848 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
Eliad Peller576eeee2014-07-01 18:38:38 +0300849 if (ret)
850 return ret;
851
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300852 iwl_force_nmi(mvm->trans);
Alexander Bondar119663c2013-10-17 14:26:50 +0200853
Eliad Peller576eeee2014-07-01 18:38:38 +0300854 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
855
Alexander Bondar119663c2013-10-17 14:26:50 +0200856 return count;
857}
858
Oren Givon91b05d12013-08-19 08:36:48 +0300859static ssize_t
860iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
861 char __user *user_buf,
862 size_t count, loff_t *ppos)
863{
864 struct iwl_mvm *mvm = file->private_data;
865 int pos = 0;
866 char buf[32];
867 const size_t bufsz = sizeof(buf);
868
869 /* print which antennas were set for the scan command by the user */
870 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
871 if (mvm->scan_rx_ant & ANT_A)
872 pos += scnprintf(buf + pos, bufsz - pos, "A");
873 if (mvm->scan_rx_ant & ANT_B)
874 pos += scnprintf(buf + pos, bufsz - pos, "B");
875 if (mvm->scan_rx_ant & ANT_C)
876 pos += scnprintf(buf + pos, bufsz - pos, "C");
877 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
878
879 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
880}
881
882static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100883iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300884 size_t count, loff_t *ppos)
885{
Oren Givon91b05d12013-08-19 08:36:48 +0300886 u8 scan_rx_ant;
887
Johannes Berg504bd622017-03-22 22:19:41 +0100888 if (!iwl_mvm_firmware_running(mvm))
889 return -EIO;
890
Oren Givon91b05d12013-08-19 08:36:48 +0300891 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
892 return -EINVAL;
893 if (scan_rx_ant > ANT_ABC)
894 return -EINVAL;
Moshe Harela0544272014-12-08 21:13:14 +0200895 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
Oren Givon91b05d12013-08-19 08:36:48 +0300896 return -EINVAL;
897
David Spinadeld2496222014-05-20 12:46:37 +0300898 if (mvm->scan_rx_ant != scan_rx_ant) {
899 mvm->scan_rx_ant = scan_rx_ant;
Johannes Berg859d9142015-06-01 17:11:11 +0200900 if (fw_has_capa(&mvm->fw->ucode_capa,
901 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
David Spinadeld2496222014-05-20 12:46:37 +0300902 iwl_mvm_config_scan(mvm);
903 }
Oren Givon91b05d12013-08-19 08:36:48 +0300904
905 return count;
906}
907
Sara Sharon43413a92015-12-31 11:49:18 +0200908static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
909 char *buf, size_t count,
910 loff_t *ppos)
911{
912 struct iwl_rss_config_cmd cmd = {
913 .flags = cpu_to_le32(IWL_RSS_ENABLE),
914 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200915 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200916 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
917 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200918 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200919 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
920 };
921 int ret, i, num_repeats, nbytes = count / 2;
922
923 ret = hex2bin(cmd.indirection_table, buf, nbytes);
924 if (ret)
925 return ret;
926
927 /*
928 * The input is the redirection table, partial or full.
929 * Repeat the pattern if needed.
930 * For example, input of 01020F will be repeated 42 times,
931 * indirecting RSS hash results to queues 1, 2, 15 (skipping
932 * queues 3 - 14).
933 */
934 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
935 for (i = 1; i < num_repeats; i++)
936 memcpy(&cmd.indirection_table[i * nbytes],
937 cmd.indirection_table, nbytes);
938 /* handle cut in the middle pattern for the last places */
939 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
940 ARRAY_SIZE(cmd.indirection_table) % nbytes);
941
Sara Sharon854d7732016-03-22 15:55:58 +0200942 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200943
944 mutex_lock(&mvm->mutex);
Johannes Berg504bd622017-03-22 22:19:41 +0100945 if (iwl_mvm_firmware_running(mvm))
946 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
947 sizeof(cmd), &cmd);
948 else
949 ret = 0;
Sara Sharon43413a92015-12-31 11:49:18 +0200950 mutex_unlock(&mvm->mutex);
951
952 return ret ?: count;
953}
954
Sara Sharon4857d6c2016-08-09 20:03:52 +0300955static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
956 char *buf, size_t count,
957 loff_t *ppos)
958{
959 struct iwl_rx_cmd_buffer rxb = {
960 ._rx_page_order = 0,
961 .truesize = 0, /* not used */
962 ._offset = 0,
963 };
964 struct iwl_rx_packet *pkt;
965 struct iwl_rx_mpdu_desc *desc;
966 int bin_len = count / 2;
967 int ret = -EINVAL;
968
Johannes Berg504bd622017-03-22 22:19:41 +0100969 if (!iwl_mvm_firmware_running(mvm))
970 return -EIO;
971
Sara Sharon4857d6c2016-08-09 20:03:52 +0300972 /* supporting only 9000 descriptor */
973 if (!mvm->trans->cfg->mq_rx_supported)
974 return -ENOTSUPP;
975
976 rxb._page = alloc_pages(GFP_ATOMIC, 0);
977 if (!rxb._page)
978 return -ENOMEM;
979 pkt = rxb_addr(&rxb);
980
981 ret = hex2bin(page_address(rxb._page), buf, bin_len);
982 if (ret)
983 goto out;
984
985 /* avoid invalid memory access */
986 if (bin_len < sizeof(*pkt) + sizeof(*desc))
987 goto out;
988
989 /* check this is RX packet */
990 if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
991 WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
992 goto out;
993
994 /* check the length in metadata matches actual received length */
995 desc = (void *)pkt->data;
996 if (le16_to_cpu(desc->mpdu_len) !=
997 (bin_len - sizeof(*desc) - sizeof(*pkt)))
998 goto out;
999
1000 local_bh_disable();
1001 iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
1002 local_bh_enable();
1003 ret = 0;
1004
1005out:
1006 iwl_free_rxb(&rxb);
1007
1008 return ret ?: count;
1009}
1010
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001011static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1012 char __user *user_buf,
1013 size_t count, loff_t *ppos)
1014{
1015 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001016 int conf;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001017 char buf[8];
1018 const size_t bufsz = sizeof(buf);
1019 int pos = 0;
1020
1021 mutex_lock(&mvm->mutex);
1022 conf = mvm->fw_dbg_conf;
1023 mutex_unlock(&mvm->mutex);
1024
1025 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1026
1027 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1028}
1029
Golan Ben Ami321c2102015-07-27 17:02:35 +03001030/*
1031 * Enable / Disable continuous recording.
1032 * Cause the FW to start continuous recording, by sending the relevant hcmd.
1033 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
1034 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
1035 */
1036static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
1037 char *buf, size_t count,
1038 loff_t *ppos)
1039{
1040 struct iwl_trans *trans = mvm->trans;
1041 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
1042 struct iwl_continuous_record_cmd cont_rec = {};
1043 int ret, rec_mode;
1044
Johannes Berg504bd622017-03-22 22:19:41 +01001045 if (!iwl_mvm_firmware_running(mvm))
1046 return -EIO;
1047
Golan Ben Ami321c2102015-07-27 17:02:35 +03001048 if (!dest)
1049 return -EOPNOTSUPP;
1050
1051 if (dest->monitor_mode != SMEM_MODE ||
Sara Sharon6e584872017-03-22 14:07:50 +02001052 trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
Golan Ben Ami321c2102015-07-27 17:02:35 +03001053 return -EOPNOTSUPP;
1054
Johannes Berg27e070d2016-01-14 10:55:22 +01001055 ret = kstrtoint(buf, 0, &rec_mode);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001056 if (ret)
1057 return ret;
1058
1059 cont_rec.record_mode.enable_recording = rec_mode ?
1060 cpu_to_le16(ENABLE_CONT_RECORDING) :
1061 cpu_to_le16(DISABLE_CONT_RECORDING);
1062
1063 mutex_lock(&mvm->mutex);
1064 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1065 sizeof(cont_rec), &cont_rec);
1066 mutex_unlock(&mvm->mutex);
1067
1068 return ret ?: count;
1069}
1070
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001071static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1072 char *buf, size_t count,
1073 loff_t *ppos)
1074{
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001075 unsigned int conf_id;
1076 int ret;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001077
Johannes Berg504bd622017-03-22 22:19:41 +01001078 if (!iwl_mvm_firmware_running(mvm))
1079 return -EIO;
1080
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001081 ret = kstrtouint(buf, 0, &conf_id);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001082 if (ret)
1083 return ret;
1084
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001085 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001086 return -EINVAL;
1087
1088 mutex_lock(&mvm->mutex);
1089 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1090 mutex_unlock(&mvm->mutex);
1091
1092 return ret ?: count;
1093}
1094
1095static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1096 char *buf, size_t count,
1097 loff_t *ppos)
1098{
Johannes Berg504bd622017-03-22 22:19:41 +01001099 int ret;
Liad Kaufmane93475a2015-01-04 11:03:13 +02001100
Johannes Berg504bd622017-03-22 22:19:41 +01001101 if (!iwl_mvm_firmware_running(mvm))
1102 return -EIO;
1103
1104 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001105 if (ret)
1106 return ret;
Dan Carpenter251fe092017-03-23 13:40:00 +03001107 if (count == 0)
1108 return 0;
Liad Kaufmane93475a2015-01-04 11:03:13 +02001109
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001110 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1111 (count - 1), NULL);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001112
1113 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001114
1115 return count;
1116}
1117
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001118static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1119 char *buf, size_t count,
1120 loff_t *ppos)
1121{
1122 unsigned int max_amsdu_len;
1123 int ret;
1124
1125 ret = kstrtouint(buf, 0, &max_amsdu_len);
Dan Carpenter32afd152016-05-04 09:19:54 +03001126 if (ret)
1127 return ret;
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001128
1129 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1130 return -EINVAL;
1131 mvm->max_amsdu_len = max_amsdu_len;
1132
1133 return count;
1134}
1135
Eliad Pellerde06a592014-01-08 10:11:12 +02001136#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1137#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1138static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1139 char __user *user_buf,
1140 size_t count, loff_t *ppos)
1141{
1142 struct iwl_mvm *mvm = file->private_data;
1143 struct iwl_bcast_filter_cmd cmd;
1144 const struct iwl_fw_bcast_filter *filter;
1145 char *buf;
1146 int bufsz = 1024;
1147 int i, j, pos = 0;
1148 ssize_t ret;
1149
1150 buf = kzalloc(bufsz, GFP_KERNEL);
1151 if (!buf)
1152 return -ENOMEM;
1153
1154 mutex_lock(&mvm->mutex);
1155 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1156 ADD_TEXT("None\n");
1157 mutex_unlock(&mvm->mutex);
1158 goto out;
1159 }
1160 mutex_unlock(&mvm->mutex);
1161
1162 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1163 filter = &cmd.filters[i];
1164
1165 ADD_TEXT("Filter [%d]:\n", i);
1166 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1167 ADD_TEXT("\tFrame Type: %s\n",
1168 filter->frame_type ? "IPv4" : "Generic");
1169
1170 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1171 const struct iwl_fw_bcast_filter_attr *attr;
1172
1173 attr = &filter->attrs[j];
1174 if (!attr->mask)
1175 break;
1176
1177 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1178 j, attr->offset,
1179 attr->offset_type ? "IP End" :
1180 "Payload Start",
1181 be32_to_cpu(attr->mask),
1182 be32_to_cpu(attr->val),
1183 le16_to_cpu(attr->reserved1));
1184 }
1185 }
1186out:
1187 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1188 kfree(buf);
1189 return ret;
1190}
1191
1192static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1193 size_t count, loff_t *ppos)
1194{
1195 int pos, next_pos;
1196 struct iwl_fw_bcast_filter filter = {};
1197 struct iwl_bcast_filter_cmd cmd;
1198 u32 filter_id, attr_id, mask, value;
1199 int err = 0;
1200
1201 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1202 &filter.frame_type, &pos) != 3)
1203 return -EINVAL;
1204
1205 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1206 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1207 return -EINVAL;
1208
1209 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1210 attr_id++) {
1211 struct iwl_fw_bcast_filter_attr *attr =
1212 &filter.attrs[attr_id];
1213
1214 if (pos >= count)
1215 break;
1216
1217 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1218 &attr->offset, &attr->offset_type,
1219 &mask, &value, &next_pos) != 4)
1220 return -EINVAL;
1221
1222 attr->mask = cpu_to_be32(mask);
1223 attr->val = cpu_to_be32(value);
1224 if (mask)
1225 filter.num_attrs++;
1226
1227 pos += next_pos;
1228 }
1229
1230 mutex_lock(&mvm->mutex);
1231 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1232 &filter, sizeof(filter));
1233
1234 /* send updated bcast filtering configuration */
Johannes Berg504bd622017-03-22 22:19:41 +01001235 if (iwl_mvm_firmware_running(mvm) &&
1236 mvm->dbgfs_bcast_filtering.override &&
Eliad Pellerde06a592014-01-08 10:11:12 +02001237 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001238 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001239 sizeof(cmd), &cmd);
1240 mutex_unlock(&mvm->mutex);
1241
1242 return err ?: count;
1243}
1244
1245static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1246 char __user *user_buf,
1247 size_t count, loff_t *ppos)
1248{
1249 struct iwl_mvm *mvm = file->private_data;
1250 struct iwl_bcast_filter_cmd cmd;
1251 char *buf;
1252 int bufsz = 1024;
1253 int i, pos = 0;
1254 ssize_t ret;
1255
1256 buf = kzalloc(bufsz, GFP_KERNEL);
1257 if (!buf)
1258 return -ENOMEM;
1259
1260 mutex_lock(&mvm->mutex);
1261 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1262 ADD_TEXT("None\n");
1263 mutex_unlock(&mvm->mutex);
1264 goto out;
1265 }
1266 mutex_unlock(&mvm->mutex);
1267
1268 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1269 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1270
1271 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1272 i, mac->default_discard, mac->attached_filters);
1273 }
1274out:
1275 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1276 kfree(buf);
1277 return ret;
1278}
1279
1280static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1281 char *buf, size_t count,
1282 loff_t *ppos)
1283{
1284 struct iwl_bcast_filter_cmd cmd;
1285 struct iwl_fw_bcast_mac mac = {};
1286 u32 mac_id, attached_filters;
1287 int err = 0;
1288
1289 if (!mvm->bcast_filters)
1290 return -ENOENT;
1291
1292 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1293 &attached_filters) != 3)
1294 return -EINVAL;
1295
1296 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1297 mac.default_discard > 1 ||
1298 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1299 return -EINVAL;
1300
1301 mac.attached_filters = cpu_to_le16(attached_filters);
1302
1303 mutex_lock(&mvm->mutex);
1304 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1305 &mac, sizeof(mac));
1306
1307 /* send updated bcast filtering configuration */
Johannes Berg504bd622017-03-22 22:19:41 +01001308 if (iwl_mvm_firmware_running(mvm) &&
1309 mvm->dbgfs_bcast_filtering.override &&
Eliad Pellerde06a592014-01-08 10:11:12 +02001310 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001311 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001312 sizeof(cmd), &cmd);
1313 mutex_unlock(&mvm->mutex);
1314
1315 return err ?: count;
1316}
1317#endif
1318
Johannes Bergafc66bb2013-05-03 11:44:16 +02001319#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001320static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +02001321 size_t count, loff_t *ppos)
1322{
Johannes Bergafc66bb2013-05-03 11:44:16 +02001323 int store;
1324
Johannes Bergafc66bb2013-05-03 11:44:16 +02001325 if (sscanf(buf, "%d", &store) != 1)
1326 return -EINVAL;
1327
1328 mvm->store_d3_resume_sram = store;
1329
1330 return count;
1331}
1332
1333static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1334 size_t count, loff_t *ppos)
1335{
1336 struct iwl_mvm *mvm = file->private_data;
1337 const struct fw_img *img;
1338 int ofs, len, pos = 0;
1339 size_t bufsz, ret;
1340 char *buf;
1341 u8 *ptr = mvm->d3_resume_sram;
1342
1343 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1344 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1345
1346 bufsz = len * 4 + 256;
1347 buf = kzalloc(bufsz, GFP_KERNEL);
1348 if (!buf)
1349 return -ENOMEM;
1350
1351 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1352 mvm->store_d3_resume_sram ? "en" : "dis");
1353
1354 if (ptr) {
1355 for (ofs = 0; ofs < len; ofs += 16) {
1356 pos += scnprintf(buf + pos, bufsz - pos,
Andy Shevchenko3cd6e2f2015-07-16 15:42:14 +03001357 "0x%.4x %16ph\n", ofs, ptr + ofs);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001358 }
1359 } else {
1360 pos += scnprintf(buf + pos, bufsz - pos,
1361 "(no data captured)\n");
1362 }
1363
1364 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1365
1366 kfree(buf);
1367
1368 return ret;
1369}
1370#endif
1371
Eliad Peller576eeee2014-07-01 18:38:38 +03001372#define PRINT_MVM_REF(ref) do { \
1373 if (mvm->refs[ref]) \
1374 pos += scnprintf(buf + pos, bufsz - pos, \
1375 "\t(0x%lx): %d %s\n", \
1376 BIT(ref), mvm->refs[ref], #ref); \
Eliad Peller70d6bab2013-11-05 14:45:16 +02001377} while (0)
1378
1379static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1380 char __user *user_buf,
1381 size_t count, loff_t *ppos)
1382{
1383 struct iwl_mvm *mvm = file->private_data;
Eliad Peller576eeee2014-07-01 18:38:38 +03001384 int i, pos = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001385 char buf[256];
1386 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001387 u32 refs = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001388
Eliad Peller576eeee2014-07-01 18:38:38 +03001389 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1390 if (mvm->refs[i])
1391 refs |= BIT(i);
1392
1393 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1394 refs);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001395
1396 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1397 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1398 PRINT_MVM_REF(IWL_MVM_REF_ROC);
Eliad Pellerc7792732015-04-19 11:41:04 +03001399 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001400 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1401 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +02001402 PRINT_MVM_REF(IWL_MVM_REF_USER);
Johannes Berg34e611e2014-09-12 10:28:01 +02001403 PRINT_MVM_REF(IWL_MVM_REF_TX);
1404 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1405 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1406 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1407 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1408 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1409 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1410 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1411 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1412 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1413 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1414 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
Eliad Pellerd15a7472014-03-27 18:53:12 +02001415 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
Eliad Peller160acc02014-11-25 12:34:45 +02001416 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
Liad Kaufmanfb2380a2015-01-01 17:42:46 +02001417 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
Eliad Peller08f0d232015-12-10 15:47:11 +02001418 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
Luca Coelho71b12302016-03-11 12:12:16 +02001419 PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
Luca Coelho16e4dd82016-03-30 15:05:56 +03001420 PRINT_MVM_REF(IWL_MVM_REF_RX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001421
1422 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1423}
1424
Eliad Peller0eb83652013-11-11 18:56:35 +02001425static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1426 size_t count, loff_t *ppos)
1427{
1428 unsigned long value;
1429 int ret;
1430 bool taken;
1431
1432 ret = kstrtoul(buf, 10, &value);
1433 if (ret < 0)
1434 return ret;
1435
1436 mutex_lock(&mvm->mutex);
1437
Eliad Peller576eeee2014-07-01 18:38:38 +03001438 taken = mvm->refs[IWL_MVM_REF_USER];
Eliad Peller0eb83652013-11-11 18:56:35 +02001439 if (value == 1 && !taken)
1440 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1441 else if (value == 0 && taken)
1442 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1443 else
1444 ret = -EINVAL;
1445
1446 mutex_unlock(&mvm->mutex);
1447
1448 if (ret < 0)
1449 return ret;
1450 return count;
1451}
1452
Johannes Berg1fa3f572013-11-13 09:10:21 +01001453#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1454 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1455#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1456 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001457#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1458 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001459 &iwl_dbgfs_##name##_ops)) \
1460 goto err; \
1461 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +02001462#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1463 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001464
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001465static ssize_t
1466iwl_dbgfs_prph_reg_read(struct file *file,
1467 char __user *user_buf,
1468 size_t count, loff_t *ppos)
1469{
1470 struct iwl_mvm *mvm = file->private_data;
1471 int pos = 0;
1472 char buf[32];
1473 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001474 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001475
1476 if (!mvm->dbgfs_prph_reg_addr)
1477 return -EINVAL;
1478
Eliad Peller576eeee2014-07-01 18:38:38 +03001479 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1480 if (ret)
1481 return ret;
1482
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001483 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1484 mvm->dbgfs_prph_reg_addr,
1485 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1486
Eliad Peller576eeee2014-07-01 18:38:38 +03001487 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1488
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001489 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1490}
1491
1492static ssize_t
1493iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1494 size_t count, loff_t *ppos)
1495{
1496 u8 args;
1497 u32 value;
Eliad Peller576eeee2014-07-01 18:38:38 +03001498 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001499
1500 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1501 /* if we only want to set the reg address - nothing more to do */
1502 if (args == 1)
1503 goto out;
1504
1505 /* otherwise, make sure we have both address and value */
1506 if (args != 2)
1507 return -EINVAL;
1508
Eliad Peller576eeee2014-07-01 18:38:38 +03001509 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1510 if (ret)
1511 return ret;
1512
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001513 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
Eliad Peller576eeee2014-07-01 18:38:38 +03001514
1515 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001516out:
1517 return count;
1518}
1519
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001520static ssize_t
1521iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1522 size_t count, loff_t *ppos)
1523{
1524 int ret;
1525
Johannes Berg504bd622017-03-22 22:19:41 +01001526 if (!iwl_mvm_firmware_running(mvm))
1527 return -EIO;
1528
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001529 mutex_lock(&mvm->mutex);
1530 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1531 mutex_unlock(&mvm->mutex);
1532
1533 return ret ?: count;
1534}
1535
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001536MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1537
Johannes Berg8ca151b2013-01-24 14:25:36 +01001538/* Device wide debugfs entries */
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001539MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1540MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001541MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1542MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001543MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001544MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001545MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001546MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001547MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001548MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001549MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001550MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001551MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001552MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001553MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1554MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001555MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001556MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001557MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001558MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001559MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001560MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001561MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001562MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
Sara Sharondd4d3162016-02-07 12:50:35 +02001563MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1564 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
Sara Sharon4857d6c2016-08-09 20:03:52 +03001565MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
Oren Givon91b05d12013-08-19 08:36:48 +03001566
Eliad Pellerde06a592014-01-08 10:11:12 +02001567#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1568MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1569MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1570#endif
1571
Johannes Bergafc66bb2013-05-03 11:44:16 +02001572#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001573MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001574#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001575
Ido Yariv2b55f432016-08-23 14:44:59 -04001576static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1577 size_t count, loff_t *ppos)
1578{
1579 struct iwl_mvm *mvm = file->private_data;
1580 struct iwl_dbg_mem_access_cmd cmd = {};
1581 struct iwl_dbg_mem_access_rsp *rsp;
1582 struct iwl_host_cmd hcmd = {
1583 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1584 .data = { &cmd, },
1585 .len = { sizeof(cmd) },
1586 };
Luca Coelho276c4b42016-09-28 11:32:35 +03001587 size_t delta;
1588 ssize_t ret, len;
Ido Yariv2b55f432016-08-23 14:44:59 -04001589
Johannes Berg504bd622017-03-22 22:19:41 +01001590 if (!iwl_mvm_firmware_running(mvm))
1591 return -EIO;
1592
Ido Yariv2b55f432016-08-23 14:44:59 -04001593 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1594 DEBUG_GROUP, 0);
1595 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1596
1597 /* Take care of alignment of both the position and the length */
1598 delta = *ppos & 0x3;
1599 cmd.addr = cpu_to_le32(*ppos - delta);
1600 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1601 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1602
1603 mutex_lock(&mvm->mutex);
1604 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1605 mutex_unlock(&mvm->mutex);
1606
1607 if (ret < 0)
1608 return ret;
1609
1610 rsp = (void *)hcmd.resp_pkt->data;
1611 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1612 ret = -ENXIO;
1613 goto out;
1614 }
1615
1616 len = min((size_t)le32_to_cpu(rsp->len) << 2,
1617 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1618 len = min(len - delta, count);
1619 if (len < 0) {
1620 ret = -EFAULT;
1621 goto out;
1622 }
1623
1624 ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1625 *ppos += ret;
1626
1627out:
1628 iwl_free_resp(&hcmd);
1629 return ret;
1630}
1631
1632static ssize_t iwl_dbgfs_mem_write(struct file *file,
1633 const char __user *user_buf, size_t count,
1634 loff_t *ppos)
1635{
1636 struct iwl_mvm *mvm = file->private_data;
1637 struct iwl_dbg_mem_access_cmd *cmd;
1638 struct iwl_dbg_mem_access_rsp *rsp;
1639 struct iwl_host_cmd hcmd = {};
1640 size_t cmd_size;
1641 size_t data_size;
1642 u32 op, len;
1643 ssize_t ret;
1644
Johannes Berg504bd622017-03-22 22:19:41 +01001645 if (!iwl_mvm_firmware_running(mvm))
1646 return -EIO;
1647
Ido Yariv2b55f432016-08-23 14:44:59 -04001648 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1649 DEBUG_GROUP, 0);
1650
1651 if (*ppos & 0x3 || count < 4) {
1652 op = DEBUG_MEM_OP_WRITE_BYTES;
1653 len = min(count, (size_t)(4 - (*ppos & 0x3)));
1654 data_size = len;
1655 } else {
1656 op = DEBUG_MEM_OP_WRITE;
1657 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1658 data_size = len << 2;
1659 }
1660
1661 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1662 cmd = kzalloc(cmd_size, GFP_KERNEL);
1663 if (!cmd)
1664 return -ENOMEM;
1665
1666 cmd->op = cpu_to_le32(op);
1667 cmd->len = cpu_to_le32(len);
1668 cmd->addr = cpu_to_le32(*ppos);
1669 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1670 kfree(cmd);
1671 return -EFAULT;
1672 }
1673
1674 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1675 hcmd.data[0] = (void *)cmd;
1676 hcmd.len[0] = cmd_size;
1677
1678 mutex_lock(&mvm->mutex);
1679 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1680 mutex_unlock(&mvm->mutex);
1681
1682 kfree(cmd);
1683
1684 if (ret < 0)
1685 return ret;
1686
1687 rsp = (void *)hcmd.resp_pkt->data;
1688 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1689 ret = -ENXIO;
1690 goto out;
1691 }
1692
1693 ret = data_size;
1694 *ppos += ret;
1695
1696out:
1697 iwl_free_resp(&hcmd);
1698 return ret;
1699}
1700
1701static const struct file_operations iwl_dbgfs_mem_ops = {
1702 .read = iwl_dbgfs_mem_read,
1703 .write = iwl_dbgfs_mem_write,
1704 .open = simple_open,
1705 .llseek = default_llseek,
1706};
1707
Johannes Berg8ca151b2013-01-24 14:25:36 +01001708int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1709{
Eliad Pellerde06a592014-01-08 10:11:12 +02001710 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001711 char buf[100];
1712
Johannes Bergd07913a2014-02-26 11:25:58 +01001713 spin_lock_init(&mvm->drv_stats_lock);
1714
Johannes Berg8ca151b2013-01-24 14:25:36 +01001715 mvm->debugfs_dir = dbgfs_dir;
1716
1717 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1718 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1719 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001720 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1721 S_IWUSR | S_IRUSR);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001722 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001723 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1724 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001725 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001726 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001727 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach639eaba2014-03-30 10:11:13 +03001728 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1729 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001730 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001731 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001732 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001733 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001734 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001735 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001736 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1737 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001738 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001739 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001740 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1741 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001742 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001743 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001744 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
Sara Sharon43413a92015-12-31 11:49:18 +02001745 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
Sara Sharon4857d6c2016-08-09 20:03:52 +03001746 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
Luciano Coelhocb2513b2015-02-27 16:26:57 +02001747 if (!debugfs_create_bool("enable_scan_iteration_notif",
1748 S_IRUSR | S_IWUSR,
1749 mvm->debugfs_dir,
1750 &mvm->scan_iter_notif_enabled))
1751 goto err;
Andrei Otcheretianskic89e3332016-01-26 18:12:28 +02001752 if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
1753 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1754 goto err;
Eliad Pellerde06a592014-01-08 10:11:12 +02001755
1756#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1757 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1758 bcast_dir = debugfs_create_dir("bcast_filtering",
1759 mvm->debugfs_dir);
1760 if (!bcast_dir)
1761 goto err;
1762
1763 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1764 bcast_dir,
1765 &mvm->dbgfs_bcast_filtering.override))
1766 goto err;
1767
1768 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1769 bcast_dir, S_IWUSR | S_IRUSR);
1770 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1771 bcast_dir, S_IWUSR | S_IRUSR);
1772 }
1773#endif
1774
Johannes Bergafc66bb2013-05-03 11:44:16 +02001775#ifdef CONFIG_PM_SLEEP
1776 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001777 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001778 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1779 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1780 goto err;
Luciano Coelho484b3d12015-03-30 20:46:32 +03001781 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1782 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1783 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001784#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001785
Luciano Coelhobdd54832014-08-07 18:08:56 +03001786 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1787 mvm->debugfs_dir, &mvm->ps_disabled))
1788 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001789 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1790 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1791 goto err;
1792 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1793 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1794 goto err;
1795 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1796 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1797 goto err;
1798 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1799 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1800 goto err;
Moshe Harel91fac942015-09-02 12:45:12 +03001801 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1802 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1803 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001804
Ido Yariv2b55f432016-08-23 14:44:59 -04001805 debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
1806 &iwl_dbgfs_mem_ops);
1807
Johannes Berg8ca151b2013-01-24 14:25:36 +01001808 /*
1809 * Create a symlink with mac80211. It will be removed when mac80211
1810 * exists (before the opmode exists which removes the target.)
1811 */
Al Viro27a22092016-08-07 12:21:25 -04001812 snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001813 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1814 goto err;
1815
1816 return 0;
1817err:
1818 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1819 return -ENOMEM;
1820}