blob: 402846650cbec93a3a871f64381cde6b7021220d [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
Sara Sharon43413a92015-12-31 11:49:18 +020010 * Copyright(c) 2016 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 Berg8ca151b2013-01-24 14:25:36 +010037 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 *
43 * * Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * * Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in
47 * the documentation and/or other materials provided with the
48 * distribution.
49 * * Neither the name Intel Corporation nor the names of its
50 * contributors may be used to endorse or promote products derived
51 * from this software without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *
65 *****************************************************************************/
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020066#include <linux/vmalloc.h>
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +020067#include <linux/ieee80211.h>
Sara Sharon854d7732016-03-22 15:55:58 +020068#include <linux/netdevice.h>
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020069
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include "mvm.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020071#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010072#include "sta.h"
73#include "iwl-io.h"
Johannes Berg820a1a52013-11-12 16:58:41 +010074#include "debugfs.h"
Johannes Berg4d075002014-04-24 10:41:31 +020075#include "iwl-fw-error-dump.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010076
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +020077static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
78 char __user *user_buf,
79 size_t count, loff_t *ppos)
80{
81 struct iwl_mvm *mvm = file->private_data;
82 char buf[16];
83 int pos, budget;
84
85 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
86 return -EIO;
87
88 mutex_lock(&mvm->mutex);
89 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
90 mutex_unlock(&mvm->mutex);
91
92 if (budget < 0)
93 return budget;
94
95 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
96
97 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
98}
99
100static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
101 size_t count, loff_t *ppos)
102{
103 int ret;
104
105 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
106 return -EIO;
107
108 mutex_lock(&mvm->mutex);
109 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
110 mutex_unlock(&mvm->mutex);
111
112 return ret ?: count;
113}
114
Johannes Berg1fa3f572013-11-13 09:10:21 +0100115static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116 size_t count, loff_t *ppos)
117{
Johannes Berg8a0bd162013-11-12 16:48:03 +0100118 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119 u32 scd_q_msk;
120
121 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
122 return -EIO;
123
Johannes Berg8ca151b2013-01-24 14:25:36 +0100124 if (sscanf(buf, "%x", &scd_q_msk) != 1)
125 return -EINVAL;
126
127 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
128
129 mutex_lock(&mvm->mutex);
Luca Coelho5888a402015-10-06 09:54:57 +0300130 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100131 mutex_unlock(&mvm->mutex);
132
133 return ret;
134}
135
Johannes Berg1fa3f572013-11-13 09:10:21 +0100136static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100137 size_t count, loff_t *ppos)
138{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200139 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +0100140 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141
142 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
143 return -EIO;
144
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
146 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200147 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
148 return -EINVAL;
149 if (drain < 0 || drain > 1)
150 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100151
152 mutex_lock(&mvm->mutex);
153
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200154 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
155
156 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100157 ret = -ENOENT;
158 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200159 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160
161 mutex_unlock(&mvm->mutex);
162
163 return ret;
164}
165
166static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
167 size_t count, loff_t *ppos)
168{
169 struct iwl_mvm *mvm = file->private_data;
170 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200171 unsigned int ofs, len;
172 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100173 u8 *ptr;
174
Johannes Berg60191d92013-05-15 13:08:51 +0200175 if (!mvm->ucode_loaded)
176 return -EINVAL;
177
Johannes Berg8ca151b2013-01-24 14:25:36 +0100178 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200179 img = &mvm->fw->img[mvm->cur_ucode];
180 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
181 len = img->sec[IWL_UCODE_SECTION_DATA].len;
182
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200183 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200184 ofs = mvm->dbgfs_sram_offset;
185 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100186 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100187
Johannes Berg8ca151b2013-01-24 14:25:36 +0100188 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200189 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100190 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191
Johannes Berg60191d92013-05-15 13:08:51 +0200192 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100193
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200194 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100195
Johannes Berg8ca151b2013-01-24 14:25:36 +0100196 kfree(ptr);
197
198 return ret;
199}
200
Johannes Berg1fa3f572013-11-13 09:10:21 +0100201static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
202 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200204 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100205 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200206 u32 img_offset, img_len;
207
208 if (!mvm->ucode_loaded)
209 return -EINVAL;
210
211 img = &mvm->fw->img[mvm->cur_ucode];
212 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
213 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100214
Johannes Berg8ca151b2013-01-24 14:25:36 +0100215 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
216 if ((offset & 0x3) || (len & 0x3))
217 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200218
219 if (offset + len > img_offset + img_len)
220 return -EINVAL;
221
Johannes Berg8ca151b2013-01-24 14:25:36 +0100222 mvm->dbgfs_sram_offset = offset;
223 mvm->dbgfs_sram_len = len;
224 } else {
225 mvm->dbgfs_sram_offset = 0;
226 mvm->dbgfs_sram_len = 0;
227 }
228
229 return count;
230}
231
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300232static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
233 char __user *user_buf,
234 size_t count, loff_t *ppos)
235{
236 struct iwl_mvm *mvm = file->private_data;
237 char buf[16];
238 int pos;
239
240 if (!mvm->temperature_test)
241 pos = scnprintf(buf , sizeof(buf), "disabled\n");
242 else
243 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
244
245 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
246}
247
248/*
249 * Set NIC Temperature
250 * Cause the driver to ignore the actual NIC temperature reported by the FW
251 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
252 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
253 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
254 */
255static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
256 char *buf, size_t count,
257 loff_t *ppos)
258{
259 int temperature;
260
Luciano Coelhoa26d4e72014-08-20 10:21:07 +0300261 if (!mvm->ucode_loaded && !mvm->temperature_test)
262 return -EIO;
263
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300264 if (kstrtoint(buf, 10, &temperature))
265 return -EINVAL;
266 /* not a legal temperature */
267 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
268 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
269 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
270 return -EINVAL;
271
272 mutex_lock(&mvm->mutex);
273 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
Luciano Coelhob689fa72014-08-20 17:26:58 +0300274 if (!mvm->temperature_test)
275 goto out;
276
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300277 mvm->temperature_test = false;
Luciano Coelhob689fa72014-08-20 17:26:58 +0300278 /* Since we can't read the temp while awake, just set
279 * it to zero until we get the next RX stats from the
280 * firmware.
281 */
282 mvm->temperature = 0;
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300283 } else {
284 mvm->temperature_test = true;
285 mvm->temperature = temperature;
286 }
287 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
288 mvm->temperature_test ? "En" : "Dis" ,
289 mvm->temperature);
290 /* handle the temperature change */
291 iwl_mvm_tt_handler(mvm);
Luciano Coelhob689fa72014-08-20 17:26:58 +0300292
293out:
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300294 mutex_unlock(&mvm->mutex);
295
296 return count;
297}
298
Luciano Coelhoc549e392014-09-04 15:58:47 +0300299static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
300 char __user *user_buf,
301 size_t count, loff_t *ppos)
302{
303 struct iwl_mvm *mvm = file->private_data;
304 char buf[16];
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200305 int pos, ret;
306 s32 temp;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300307
308 if (!mvm->ucode_loaded)
309 return -EIO;
310
311 mutex_lock(&mvm->mutex);
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200312 ret = iwl_mvm_get_temp(mvm, &temp);
Luciano Coelhoc549e392014-09-04 15:58:47 +0300313 mutex_unlock(&mvm->mutex);
314
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200315 if (ret)
316 return -EIO;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300317
318 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
319
320 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
321}
322
Johannes Berg8ca151b2013-01-24 14:25:36 +0100323static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
324 size_t count, loff_t *ppos)
325{
326 struct iwl_mvm *mvm = file->private_data;
327 struct ieee80211_sta *sta;
328 char buf[400];
329 int i, pos = 0, bufsz = sizeof(buf);
330
331 mutex_lock(&mvm->mutex);
332
Sara Sharon0ae98812017-01-04 14:53:58 +0200333 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100334 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
335 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
336 lockdep_is_held(&mvm->mutex));
337 if (!sta)
338 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
339 else if (IS_ERR(sta))
340 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
341 PTR_ERR(sta));
342 else
343 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
344 sta->addr);
345 }
346
347 mutex_unlock(&mvm->mutex);
348
349 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
350}
351
Alexander Bondar64b928c2013-09-03 14:18:03 +0300352static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
353 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100354 size_t count, loff_t *ppos)
355{
356 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300357 char buf[64];
358 int bufsz = sizeof(buf);
359 int pos = 0;
360
361 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
362 mvm->disable_power_off);
363 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
364 mvm->disable_power_off_d3);
365
366 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
367}
368
Johannes Berg1fa3f572013-11-13 09:10:21 +0100369static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300370 size_t count, loff_t *ppos)
371{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100372 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100373
374 if (!mvm->ucode_loaded)
375 return -EIO;
376
Alexander Bondar64b928c2013-09-03 14:18:03 +0300377 if (!strncmp("disable_power_off_d0=", buf, 21)) {
378 if (sscanf(buf + 21, "%d", &val) != 1)
379 return -EINVAL;
380 mvm->disable_power_off = val;
381 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
382 if (sscanf(buf + 21, "%d", &val) != 1)
383 return -EINVAL;
384 mvm->disable_power_off_d3 = val;
385 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100386 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300387 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100388
Alexander Bondar64b928c2013-09-03 14:18:03 +0300389 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200390 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300391 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100392
Alexander Bondar64b928c2013-09-03 14:18:03 +0300393 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100394}
395
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200396#define BT_MBOX_MSG(_notif, _num, _field) \
397 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
398 >> BT_MBOX##_num##_##_field##_POS)
399
400
401#define BT_MBOX_PRINT(_num, _field, _end) \
402 pos += scnprintf(buf + pos, bufsz - pos, \
403 "\t%s: %d%s", \
404 #_field, \
405 BT_MBOX_MSG(notif, _num, _field), \
406 true ? "\n" : ", ");
407
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300408static
409int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
410 int pos, int bufsz)
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200411{
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200412 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
413
414 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
415 BT_MBOX_PRINT(0, LE_PROF1, false);
416 BT_MBOX_PRINT(0, LE_PROF2, false);
417 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
418 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
419 BT_MBOX_PRINT(0, INBAND_S, false);
420 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
421 BT_MBOX_PRINT(0, LE_SCAN, false);
422 BT_MBOX_PRINT(0, LE_ADV, false);
423 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
424 BT_MBOX_PRINT(0, OPEN_CON_1, true);
425
426 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
427
428 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
429 BT_MBOX_PRINT(1, IP_SR, false);
430 BT_MBOX_PRINT(1, LE_MSTR, false);
431 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
432 BT_MBOX_PRINT(1, MSG_TYPE, false);
433 BT_MBOX_PRINT(1, SSN, true);
434
435 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
436
437 BT_MBOX_PRINT(2, SNIFF_ACT, false);
438 BT_MBOX_PRINT(2, PAG, false);
439 BT_MBOX_PRINT(2, INQUIRY, false);
440 BT_MBOX_PRINT(2, CONN, false);
441 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
442 BT_MBOX_PRINT(2, DISC, false);
443 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
444 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
445 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
446 BT_MBOX_PRINT(2, SCO_DURATION, true);
447
448 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
449
450 BT_MBOX_PRINT(3, SCO_STATE, false);
451 BT_MBOX_PRINT(3, SNIFF_STATE, false);
452 BT_MBOX_PRINT(3, A2DP_STATE, false);
453 BT_MBOX_PRINT(3, ACL_STATE, false);
454 BT_MBOX_PRINT(3, MSTR_STATE, false);
455 BT_MBOX_PRINT(3, OBX_STATE, false);
456 BT_MBOX_PRINT(3, OPEN_CON_2, false);
457 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
458 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
459 BT_MBOX_PRINT(3, INBAND_P, false);
460 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
461 BT_MBOX_PRINT(3, SSN_2, false);
462 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
463
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300464 return pos;
465}
466
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300467static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
468 size_t count, loff_t *ppos)
469{
470 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200471 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300472 char *buf;
473 int ret, pos = 0, bufsz = sizeof(char) * 1024;
474
475 buf = kmalloc(bufsz, GFP_KERNEL);
476 if (!buf)
477 return -ENOMEM;
478
479 mutex_lock(&mvm->mutex);
480
Sara Sharon97f95c92016-03-07 16:55:20 +0200481 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300482
Sara Sharon97f95c92016-03-07 16:55:20 +0200483 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
484 notif->bt_ci_compliance);
485 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
486 le32_to_cpu(notif->primary_ch_lut));
487 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
488 le32_to_cpu(notif->secondary_ch_lut));
489 pos += scnprintf(buf + pos,
490 bufsz - pos, "bt_activity_grading = %d\n",
491 le32_to_cpu(notif->bt_activity_grading));
492 pos += scnprintf(buf + pos, bufsz - pos,
493 "antenna isolation = %d CORUN LUT index = %d\n",
494 mvm->last_ant_isol, mvm->last_corun_lut);
495 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
496 (notif->ttc_rrc_status >> 4) & 0xF);
497 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
498 notif->ttc_rrc_status & 0xF);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200499
Moshe Harelc725a462015-10-27 14:04:12 +0200500 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
501 IWL_MVM_BT_COEX_SYNC2SCO);
502 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
503 IWL_MVM_BT_COEX_MPLUT);
504 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
505 IWL_MVM_BT_COEX_CORUNNING);
506
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200507 mutex_unlock(&mvm->mutex);
508
509 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
510 kfree(buf);
511
512 return ret;
513}
514#undef BT_MBOX_PRINT
515
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300516static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
517 size_t count, loff_t *ppos)
518{
519 struct iwl_mvm *mvm = file->private_data;
Sara Sharon97f95c92016-03-07 16:55:20 +0200520 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300521 char buf[256];
522 int bufsz = sizeof(buf);
523 int pos = 0;
524
525 mutex_lock(&mvm->mutex);
526
Sara Sharon97f95c92016-03-07 16:55:20 +0200527 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
528 pos += scnprintf(buf + pos, bufsz - pos,
529 "\tPrimary Channel Bitmap 0x%016llx\n",
530 le64_to_cpu(cmd->bt_primary_ci));
531 pos += scnprintf(buf + pos, bufsz - pos,
532 "\tSecondary Channel Bitmap 0x%016llx\n",
533 le64_to_cpu(cmd->bt_secondary_ci));
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300534
535 mutex_unlock(&mvm->mutex);
536
537 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
538}
539
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200540static ssize_t
541iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
542 size_t count, loff_t *ppos)
543{
544 u32 bt_tx_prio;
545
546 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
547 return -EINVAL;
548 if (bt_tx_prio > 4)
549 return -EINVAL;
550
551 mvm->bt_tx_prio = bt_tx_prio;
552
553 return count;
554}
555
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300556static ssize_t
557iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
558 size_t count, loff_t *ppos)
559{
560 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
561 [BT_FORCE_ANT_DIS] = "dis",
562 [BT_FORCE_ANT_AUTO] = "auto",
563 [BT_FORCE_ANT_BT] = "bt",
564 [BT_FORCE_ANT_WIFI] = "wifi",
565 };
566 int ret, bt_force_ant_mode;
567
568 for (bt_force_ant_mode = 0;
569 bt_force_ant_mode < ARRAY_SIZE(modes_str);
570 bt_force_ant_mode++) {
571 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
572 break;
573 }
574
575 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
576 return -EINVAL;
577
578 ret = 0;
579 mutex_lock(&mvm->mutex);
580 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
581 goto out;
582
583 mvm->bt_force_ant_mode = bt_force_ant_mode;
584 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
585 modes_str[mvm->bt_force_ant_mode]);
586 ret = iwl_send_bt_init_conf(mvm);
587
588out:
589 mutex_unlock(&mvm->mutex);
590 return ret ?: count;
591}
592
Johannes Berg93d17cc2015-01-15 12:59:26 +0100593#define PRINT_STATS_LE32(_struct, _memb) \
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300594 pos += scnprintf(buf + pos, bufsz - pos, \
Johannes Berg93d17cc2015-01-15 12:59:26 +0100595 fmt_table, #_memb, \
596 le32_to_cpu(_struct->_memb))
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300597
598static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
599 char __user *user_buf, size_t count,
600 loff_t *ppos)
601{
602 struct iwl_mvm *mvm = file->private_data;
603 static const char *fmt_table = "\t%-30s %10u\n";
604 static const char *fmt_header = "%-32s\n";
605 int pos = 0;
606 char *buf;
607 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300608 /* 43 is the size of each data line, 33 is the size of each header */
609 size_t bufsz =
610 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
611 (4 * 33) + 1;
612
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300613 struct mvm_statistics_rx_phy *ofdm;
614 struct mvm_statistics_rx_phy *cck;
615 struct mvm_statistics_rx_non_phy *general;
616 struct mvm_statistics_rx_ht_phy *ht;
617
618 buf = kzalloc(bufsz, GFP_KERNEL);
619 if (!buf)
620 return -ENOMEM;
621
622 mutex_lock(&mvm->mutex);
623
624 ofdm = &mvm->rx_stats.ofdm;
625 cck = &mvm->rx_stats.cck;
626 general = &mvm->rx_stats.general;
627 ht = &mvm->rx_stats.ofdm_ht;
628
629 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
630 "Statistics_Rx - OFDM");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100631 PRINT_STATS_LE32(ofdm, ina_cnt);
632 PRINT_STATS_LE32(ofdm, fina_cnt);
633 PRINT_STATS_LE32(ofdm, plcp_err);
634 PRINT_STATS_LE32(ofdm, crc32_err);
635 PRINT_STATS_LE32(ofdm, overrun_err);
636 PRINT_STATS_LE32(ofdm, early_overrun_err);
637 PRINT_STATS_LE32(ofdm, crc32_good);
638 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
639 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
640 PRINT_STATS_LE32(ofdm, sfd_timeout);
641 PRINT_STATS_LE32(ofdm, fina_timeout);
642 PRINT_STATS_LE32(ofdm, unresponded_rts);
643 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
644 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
645 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
646 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
647 PRINT_STATS_LE32(ofdm, dsp_self_kill);
648 PRINT_STATS_LE32(ofdm, mh_format_err);
649 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
650 PRINT_STATS_LE32(ofdm, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300651
652 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
653 "Statistics_Rx - CCK");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100654 PRINT_STATS_LE32(cck, ina_cnt);
655 PRINT_STATS_LE32(cck, fina_cnt);
656 PRINT_STATS_LE32(cck, plcp_err);
657 PRINT_STATS_LE32(cck, crc32_err);
658 PRINT_STATS_LE32(cck, overrun_err);
659 PRINT_STATS_LE32(cck, early_overrun_err);
660 PRINT_STATS_LE32(cck, crc32_good);
661 PRINT_STATS_LE32(cck, false_alarm_cnt);
662 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
663 PRINT_STATS_LE32(cck, sfd_timeout);
664 PRINT_STATS_LE32(cck, fina_timeout);
665 PRINT_STATS_LE32(cck, unresponded_rts);
666 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
667 PRINT_STATS_LE32(cck, sent_ack_cnt);
668 PRINT_STATS_LE32(cck, sent_cts_cnt);
669 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
670 PRINT_STATS_LE32(cck, dsp_self_kill);
671 PRINT_STATS_LE32(cck, mh_format_err);
672 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
673 PRINT_STATS_LE32(cck, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300674
675 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
676 "Statistics_Rx - GENERAL");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100677 PRINT_STATS_LE32(general, bogus_cts);
678 PRINT_STATS_LE32(general, bogus_ack);
679 PRINT_STATS_LE32(general, non_bssid_frames);
680 PRINT_STATS_LE32(general, filtered_frames);
681 PRINT_STATS_LE32(general, non_channel_beacons);
682 PRINT_STATS_LE32(general, channel_beacons);
683 PRINT_STATS_LE32(general, num_missed_bcon);
684 PRINT_STATS_LE32(general, adc_rx_saturation_time);
685 PRINT_STATS_LE32(general, ina_detection_search_time);
686 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
687 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
688 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
689 PRINT_STATS_LE32(general, interference_data_flag);
690 PRINT_STATS_LE32(general, channel_load);
691 PRINT_STATS_LE32(general, dsp_false_alarms);
692 PRINT_STATS_LE32(general, beacon_rssi_a);
693 PRINT_STATS_LE32(general, beacon_rssi_b);
694 PRINT_STATS_LE32(general, beacon_rssi_c);
695 PRINT_STATS_LE32(general, beacon_energy_a);
696 PRINT_STATS_LE32(general, beacon_energy_b);
697 PRINT_STATS_LE32(general, beacon_energy_c);
698 PRINT_STATS_LE32(general, num_bt_kills);
699 PRINT_STATS_LE32(general, mac_id);
700 PRINT_STATS_LE32(general, directed_data_mpdu);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300701
702 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
703 "Statistics_Rx - HT");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100704 PRINT_STATS_LE32(ht, plcp_err);
705 PRINT_STATS_LE32(ht, overrun_err);
706 PRINT_STATS_LE32(ht, early_overrun_err);
707 PRINT_STATS_LE32(ht, crc32_good);
708 PRINT_STATS_LE32(ht, crc32_err);
709 PRINT_STATS_LE32(ht, mh_format_err);
710 PRINT_STATS_LE32(ht, agg_crc32_good);
711 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
712 PRINT_STATS_LE32(ht, agg_cnt);
713 PRINT_STATS_LE32(ht, unsupport_mcs);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300714
715 mutex_unlock(&mvm->mutex);
716
717 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
718 kfree(buf);
719
720 return ret;
721}
722#undef PRINT_STAT_LE32
723
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200724static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
725 char __user *user_buf, size_t count,
726 loff_t *ppos,
727 struct iwl_mvm_frame_stats *stats)
728{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200729 char *buff, *pos, *endpos;
730 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200731 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200732 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200733
734 buff = kmalloc(bufsz, GFP_KERNEL);
735 if (!buff)
736 return -ENOMEM;
737
738 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200739
740 pos = buff;
741 endpos = pos + bufsz;
742
743 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200744 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
745 stats->legacy_frames,
746 stats->ht_frames,
747 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200748 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200749 stats->bw_20_frames,
750 stats->bw_40_frames,
751 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200752 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200753 stats->ngi_frames,
754 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200755 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200756 stats->siso_frames,
757 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200758 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200759 stats->fail_frames,
760 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200761 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200762 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200763 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200764 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200765 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200766 stats->ampdu_count > 0 ?
767 (stats->agg_frames / stats->ampdu_count) : 0);
768
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200769 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200770
771 idx = stats->last_frame_idx - 1;
772 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
773 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
774 if (stats->last_rates[idx] == 0)
775 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200776 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200777 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200778 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200779 }
780 spin_unlock_bh(&mvm->drv_stats_lock);
781
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200782 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200783 kfree(buff);
784
785 return ret;
786}
787
788static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
789 char __user *user_buf, size_t count,
790 loff_t *ppos)
791{
792 struct iwl_mvm *mvm = file->private_data;
793
794 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
795 &mvm->drv_rx_stats);
796}
797
Johannes Berg1fa3f572013-11-13 09:10:21 +0100798static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200799 size_t count, loff_t *ppos)
800{
Luca Coelho758d1a82016-11-09 10:02:46 +0200801 int __maybe_unused ret;
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200802
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200803 mutex_lock(&mvm->mutex);
804
Eran Harary291aa7c2013-07-03 11:00:06 +0300805 /* allow one more restart that we're provoking here */
806 if (mvm->restart_fw >= 0)
807 mvm->restart_fw++;
808
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200809 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300810 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200811
812 mutex_unlock(&mvm->mutex);
813
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200814 return count;
815}
816
Johannes Berg1fa3f572013-11-13 09:10:21 +0100817static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200818 size_t count, loff_t *ppos)
819{
Eliad Peller576eeee2014-07-01 18:38:38 +0300820 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
821 if (ret)
822 return ret;
823
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300824 iwl_force_nmi(mvm->trans);
Alexander Bondar119663c2013-10-17 14:26:50 +0200825
Eliad Peller576eeee2014-07-01 18:38:38 +0300826 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
827
Alexander Bondar119663c2013-10-17 14:26:50 +0200828 return count;
829}
830
Oren Givon91b05d12013-08-19 08:36:48 +0300831static ssize_t
832iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
833 char __user *user_buf,
834 size_t count, loff_t *ppos)
835{
836 struct iwl_mvm *mvm = file->private_data;
837 int pos = 0;
838 char buf[32];
839 const size_t bufsz = sizeof(buf);
840
841 /* print which antennas were set for the scan command by the user */
842 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
843 if (mvm->scan_rx_ant & ANT_A)
844 pos += scnprintf(buf + pos, bufsz - pos, "A");
845 if (mvm->scan_rx_ant & ANT_B)
846 pos += scnprintf(buf + pos, bufsz - pos, "B");
847 if (mvm->scan_rx_ant & ANT_C)
848 pos += scnprintf(buf + pos, bufsz - pos, "C");
849 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
850
851 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
852}
853
854static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100855iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300856 size_t count, loff_t *ppos)
857{
Oren Givon91b05d12013-08-19 08:36:48 +0300858 u8 scan_rx_ant;
859
Oren Givon91b05d12013-08-19 08:36:48 +0300860 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
861 return -EINVAL;
862 if (scan_rx_ant > ANT_ABC)
863 return -EINVAL;
Moshe Harela0544272014-12-08 21:13:14 +0200864 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
Oren Givon91b05d12013-08-19 08:36:48 +0300865 return -EINVAL;
866
David Spinadeld2496222014-05-20 12:46:37 +0300867 if (mvm->scan_rx_ant != scan_rx_ant) {
868 mvm->scan_rx_ant = scan_rx_ant;
Johannes Berg859d9142015-06-01 17:11:11 +0200869 if (fw_has_capa(&mvm->fw->ucode_capa,
870 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
David Spinadeld2496222014-05-20 12:46:37 +0300871 iwl_mvm_config_scan(mvm);
872 }
Oren Givon91b05d12013-08-19 08:36:48 +0300873
874 return count;
875}
876
Sara Sharon43413a92015-12-31 11:49:18 +0200877static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
878 char *buf, size_t count,
879 loff_t *ppos)
880{
881 struct iwl_rss_config_cmd cmd = {
882 .flags = cpu_to_le32(IWL_RSS_ENABLE),
883 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200884 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200885 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
886 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200887 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200888 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
889 };
890 int ret, i, num_repeats, nbytes = count / 2;
891
892 ret = hex2bin(cmd.indirection_table, buf, nbytes);
893 if (ret)
894 return ret;
895
896 /*
897 * The input is the redirection table, partial or full.
898 * Repeat the pattern if needed.
899 * For example, input of 01020F will be repeated 42 times,
900 * indirecting RSS hash results to queues 1, 2, 15 (skipping
901 * queues 3 - 14).
902 */
903 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
904 for (i = 1; i < num_repeats; i++)
905 memcpy(&cmd.indirection_table[i * nbytes],
906 cmd.indirection_table, nbytes);
907 /* handle cut in the middle pattern for the last places */
908 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
909 ARRAY_SIZE(cmd.indirection_table) % nbytes);
910
Sara Sharon854d7732016-03-22 15:55:58 +0200911 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200912
913 mutex_lock(&mvm->mutex);
914 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
915 mutex_unlock(&mvm->mutex);
916
917 return ret ?: count;
918}
919
Sara Sharon4857d6c2016-08-09 20:03:52 +0300920static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
921 char *buf, size_t count,
922 loff_t *ppos)
923{
924 struct iwl_rx_cmd_buffer rxb = {
925 ._rx_page_order = 0,
926 .truesize = 0, /* not used */
927 ._offset = 0,
928 };
929 struct iwl_rx_packet *pkt;
930 struct iwl_rx_mpdu_desc *desc;
931 int bin_len = count / 2;
932 int ret = -EINVAL;
933
934 /* supporting only 9000 descriptor */
935 if (!mvm->trans->cfg->mq_rx_supported)
936 return -ENOTSUPP;
937
938 rxb._page = alloc_pages(GFP_ATOMIC, 0);
939 if (!rxb._page)
940 return -ENOMEM;
941 pkt = rxb_addr(&rxb);
942
943 ret = hex2bin(page_address(rxb._page), buf, bin_len);
944 if (ret)
945 goto out;
946
947 /* avoid invalid memory access */
948 if (bin_len < sizeof(*pkt) + sizeof(*desc))
949 goto out;
950
951 /* check this is RX packet */
952 if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
953 WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
954 goto out;
955
956 /* check the length in metadata matches actual received length */
957 desc = (void *)pkt->data;
958 if (le16_to_cpu(desc->mpdu_len) !=
959 (bin_len - sizeof(*desc) - sizeof(*pkt)))
960 goto out;
961
962 local_bh_disable();
963 iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
964 local_bh_enable();
965 ret = 0;
966
967out:
968 iwl_free_rxb(&rxb);
969
970 return ret ?: count;
971}
972
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200973static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
974 char __user *user_buf,
975 size_t count, loff_t *ppos)
976{
977 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +0200978 int conf;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200979 char buf[8];
980 const size_t bufsz = sizeof(buf);
981 int pos = 0;
982
983 mutex_lock(&mvm->mutex);
984 conf = mvm->fw_dbg_conf;
985 mutex_unlock(&mvm->mutex);
986
987 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
988
989 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
990}
991
Golan Ben Ami321c2102015-07-27 17:02:35 +0300992/*
993 * Enable / Disable continuous recording.
994 * Cause the FW to start continuous recording, by sending the relevant hcmd.
995 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
996 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
997 */
998static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
999 char *buf, size_t count,
1000 loff_t *ppos)
1001{
1002 struct iwl_trans *trans = mvm->trans;
1003 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
1004 struct iwl_continuous_record_cmd cont_rec = {};
1005 int ret, rec_mode;
1006
1007 if (!dest)
1008 return -EOPNOTSUPP;
1009
1010 if (dest->monitor_mode != SMEM_MODE ||
1011 trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
1012 return -EOPNOTSUPP;
1013
Johannes Berg27e070d2016-01-14 10:55:22 +01001014 ret = kstrtoint(buf, 0, &rec_mode);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001015 if (ret)
1016 return ret;
1017
1018 cont_rec.record_mode.enable_recording = rec_mode ?
1019 cpu_to_le16(ENABLE_CONT_RECORDING) :
1020 cpu_to_le16(DISABLE_CONT_RECORDING);
1021
1022 mutex_lock(&mvm->mutex);
1023 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1024 sizeof(cont_rec), &cont_rec);
1025 mutex_unlock(&mvm->mutex);
1026
1027 return ret ?: count;
1028}
1029
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001030static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1031 char *buf, size_t count,
1032 loff_t *ppos)
1033{
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001034 unsigned int conf_id;
1035 int ret;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001036
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001037 ret = kstrtouint(buf, 0, &conf_id);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001038 if (ret)
1039 return ret;
1040
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001041 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001042 return -EINVAL;
1043
1044 mutex_lock(&mvm->mutex);
1045 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1046 mutex_unlock(&mvm->mutex);
1047
1048 return ret ?: count;
1049}
1050
1051static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1052 char *buf, size_t count,
1053 loff_t *ppos)
1054{
Liad Kaufmane93475a2015-01-04 11:03:13 +02001055 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1056
1057 if (ret)
1058 return ret;
Dan Carpenter251fe092017-03-23 13:40:00 +03001059 if (count == 0)
1060 return 0;
Liad Kaufmane93475a2015-01-04 11:03:13 +02001061
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001062 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1063 (count - 1), NULL);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001064
1065 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001066
1067 return count;
1068}
1069
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001070static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1071 char *buf, size_t count,
1072 loff_t *ppos)
1073{
1074 unsigned int max_amsdu_len;
1075 int ret;
1076
1077 ret = kstrtouint(buf, 0, &max_amsdu_len);
Dan Carpenter32afd152016-05-04 09:19:54 +03001078 if (ret)
1079 return ret;
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001080
1081 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1082 return -EINVAL;
1083 mvm->max_amsdu_len = max_amsdu_len;
1084
1085 return count;
1086}
1087
Eliad Pellerde06a592014-01-08 10:11:12 +02001088#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1089#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1090static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1091 char __user *user_buf,
1092 size_t count, loff_t *ppos)
1093{
1094 struct iwl_mvm *mvm = file->private_data;
1095 struct iwl_bcast_filter_cmd cmd;
1096 const struct iwl_fw_bcast_filter *filter;
1097 char *buf;
1098 int bufsz = 1024;
1099 int i, j, pos = 0;
1100 ssize_t ret;
1101
1102 buf = kzalloc(bufsz, GFP_KERNEL);
1103 if (!buf)
1104 return -ENOMEM;
1105
1106 mutex_lock(&mvm->mutex);
1107 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1108 ADD_TEXT("None\n");
1109 mutex_unlock(&mvm->mutex);
1110 goto out;
1111 }
1112 mutex_unlock(&mvm->mutex);
1113
1114 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1115 filter = &cmd.filters[i];
1116
1117 ADD_TEXT("Filter [%d]:\n", i);
1118 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1119 ADD_TEXT("\tFrame Type: %s\n",
1120 filter->frame_type ? "IPv4" : "Generic");
1121
1122 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1123 const struct iwl_fw_bcast_filter_attr *attr;
1124
1125 attr = &filter->attrs[j];
1126 if (!attr->mask)
1127 break;
1128
1129 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1130 j, attr->offset,
1131 attr->offset_type ? "IP End" :
1132 "Payload Start",
1133 be32_to_cpu(attr->mask),
1134 be32_to_cpu(attr->val),
1135 le16_to_cpu(attr->reserved1));
1136 }
1137 }
1138out:
1139 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1140 kfree(buf);
1141 return ret;
1142}
1143
1144static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1145 size_t count, loff_t *ppos)
1146{
1147 int pos, next_pos;
1148 struct iwl_fw_bcast_filter filter = {};
1149 struct iwl_bcast_filter_cmd cmd;
1150 u32 filter_id, attr_id, mask, value;
1151 int err = 0;
1152
1153 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1154 &filter.frame_type, &pos) != 3)
1155 return -EINVAL;
1156
1157 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1158 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1159 return -EINVAL;
1160
1161 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1162 attr_id++) {
1163 struct iwl_fw_bcast_filter_attr *attr =
1164 &filter.attrs[attr_id];
1165
1166 if (pos >= count)
1167 break;
1168
1169 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1170 &attr->offset, &attr->offset_type,
1171 &mask, &value, &next_pos) != 4)
1172 return -EINVAL;
1173
1174 attr->mask = cpu_to_be32(mask);
1175 attr->val = cpu_to_be32(value);
1176 if (mask)
1177 filter.num_attrs++;
1178
1179 pos += next_pos;
1180 }
1181
1182 mutex_lock(&mvm->mutex);
1183 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1184 &filter, sizeof(filter));
1185
1186 /* send updated bcast filtering configuration */
1187 if (mvm->dbgfs_bcast_filtering.override &&
1188 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001189 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001190 sizeof(cmd), &cmd);
1191 mutex_unlock(&mvm->mutex);
1192
1193 return err ?: count;
1194}
1195
1196static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1197 char __user *user_buf,
1198 size_t count, loff_t *ppos)
1199{
1200 struct iwl_mvm *mvm = file->private_data;
1201 struct iwl_bcast_filter_cmd cmd;
1202 char *buf;
1203 int bufsz = 1024;
1204 int i, pos = 0;
1205 ssize_t ret;
1206
1207 buf = kzalloc(bufsz, GFP_KERNEL);
1208 if (!buf)
1209 return -ENOMEM;
1210
1211 mutex_lock(&mvm->mutex);
1212 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1213 ADD_TEXT("None\n");
1214 mutex_unlock(&mvm->mutex);
1215 goto out;
1216 }
1217 mutex_unlock(&mvm->mutex);
1218
1219 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1220 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1221
1222 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1223 i, mac->default_discard, mac->attached_filters);
1224 }
1225out:
1226 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1227 kfree(buf);
1228 return ret;
1229}
1230
1231static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1232 char *buf, size_t count,
1233 loff_t *ppos)
1234{
1235 struct iwl_bcast_filter_cmd cmd;
1236 struct iwl_fw_bcast_mac mac = {};
1237 u32 mac_id, attached_filters;
1238 int err = 0;
1239
1240 if (!mvm->bcast_filters)
1241 return -ENOENT;
1242
1243 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1244 &attached_filters) != 3)
1245 return -EINVAL;
1246
1247 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1248 mac.default_discard > 1 ||
1249 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1250 return -EINVAL;
1251
1252 mac.attached_filters = cpu_to_le16(attached_filters);
1253
1254 mutex_lock(&mvm->mutex);
1255 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1256 &mac, sizeof(mac));
1257
1258 /* send updated bcast filtering configuration */
1259 if (mvm->dbgfs_bcast_filtering.override &&
1260 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001261 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001262 sizeof(cmd), &cmd);
1263 mutex_unlock(&mvm->mutex);
1264
1265 return err ?: count;
1266}
1267#endif
1268
Johannes Bergafc66bb2013-05-03 11:44:16 +02001269#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001270static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +02001271 size_t count, loff_t *ppos)
1272{
Johannes Bergafc66bb2013-05-03 11:44:16 +02001273 int store;
1274
Johannes Bergafc66bb2013-05-03 11:44:16 +02001275 if (sscanf(buf, "%d", &store) != 1)
1276 return -EINVAL;
1277
1278 mvm->store_d3_resume_sram = store;
1279
1280 return count;
1281}
1282
1283static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1284 size_t count, loff_t *ppos)
1285{
1286 struct iwl_mvm *mvm = file->private_data;
1287 const struct fw_img *img;
1288 int ofs, len, pos = 0;
1289 size_t bufsz, ret;
1290 char *buf;
1291 u8 *ptr = mvm->d3_resume_sram;
1292
1293 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1294 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1295
1296 bufsz = len * 4 + 256;
1297 buf = kzalloc(bufsz, GFP_KERNEL);
1298 if (!buf)
1299 return -ENOMEM;
1300
1301 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1302 mvm->store_d3_resume_sram ? "en" : "dis");
1303
1304 if (ptr) {
1305 for (ofs = 0; ofs < len; ofs += 16) {
1306 pos += scnprintf(buf + pos, bufsz - pos,
Andy Shevchenko3cd6e2f2015-07-16 15:42:14 +03001307 "0x%.4x %16ph\n", ofs, ptr + ofs);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001308 }
1309 } else {
1310 pos += scnprintf(buf + pos, bufsz - pos,
1311 "(no data captured)\n");
1312 }
1313
1314 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1315
1316 kfree(buf);
1317
1318 return ret;
1319}
1320#endif
1321
Eliad Peller576eeee2014-07-01 18:38:38 +03001322#define PRINT_MVM_REF(ref) do { \
1323 if (mvm->refs[ref]) \
1324 pos += scnprintf(buf + pos, bufsz - pos, \
1325 "\t(0x%lx): %d %s\n", \
1326 BIT(ref), mvm->refs[ref], #ref); \
Eliad Peller70d6bab2013-11-05 14:45:16 +02001327} while (0)
1328
1329static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1330 char __user *user_buf,
1331 size_t count, loff_t *ppos)
1332{
1333 struct iwl_mvm *mvm = file->private_data;
Eliad Peller576eeee2014-07-01 18:38:38 +03001334 int i, pos = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001335 char buf[256];
1336 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001337 u32 refs = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001338
Eliad Peller576eeee2014-07-01 18:38:38 +03001339 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1340 if (mvm->refs[i])
1341 refs |= BIT(i);
1342
1343 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1344 refs);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001345
1346 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1347 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1348 PRINT_MVM_REF(IWL_MVM_REF_ROC);
Eliad Pellerc7792732015-04-19 11:41:04 +03001349 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001350 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1351 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +02001352 PRINT_MVM_REF(IWL_MVM_REF_USER);
Johannes Berg34e611e2014-09-12 10:28:01 +02001353 PRINT_MVM_REF(IWL_MVM_REF_TX);
1354 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1355 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1356 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1357 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1358 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1359 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1360 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1361 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1362 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1363 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1364 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
Eliad Pellerd15a7472014-03-27 18:53:12 +02001365 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
Eliad Peller160acc02014-11-25 12:34:45 +02001366 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
Liad Kaufmanfb2380a2015-01-01 17:42:46 +02001367 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
Eliad Peller08f0d232015-12-10 15:47:11 +02001368 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
Luca Coelho71b12302016-03-11 12:12:16 +02001369 PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
Luca Coelho16e4dd82016-03-30 15:05:56 +03001370 PRINT_MVM_REF(IWL_MVM_REF_RX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001371
1372 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1373}
1374
Eliad Peller0eb83652013-11-11 18:56:35 +02001375static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1376 size_t count, loff_t *ppos)
1377{
1378 unsigned long value;
1379 int ret;
1380 bool taken;
1381
1382 ret = kstrtoul(buf, 10, &value);
1383 if (ret < 0)
1384 return ret;
1385
1386 mutex_lock(&mvm->mutex);
1387
Eliad Peller576eeee2014-07-01 18:38:38 +03001388 taken = mvm->refs[IWL_MVM_REF_USER];
Eliad Peller0eb83652013-11-11 18:56:35 +02001389 if (value == 1 && !taken)
1390 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1391 else if (value == 0 && taken)
1392 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1393 else
1394 ret = -EINVAL;
1395
1396 mutex_unlock(&mvm->mutex);
1397
1398 if (ret < 0)
1399 return ret;
1400 return count;
1401}
1402
Johannes Berg1fa3f572013-11-13 09:10:21 +01001403#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1404 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1405#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1406 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001407#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1408 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001409 &iwl_dbgfs_##name##_ops)) \
1410 goto err; \
1411 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +02001412#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1413 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001414
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001415static ssize_t
1416iwl_dbgfs_prph_reg_read(struct file *file,
1417 char __user *user_buf,
1418 size_t count, loff_t *ppos)
1419{
1420 struct iwl_mvm *mvm = file->private_data;
1421 int pos = 0;
1422 char buf[32];
1423 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001424 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001425
1426 if (!mvm->dbgfs_prph_reg_addr)
1427 return -EINVAL;
1428
Eliad Peller576eeee2014-07-01 18:38:38 +03001429 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1430 if (ret)
1431 return ret;
1432
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001433 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1434 mvm->dbgfs_prph_reg_addr,
1435 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1436
Eliad Peller576eeee2014-07-01 18:38:38 +03001437 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1438
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001439 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1440}
1441
1442static ssize_t
1443iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1444 size_t count, loff_t *ppos)
1445{
1446 u8 args;
1447 u32 value;
Eliad Peller576eeee2014-07-01 18:38:38 +03001448 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001449
1450 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1451 /* if we only want to set the reg address - nothing more to do */
1452 if (args == 1)
1453 goto out;
1454
1455 /* otherwise, make sure we have both address and value */
1456 if (args != 2)
1457 return -EINVAL;
1458
Eliad Peller576eeee2014-07-01 18:38:38 +03001459 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1460 if (ret)
1461 return ret;
1462
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001463 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
Eliad Peller576eeee2014-07-01 18:38:38 +03001464
1465 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001466out:
1467 return count;
1468}
1469
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001470static ssize_t
1471iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1472 size_t count, loff_t *ppos)
1473{
1474 int ret;
1475
1476 mutex_lock(&mvm->mutex);
1477 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1478 mutex_unlock(&mvm->mutex);
1479
1480 return ret ?: count;
1481}
1482
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001483MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1484
Johannes Berg8ca151b2013-01-24 14:25:36 +01001485/* Device wide debugfs entries */
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001486MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1487MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001488MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1489MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001490MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001491MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001492MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001493MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001494MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001495MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001496MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001497MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001498MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001499MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001500MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1501MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001502MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001503MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001504MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001505MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001506MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001507MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001508MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001509MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
Sara Sharondd4d3162016-02-07 12:50:35 +02001510MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1511 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
Sara Sharon4857d6c2016-08-09 20:03:52 +03001512MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
Oren Givon91b05d12013-08-19 08:36:48 +03001513
Eliad Pellerde06a592014-01-08 10:11:12 +02001514#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1515MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1516MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1517#endif
1518
Johannes Bergafc66bb2013-05-03 11:44:16 +02001519#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001520MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001521#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001522
Ido Yariv2b55f432016-08-23 14:44:59 -04001523static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1524 size_t count, loff_t *ppos)
1525{
1526 struct iwl_mvm *mvm = file->private_data;
1527 struct iwl_dbg_mem_access_cmd cmd = {};
1528 struct iwl_dbg_mem_access_rsp *rsp;
1529 struct iwl_host_cmd hcmd = {
1530 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1531 .data = { &cmd, },
1532 .len = { sizeof(cmd) },
1533 };
Luca Coelho276c4b42016-09-28 11:32:35 +03001534 size_t delta;
1535 ssize_t ret, len;
Ido Yariv2b55f432016-08-23 14:44:59 -04001536
1537 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1538 DEBUG_GROUP, 0);
1539 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1540
1541 /* Take care of alignment of both the position and the length */
1542 delta = *ppos & 0x3;
1543 cmd.addr = cpu_to_le32(*ppos - delta);
1544 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1545 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1546
1547 mutex_lock(&mvm->mutex);
1548 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1549 mutex_unlock(&mvm->mutex);
1550
1551 if (ret < 0)
1552 return ret;
1553
1554 rsp = (void *)hcmd.resp_pkt->data;
1555 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1556 ret = -ENXIO;
1557 goto out;
1558 }
1559
1560 len = min((size_t)le32_to_cpu(rsp->len) << 2,
1561 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1562 len = min(len - delta, count);
1563 if (len < 0) {
1564 ret = -EFAULT;
1565 goto out;
1566 }
1567
1568 ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1569 *ppos += ret;
1570
1571out:
1572 iwl_free_resp(&hcmd);
1573 return ret;
1574}
1575
1576static ssize_t iwl_dbgfs_mem_write(struct file *file,
1577 const char __user *user_buf, size_t count,
1578 loff_t *ppos)
1579{
1580 struct iwl_mvm *mvm = file->private_data;
1581 struct iwl_dbg_mem_access_cmd *cmd;
1582 struct iwl_dbg_mem_access_rsp *rsp;
1583 struct iwl_host_cmd hcmd = {};
1584 size_t cmd_size;
1585 size_t data_size;
1586 u32 op, len;
1587 ssize_t ret;
1588
1589 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1590 DEBUG_GROUP, 0);
1591
1592 if (*ppos & 0x3 || count < 4) {
1593 op = DEBUG_MEM_OP_WRITE_BYTES;
1594 len = min(count, (size_t)(4 - (*ppos & 0x3)));
1595 data_size = len;
1596 } else {
1597 op = DEBUG_MEM_OP_WRITE;
1598 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1599 data_size = len << 2;
1600 }
1601
1602 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1603 cmd = kzalloc(cmd_size, GFP_KERNEL);
1604 if (!cmd)
1605 return -ENOMEM;
1606
1607 cmd->op = cpu_to_le32(op);
1608 cmd->len = cpu_to_le32(len);
1609 cmd->addr = cpu_to_le32(*ppos);
1610 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1611 kfree(cmd);
1612 return -EFAULT;
1613 }
1614
1615 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1616 hcmd.data[0] = (void *)cmd;
1617 hcmd.len[0] = cmd_size;
1618
1619 mutex_lock(&mvm->mutex);
1620 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1621 mutex_unlock(&mvm->mutex);
1622
1623 kfree(cmd);
1624
1625 if (ret < 0)
1626 return ret;
1627
1628 rsp = (void *)hcmd.resp_pkt->data;
1629 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1630 ret = -ENXIO;
1631 goto out;
1632 }
1633
1634 ret = data_size;
1635 *ppos += ret;
1636
1637out:
1638 iwl_free_resp(&hcmd);
1639 return ret;
1640}
1641
1642static const struct file_operations iwl_dbgfs_mem_ops = {
1643 .read = iwl_dbgfs_mem_read,
1644 .write = iwl_dbgfs_mem_write,
1645 .open = simple_open,
1646 .llseek = default_llseek,
1647};
1648
Johannes Berg8ca151b2013-01-24 14:25:36 +01001649int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1650{
Eliad Pellerde06a592014-01-08 10:11:12 +02001651 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001652 char buf[100];
1653
Johannes Bergd07913a2014-02-26 11:25:58 +01001654 spin_lock_init(&mvm->drv_stats_lock);
1655
Johannes Berg8ca151b2013-01-24 14:25:36 +01001656 mvm->debugfs_dir = dbgfs_dir;
1657
1658 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1659 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1660 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001661 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1662 S_IWUSR | S_IRUSR);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001663 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
Chaya Rachel Ivgi00f481b2016-02-24 12:19:22 +02001664 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1665 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001666 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001667 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001668 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach639eaba2014-03-30 10:11:13 +03001669 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1670 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001671 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001672 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001673 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001674 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001675 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001676 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001677 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1678 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001679 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001680 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001681 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1682 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbach9e7dce22015-10-26 16:14:06 +02001683 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001684 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001685 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
Sara Sharon43413a92015-12-31 11:49:18 +02001686 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
Sara Sharon4857d6c2016-08-09 20:03:52 +03001687 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
Luciano Coelhocb2513b2015-02-27 16:26:57 +02001688 if (!debugfs_create_bool("enable_scan_iteration_notif",
1689 S_IRUSR | S_IWUSR,
1690 mvm->debugfs_dir,
1691 &mvm->scan_iter_notif_enabled))
1692 goto err;
Andrei Otcheretianskic89e3332016-01-26 18:12:28 +02001693 if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
1694 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1695 goto err;
Eliad Pellerde06a592014-01-08 10:11:12 +02001696
1697#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1698 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1699 bcast_dir = debugfs_create_dir("bcast_filtering",
1700 mvm->debugfs_dir);
1701 if (!bcast_dir)
1702 goto err;
1703
1704 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1705 bcast_dir,
1706 &mvm->dbgfs_bcast_filtering.override))
1707 goto err;
1708
1709 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1710 bcast_dir, S_IWUSR | S_IRUSR);
1711 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1712 bcast_dir, S_IWUSR | S_IRUSR);
1713 }
1714#endif
1715
Johannes Bergafc66bb2013-05-03 11:44:16 +02001716#ifdef CONFIG_PM_SLEEP
1717 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001718 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001719 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1720 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1721 goto err;
Luciano Coelho484b3d12015-03-30 20:46:32 +03001722 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1723 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1724 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001725#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001726
Luciano Coelhobdd54832014-08-07 18:08:56 +03001727 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1728 mvm->debugfs_dir, &mvm->ps_disabled))
1729 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001730 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1731 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1732 goto err;
1733 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1734 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1735 goto err;
1736 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1737 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1738 goto err;
1739 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1740 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1741 goto err;
Moshe Harel91fac942015-09-02 12:45:12 +03001742 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1743 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1744 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001745
Ido Yariv2b55f432016-08-23 14:44:59 -04001746 debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
1747 &iwl_dbgfs_mem_ops);
1748
Johannes Berg8ca151b2013-01-24 14:25:36 +01001749 /*
1750 * Create a symlink with mac80211. It will be removed when mac80211
1751 * exists (before the opmode exists which removes the target.)
1752 */
Al Viro27a22092016-08-07 12:21:25 -04001753 snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001754 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1755 goto err;
1756
1757 return 0;
1758err:
1759 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1760 return -ENOMEM;
1761}