blob: ac9787c092482d5ece3eef5dc06acea95fe7c46b [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.
Johannes Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020063#include <linux/vmalloc.h>
64
Johannes Berg8ca151b2013-01-24 14:25:36 +010065#include "mvm.h"
66#include "sta.h"
67#include "iwl-io.h"
Johannes Berg820a1a52013-11-12 16:58:41 +010068#include "debugfs.h"
Johannes Berg4d075002014-04-24 10:41:31 +020069#include "iwl-fw-error-dump.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010070
Johannes Berg1fa3f572013-11-13 09:10:21 +010071static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010072 size_t count, loff_t *ppos)
73{
Johannes Berg8a0bd162013-11-12 16:48:03 +010074 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +010075 u32 scd_q_msk;
76
77 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
78 return -EIO;
79
Johannes Berg8ca151b2013-01-24 14:25:36 +010080 if (sscanf(buf, "%x", &scd_q_msk) != 1)
81 return -EINVAL;
82
83 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
84
85 mutex_lock(&mvm->mutex);
86 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
87 mutex_unlock(&mvm->mutex);
88
89 return ret;
90}
91
Johannes Berg1fa3f572013-11-13 09:10:21 +010092static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010093 size_t count, loff_t *ppos)
94{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +020095 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +010096 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +010097
98 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
99 return -EIO;
100
Johannes Berg8ca151b2013-01-24 14:25:36 +0100101 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
102 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200103 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
104 return -EINVAL;
105 if (drain < 0 || drain > 1)
106 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100107
108 mutex_lock(&mvm->mutex);
109
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200110 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
111
112 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100113 ret = -ENOENT;
114 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200115 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116
117 mutex_unlock(&mvm->mutex);
118
119 return ret;
120}
121
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200122static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file)
123{
124 struct iwl_mvm *mvm = inode->i_private;
125 int ret;
126
127 if (!mvm)
128 return -EINVAL;
129
130 mutex_lock(&mvm->mutex);
131 if (!mvm->fw_error_dump) {
132 ret = -ENODATA;
133 goto out;
134 }
135
136 file->private_data = mvm->fw_error_dump;
137 mvm->fw_error_dump = NULL;
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +0200138 ret = 0;
139
140out:
141 mutex_unlock(&mvm->mutex);
142 return ret;
143}
144
145static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file,
146 char __user *user_buf,
147 size_t count, loff_t *ppos)
148{
149 struct iwl_fw_error_dump_file *dump_file = file->private_data;
150
151 return simple_read_from_buffer(user_buf, count, ppos,
152 dump_file,
153 le32_to_cpu(dump_file->file_len));
154}
155
156static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
157 struct file *file)
158{
159 vfree(file->private_data);
160
161 return 0;
162}
163
Johannes Berg8ca151b2013-01-24 14:25:36 +0100164static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
165 size_t count, loff_t *ppos)
166{
167 struct iwl_mvm *mvm = file->private_data;
168 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200169 unsigned int ofs, len;
170 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100171 u8 *ptr;
172
Johannes Berg60191d92013-05-15 13:08:51 +0200173 if (!mvm->ucode_loaded)
174 return -EINVAL;
175
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200177 img = &mvm->fw->img[mvm->cur_ucode];
178 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
179 len = img->sec[IWL_UCODE_SECTION_DATA].len;
180
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200181 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200182 ofs = mvm->dbgfs_sram_offset;
183 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100184 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100185
Johannes Berg8ca151b2013-01-24 14:25:36 +0100186 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200187 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100188 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100189
Johannes Berg60191d92013-05-15 13:08:51 +0200190 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200192 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100193
Johannes Berg8ca151b2013-01-24 14:25:36 +0100194 kfree(ptr);
195
196 return ret;
197}
198
Johannes Berg1fa3f572013-11-13 09:10:21 +0100199static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
200 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100201{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200202 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200204 u32 img_offset, img_len;
205
206 if (!mvm->ucode_loaded)
207 return -EINVAL;
208
209 img = &mvm->fw->img[mvm->cur_ucode];
210 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
211 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100212
Johannes Berg8ca151b2013-01-24 14:25:36 +0100213 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
214 if ((offset & 0x3) || (len & 0x3))
215 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200216
217 if (offset + len > img_offset + img_len)
218 return -EINVAL;
219
Johannes Berg8ca151b2013-01-24 14:25:36 +0100220 mvm->dbgfs_sram_offset = offset;
221 mvm->dbgfs_sram_len = len;
222 } else {
223 mvm->dbgfs_sram_offset = 0;
224 mvm->dbgfs_sram_len = 0;
225 }
226
227 return count;
228}
229
230static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
231 size_t count, loff_t *ppos)
232{
233 struct iwl_mvm *mvm = file->private_data;
234 struct ieee80211_sta *sta;
235 char buf[400];
236 int i, pos = 0, bufsz = sizeof(buf);
237
238 mutex_lock(&mvm->mutex);
239
240 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
241 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
242 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
243 lockdep_is_held(&mvm->mutex));
244 if (!sta)
245 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
246 else if (IS_ERR(sta))
247 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
248 PTR_ERR(sta));
249 else
250 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
251 sta->addr);
252 }
253
254 mutex_unlock(&mvm->mutex);
255
256 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
257}
258
Alexander Bondar64b928c2013-09-03 14:18:03 +0300259static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
260 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100261 size_t count, loff_t *ppos)
262{
263 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300264 char buf[64];
265 int bufsz = sizeof(buf);
266 int pos = 0;
267
268 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
269 mvm->disable_power_off);
270 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
271 mvm->disable_power_off_d3);
272
273 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
274}
275
Johannes Berg1fa3f572013-11-13 09:10:21 +0100276static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300277 size_t count, loff_t *ppos)
278{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100279 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100280
281 if (!mvm->ucode_loaded)
282 return -EIO;
283
Alexander Bondar64b928c2013-09-03 14:18:03 +0300284 if (!strncmp("disable_power_off_d0=", buf, 21)) {
285 if (sscanf(buf + 21, "%d", &val) != 1)
286 return -EINVAL;
287 mvm->disable_power_off = val;
288 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
289 if (sscanf(buf + 21, "%d", &val) != 1)
290 return -EINVAL;
291 mvm->disable_power_off_d3 = val;
292 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100293 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300294 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100295
Alexander Bondar64b928c2013-09-03 14:18:03 +0300296 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200297 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300298 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100299
Alexander Bondar64b928c2013-09-03 14:18:03 +0300300 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100301}
302
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200303#define BT_MBOX_MSG(_notif, _num, _field) \
304 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
305 >> BT_MBOX##_num##_##_field##_POS)
306
307
308#define BT_MBOX_PRINT(_num, _field, _end) \
309 pos += scnprintf(buf + pos, bufsz - pos, \
310 "\t%s: %d%s", \
311 #_field, \
312 BT_MBOX_MSG(notif, _num, _field), \
313 true ? "\n" : ", ");
314
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300315static
316int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
317 int pos, int bufsz)
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200318{
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200319 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
320
321 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
322 BT_MBOX_PRINT(0, LE_PROF1, false);
323 BT_MBOX_PRINT(0, LE_PROF2, false);
324 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
325 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
326 BT_MBOX_PRINT(0, INBAND_S, false);
327 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
328 BT_MBOX_PRINT(0, LE_SCAN, false);
329 BT_MBOX_PRINT(0, LE_ADV, false);
330 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
331 BT_MBOX_PRINT(0, OPEN_CON_1, true);
332
333 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
334
335 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
336 BT_MBOX_PRINT(1, IP_SR, false);
337 BT_MBOX_PRINT(1, LE_MSTR, false);
338 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
339 BT_MBOX_PRINT(1, MSG_TYPE, false);
340 BT_MBOX_PRINT(1, SSN, true);
341
342 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
343
344 BT_MBOX_PRINT(2, SNIFF_ACT, false);
345 BT_MBOX_PRINT(2, PAG, false);
346 BT_MBOX_PRINT(2, INQUIRY, false);
347 BT_MBOX_PRINT(2, CONN, false);
348 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
349 BT_MBOX_PRINT(2, DISC, false);
350 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
351 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
352 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
353 BT_MBOX_PRINT(2, SCO_DURATION, true);
354
355 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
356
357 BT_MBOX_PRINT(3, SCO_STATE, false);
358 BT_MBOX_PRINT(3, SNIFF_STATE, false);
359 BT_MBOX_PRINT(3, A2DP_STATE, false);
360 BT_MBOX_PRINT(3, ACL_STATE, false);
361 BT_MBOX_PRINT(3, MSTR_STATE, false);
362 BT_MBOX_PRINT(3, OBX_STATE, false);
363 BT_MBOX_PRINT(3, OPEN_CON_2, false);
364 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
365 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
366 BT_MBOX_PRINT(3, INBAND_P, false);
367 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
368 BT_MBOX_PRINT(3, SSN_2, false);
369 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
370
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300371 return pos;
372}
373
374static
375int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
376 char *buf, int pos, int bufsz)
377{
378 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
379
380 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
381 BT_MBOX_PRINT(0, LE_PROF1, false);
382 BT_MBOX_PRINT(0, LE_PROF2, false);
383 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
384 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
385 BT_MBOX_PRINT(0, INBAND_S, false);
386 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
387 BT_MBOX_PRINT(0, LE_SCAN, false);
388 BT_MBOX_PRINT(0, LE_ADV, false);
389 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
390 BT_MBOX_PRINT(0, OPEN_CON_1, true);
391
392 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
393
394 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
395 BT_MBOX_PRINT(1, IP_SR, false);
396 BT_MBOX_PRINT(1, LE_MSTR, false);
397 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
398 BT_MBOX_PRINT(1, MSG_TYPE, false);
399 BT_MBOX_PRINT(1, SSN, true);
400
401 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
402
403 BT_MBOX_PRINT(2, SNIFF_ACT, false);
404 BT_MBOX_PRINT(2, PAG, false);
405 BT_MBOX_PRINT(2, INQUIRY, false);
406 BT_MBOX_PRINT(2, CONN, false);
407 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
408 BT_MBOX_PRINT(2, DISC, false);
409 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
410 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
411 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
412 BT_MBOX_PRINT(2, SCO_DURATION, true);
413
414 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
415
416 BT_MBOX_PRINT(3, SCO_STATE, false);
417 BT_MBOX_PRINT(3, SNIFF_STATE, false);
418 BT_MBOX_PRINT(3, A2DP_STATE, false);
419 BT_MBOX_PRINT(3, ACL_STATE, false);
420 BT_MBOX_PRINT(3, MSTR_STATE, false);
421 BT_MBOX_PRINT(3, OBX_STATE, false);
422 BT_MBOX_PRINT(3, OPEN_CON_2, false);
423 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
424 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
425 BT_MBOX_PRINT(3, INBAND_P, false);
426 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
427 BT_MBOX_PRINT(3, SSN_2, false);
428 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
429
430 return pos;
431}
432
433static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
434 size_t count, loff_t *ppos)
435{
436 struct iwl_mvm *mvm = file->private_data;
437 char *buf;
438 int ret, pos = 0, bufsz = sizeof(char) * 1024;
439
440 buf = kmalloc(bufsz, GFP_KERNEL);
441 if (!buf)
442 return -ENOMEM;
443
444 mutex_lock(&mvm->mutex);
445
446 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
447 struct iwl_bt_coex_profile_notif_old *notif =
448 &mvm->last_bt_notif_old;
449
450 pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
451
452 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
453 notif->bt_ci_compliance);
454 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
455 le32_to_cpu(notif->primary_ch_lut));
456 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
457 le32_to_cpu(notif->secondary_ch_lut));
458 pos += scnprintf(buf+pos,
459 bufsz-pos, "bt_activity_grading = %d\n",
460 le32_to_cpu(notif->bt_activity_grading));
461 pos += scnprintf(buf+pos, bufsz-pos,
462 "antenna isolation = %d CORUN LUT index = %d\n",
463 mvm->last_ant_isol, mvm->last_corun_lut);
464 } else {
465 struct iwl_bt_coex_profile_notif *notif =
466 &mvm->last_bt_notif;
467
468 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
469
470 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
471 notif->bt_ci_compliance);
472 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
473 le32_to_cpu(notif->primary_ch_lut));
474 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
475 le32_to_cpu(notif->secondary_ch_lut));
476 pos += scnprintf(buf+pos,
477 bufsz-pos, "bt_activity_grading = %d\n",
478 le32_to_cpu(notif->bt_activity_grading));
479 pos += scnprintf(buf+pos, bufsz-pos,
480 "antenna isolation = %d CORUN LUT index = %d\n",
481 mvm->last_ant_isol, mvm->last_corun_lut);
482 }
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200483
484 mutex_unlock(&mvm->mutex);
485
486 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
487 kfree(buf);
488
489 return ret;
490}
491#undef BT_MBOX_PRINT
492
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300493static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
494 size_t count, loff_t *ppos)
495{
496 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300497 char buf[256];
498 int bufsz = sizeof(buf);
499 int pos = 0;
500
501 mutex_lock(&mvm->mutex);
502
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300503 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
504 struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300505
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300506 pos += scnprintf(buf+pos, bufsz-pos,
507 "Channel inhibition CMD\n");
508 pos += scnprintf(buf+pos, bufsz-pos,
509 "\tPrimary Channel Bitmap 0x%016llx\n",
510 le64_to_cpu(cmd->bt_primary_ci));
511 pos += scnprintf(buf+pos, bufsz-pos,
512 "\tSecondary Channel Bitmap 0x%016llx\n",
513 le64_to_cpu(cmd->bt_secondary_ci));
514
515 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
516 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
517 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
518 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
519 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
520
521 } else {
522 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
523
524 pos += scnprintf(buf+pos, bufsz-pos,
525 "Channel inhibition CMD\n");
526 pos += scnprintf(buf+pos, bufsz-pos,
527 "\tPrimary Channel Bitmap 0x%016llx\n",
528 le64_to_cpu(cmd->bt_primary_ci));
529 pos += scnprintf(buf+pos, bufsz-pos,
530 "\tSecondary Channel Bitmap 0x%016llx\n",
531 le64_to_cpu(cmd->bt_secondary_ci));
532
533 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
534 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
535 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
536 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
537 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
538 }
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300539
540 mutex_unlock(&mvm->mutex);
541
542 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
543}
544
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200545static ssize_t
546iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
547 size_t count, loff_t *ppos)
548{
549 u32 bt_tx_prio;
550
551 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
552 return -EINVAL;
553 if (bt_tx_prio > 4)
554 return -EINVAL;
555
556 mvm->bt_tx_prio = bt_tx_prio;
557
558 return count;
559}
560
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300561static ssize_t
562iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
563 size_t count, loff_t *ppos)
564{
565 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
566 [BT_FORCE_ANT_DIS] = "dis",
567 [BT_FORCE_ANT_AUTO] = "auto",
568 [BT_FORCE_ANT_BT] = "bt",
569 [BT_FORCE_ANT_WIFI] = "wifi",
570 };
571 int ret, bt_force_ant_mode;
572
573 for (bt_force_ant_mode = 0;
574 bt_force_ant_mode < ARRAY_SIZE(modes_str);
575 bt_force_ant_mode++) {
576 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
577 break;
578 }
579
580 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
581 return -EINVAL;
582
583 ret = 0;
584 mutex_lock(&mvm->mutex);
585 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
586 goto out;
587
588 mvm->bt_force_ant_mode = bt_force_ant_mode;
589 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
590 modes_str[mvm->bt_force_ant_mode]);
591 ret = iwl_send_bt_init_conf(mvm);
592
593out:
594 mutex_unlock(&mvm->mutex);
595 return ret ?: count;
596}
597
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300598#define PRINT_STATS_LE32(_str, _val) \
599 pos += scnprintf(buf + pos, bufsz - pos, \
600 fmt_table, _str, \
601 le32_to_cpu(_val))
602
603static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
604 char __user *user_buf, size_t count,
605 loff_t *ppos)
606{
607 struct iwl_mvm *mvm = file->private_data;
608 static const char *fmt_table = "\t%-30s %10u\n";
609 static const char *fmt_header = "%-32s\n";
610 int pos = 0;
611 char *buf;
612 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300613 /* 43 is the size of each data line, 33 is the size of each header */
614 size_t bufsz =
615 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
616 (4 * 33) + 1;
617
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300618 struct mvm_statistics_rx_phy *ofdm;
619 struct mvm_statistics_rx_phy *cck;
620 struct mvm_statistics_rx_non_phy *general;
621 struct mvm_statistics_rx_ht_phy *ht;
622
623 buf = kzalloc(bufsz, GFP_KERNEL);
624 if (!buf)
625 return -ENOMEM;
626
627 mutex_lock(&mvm->mutex);
628
629 ofdm = &mvm->rx_stats.ofdm;
630 cck = &mvm->rx_stats.cck;
631 general = &mvm->rx_stats.general;
632 ht = &mvm->rx_stats.ofdm_ht;
633
634 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
635 "Statistics_Rx - OFDM");
636 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
637 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
638 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
639 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
640 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
641 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
642 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
643 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
644 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
645 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
646 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
647 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
648 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
649 ofdm->rxe_frame_limit_overrun);
650 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
651 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
652 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
653 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
654 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
655 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
656 PRINT_STATS_LE32("reserved", ofdm->reserved);
657
658 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
659 "Statistics_Rx - CCK");
660 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
661 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
662 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
663 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
664 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
665 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
666 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
667 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
668 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
669 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
670 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
671 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
672 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
673 cck->rxe_frame_limit_overrun);
674 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
675 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
676 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
677 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
678 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
679 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
680 PRINT_STATS_LE32("reserved", cck->reserved);
681
682 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
683 "Statistics_Rx - GENERAL");
684 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
685 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
686 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
687 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
688 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
689 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
690 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
691 PRINT_STATS_LE32("adc_rx_saturation_time",
692 general->adc_rx_saturation_time);
693 PRINT_STATS_LE32("ina_detection_search_time",
694 general->ina_detection_search_time);
695 PRINT_STATS_LE32("beacon_silence_rssi_a",
696 general->beacon_silence_rssi_a);
697 PRINT_STATS_LE32("beacon_silence_rssi_b",
698 general->beacon_silence_rssi_b);
699 PRINT_STATS_LE32("beacon_silence_rssi_c",
700 general->beacon_silence_rssi_c);
701 PRINT_STATS_LE32("interference_data_flag",
702 general->interference_data_flag);
703 PRINT_STATS_LE32("channel_load", general->channel_load);
704 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
705 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
706 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
707 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
708 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
709 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
710 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
711 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
Luciano Coelho3f617282013-10-14 13:18:41 +0300712 PRINT_STATS_LE32("mac_id", general->mac_id);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300713 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
714
715 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
716 "Statistics_Rx - HT");
717 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
718 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
719 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
720 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
721 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
722 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
723 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
724 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
725 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
726 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
727
728 mutex_unlock(&mvm->mutex);
729
730 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
731 kfree(buf);
732
733 return ret;
734}
735#undef PRINT_STAT_LE32
736
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200737static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
738 char __user *user_buf, size_t count,
739 loff_t *ppos,
740 struct iwl_mvm_frame_stats *stats)
741{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200742 char *buff, *pos, *endpos;
743 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200744 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200745 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200746
747 buff = kmalloc(bufsz, GFP_KERNEL);
748 if (!buff)
749 return -ENOMEM;
750
751 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200752
753 pos = buff;
754 endpos = pos + bufsz;
755
756 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200757 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
758 stats->legacy_frames,
759 stats->ht_frames,
760 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200761 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200762 stats->bw_20_frames,
763 stats->bw_40_frames,
764 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200765 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200766 stats->ngi_frames,
767 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200768 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200769 stats->siso_frames,
770 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200771 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200772 stats->fail_frames,
773 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200774 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200775 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200776 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200777 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200778 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200779 stats->ampdu_count > 0 ?
780 (stats->agg_frames / stats->ampdu_count) : 0);
781
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200782 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200783
784 idx = stats->last_frame_idx - 1;
785 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
786 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
787 if (stats->last_rates[idx] == 0)
788 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200789 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200790 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200791 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200792 }
793 spin_unlock_bh(&mvm->drv_stats_lock);
794
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200795 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200796 kfree(buff);
797
798 return ret;
799}
800
801static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
802 char __user *user_buf, size_t count,
803 loff_t *ppos)
804{
805 struct iwl_mvm *mvm = file->private_data;
806
807 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
808 &mvm->drv_rx_stats);
809}
810
Johannes Berg1fa3f572013-11-13 09:10:21 +0100811static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200812 size_t count, loff_t *ppos)
813{
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200814 int ret;
815
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200816 mutex_lock(&mvm->mutex);
817
Eran Harary291aa7c2013-07-03 11:00:06 +0300818 /* allow one more restart that we're provoking here */
819 if (mvm->restart_fw >= 0)
820 mvm->restart_fw++;
821
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200822 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300823 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200824
825 mutex_unlock(&mvm->mutex);
826
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200827 return count;
828}
829
Johannes Berg1fa3f572013-11-13 09:10:21 +0100830static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200831 size_t count, loff_t *ppos)
832{
Eliad Peller576eeee2014-07-01 18:38:38 +0300833 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
834 if (ret)
835 return ret;
836
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300837 iwl_force_nmi(mvm->trans);
Alexander Bondar119663c2013-10-17 14:26:50 +0200838
Eliad Peller576eeee2014-07-01 18:38:38 +0300839 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
840
Alexander Bondar119663c2013-10-17 14:26:50 +0200841 return count;
842}
843
Oren Givon91b05d12013-08-19 08:36:48 +0300844static ssize_t
845iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
846 char __user *user_buf,
847 size_t count, loff_t *ppos)
848{
849 struct iwl_mvm *mvm = file->private_data;
850 int pos = 0;
851 char buf[32];
852 const size_t bufsz = sizeof(buf);
853
854 /* print which antennas were set for the scan command by the user */
855 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
856 if (mvm->scan_rx_ant & ANT_A)
857 pos += scnprintf(buf + pos, bufsz - pos, "A");
858 if (mvm->scan_rx_ant & ANT_B)
859 pos += scnprintf(buf + pos, bufsz - pos, "B");
860 if (mvm->scan_rx_ant & ANT_C)
861 pos += scnprintf(buf + pos, bufsz - pos, "C");
862 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
863
864 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
865}
866
867static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100868iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300869 size_t count, loff_t *ppos)
870{
Oren Givon91b05d12013-08-19 08:36:48 +0300871 u8 scan_rx_ant;
872
Oren Givon91b05d12013-08-19 08:36:48 +0300873 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
874 return -EINVAL;
875 if (scan_rx_ant > ANT_ABC)
876 return -EINVAL;
Johannes Berg4ed735e2014-02-12 21:47:44 +0100877 if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
Oren Givon91b05d12013-08-19 08:36:48 +0300878 return -EINVAL;
879
Oren Givon91b05d12013-08-19 08:36:48 +0300880 mvm->scan_rx_ant = scan_rx_ant;
881
882 return count;
883}
884
Eliad Pellerde06a592014-01-08 10:11:12 +0200885#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
886#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
887static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
888 char __user *user_buf,
889 size_t count, loff_t *ppos)
890{
891 struct iwl_mvm *mvm = file->private_data;
892 struct iwl_bcast_filter_cmd cmd;
893 const struct iwl_fw_bcast_filter *filter;
894 char *buf;
895 int bufsz = 1024;
896 int i, j, pos = 0;
897 ssize_t ret;
898
899 buf = kzalloc(bufsz, GFP_KERNEL);
900 if (!buf)
901 return -ENOMEM;
902
903 mutex_lock(&mvm->mutex);
904 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
905 ADD_TEXT("None\n");
906 mutex_unlock(&mvm->mutex);
907 goto out;
908 }
909 mutex_unlock(&mvm->mutex);
910
911 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
912 filter = &cmd.filters[i];
913
914 ADD_TEXT("Filter [%d]:\n", i);
915 ADD_TEXT("\tDiscard=%d\n", filter->discard);
916 ADD_TEXT("\tFrame Type: %s\n",
917 filter->frame_type ? "IPv4" : "Generic");
918
919 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
920 const struct iwl_fw_bcast_filter_attr *attr;
921
922 attr = &filter->attrs[j];
923 if (!attr->mask)
924 break;
925
926 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
927 j, attr->offset,
928 attr->offset_type ? "IP End" :
929 "Payload Start",
930 be32_to_cpu(attr->mask),
931 be32_to_cpu(attr->val),
932 le16_to_cpu(attr->reserved1));
933 }
934 }
935out:
936 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
937 kfree(buf);
938 return ret;
939}
940
941static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
942 size_t count, loff_t *ppos)
943{
944 int pos, next_pos;
945 struct iwl_fw_bcast_filter filter = {};
946 struct iwl_bcast_filter_cmd cmd;
947 u32 filter_id, attr_id, mask, value;
948 int err = 0;
949
950 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
951 &filter.frame_type, &pos) != 3)
952 return -EINVAL;
953
954 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
955 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
956 return -EINVAL;
957
958 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
959 attr_id++) {
960 struct iwl_fw_bcast_filter_attr *attr =
961 &filter.attrs[attr_id];
962
963 if (pos >= count)
964 break;
965
966 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
967 &attr->offset, &attr->offset_type,
968 &mask, &value, &next_pos) != 4)
969 return -EINVAL;
970
971 attr->mask = cpu_to_be32(mask);
972 attr->val = cpu_to_be32(value);
973 if (mask)
974 filter.num_attrs++;
975
976 pos += next_pos;
977 }
978
979 mutex_lock(&mvm->mutex);
980 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
981 &filter, sizeof(filter));
982
983 /* send updated bcast filtering configuration */
984 if (mvm->dbgfs_bcast_filtering.override &&
985 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300986 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +0200987 sizeof(cmd), &cmd);
988 mutex_unlock(&mvm->mutex);
989
990 return err ?: count;
991}
992
993static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
994 char __user *user_buf,
995 size_t count, loff_t *ppos)
996{
997 struct iwl_mvm *mvm = file->private_data;
998 struct iwl_bcast_filter_cmd cmd;
999 char *buf;
1000 int bufsz = 1024;
1001 int i, pos = 0;
1002 ssize_t ret;
1003
1004 buf = kzalloc(bufsz, GFP_KERNEL);
1005 if (!buf)
1006 return -ENOMEM;
1007
1008 mutex_lock(&mvm->mutex);
1009 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1010 ADD_TEXT("None\n");
1011 mutex_unlock(&mvm->mutex);
1012 goto out;
1013 }
1014 mutex_unlock(&mvm->mutex);
1015
1016 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1017 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1018
1019 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1020 i, mac->default_discard, mac->attached_filters);
1021 }
1022out:
1023 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1024 kfree(buf);
1025 return ret;
1026}
1027
1028static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1029 char *buf, size_t count,
1030 loff_t *ppos)
1031{
1032 struct iwl_bcast_filter_cmd cmd;
1033 struct iwl_fw_bcast_mac mac = {};
1034 u32 mac_id, attached_filters;
1035 int err = 0;
1036
1037 if (!mvm->bcast_filters)
1038 return -ENOENT;
1039
1040 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1041 &attached_filters) != 3)
1042 return -EINVAL;
1043
1044 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1045 mac.default_discard > 1 ||
1046 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1047 return -EINVAL;
1048
1049 mac.attached_filters = cpu_to_le16(attached_filters);
1050
1051 mutex_lock(&mvm->mutex);
1052 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1053 &mac, sizeof(mac));
1054
1055 /* send updated bcast filtering configuration */
1056 if (mvm->dbgfs_bcast_filtering.override &&
1057 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001058 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001059 sizeof(cmd), &cmd);
1060 mutex_unlock(&mvm->mutex);
1061
1062 return err ?: count;
1063}
1064#endif
1065
Johannes Bergafc66bb2013-05-03 11:44:16 +02001066#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001067static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +02001068 size_t count, loff_t *ppos)
1069{
Johannes Bergafc66bb2013-05-03 11:44:16 +02001070 int store;
1071
Johannes Bergafc66bb2013-05-03 11:44:16 +02001072 if (sscanf(buf, "%d", &store) != 1)
1073 return -EINVAL;
1074
1075 mvm->store_d3_resume_sram = store;
1076
1077 return count;
1078}
1079
1080static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1081 size_t count, loff_t *ppos)
1082{
1083 struct iwl_mvm *mvm = file->private_data;
1084 const struct fw_img *img;
1085 int ofs, len, pos = 0;
1086 size_t bufsz, ret;
1087 char *buf;
1088 u8 *ptr = mvm->d3_resume_sram;
1089
1090 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1091 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1092
1093 bufsz = len * 4 + 256;
1094 buf = kzalloc(bufsz, GFP_KERNEL);
1095 if (!buf)
1096 return -ENOMEM;
1097
1098 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1099 mvm->store_d3_resume_sram ? "en" : "dis");
1100
1101 if (ptr) {
1102 for (ofs = 0; ofs < len; ofs += 16) {
1103 pos += scnprintf(buf + pos, bufsz - pos,
1104 "0x%.4x ", ofs);
1105 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1106 bufsz - pos, false);
1107 pos += strlen(buf + pos);
1108 if (bufsz - pos > 0)
1109 buf[pos++] = '\n';
1110 }
1111 } else {
1112 pos += scnprintf(buf + pos, bufsz - pos,
1113 "(no data captured)\n");
1114 }
1115
1116 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1117
1118 kfree(buf);
1119
1120 return ret;
1121}
1122#endif
1123
Eliad Peller576eeee2014-07-01 18:38:38 +03001124#define PRINT_MVM_REF(ref) do { \
1125 if (mvm->refs[ref]) \
1126 pos += scnprintf(buf + pos, bufsz - pos, \
1127 "\t(0x%lx): %d %s\n", \
1128 BIT(ref), mvm->refs[ref], #ref); \
Eliad Peller70d6bab2013-11-05 14:45:16 +02001129} while (0)
1130
1131static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1132 char __user *user_buf,
1133 size_t count, loff_t *ppos)
1134{
1135 struct iwl_mvm *mvm = file->private_data;
Eliad Peller576eeee2014-07-01 18:38:38 +03001136 int i, pos = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001137 char buf[256];
1138 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001139 u32 refs = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001140
Eliad Peller576eeee2014-07-01 18:38:38 +03001141 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1142 if (mvm->refs[i])
1143 refs |= BIT(i);
1144
1145 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1146 refs);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001147
1148 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1149 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1150 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1151 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1152 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +02001153 PRINT_MVM_REF(IWL_MVM_REF_USER);
Eliad Pellerd15a7472014-03-27 18:53:12 +02001154 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001155
1156 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1157}
1158
Eliad Peller0eb83652013-11-11 18:56:35 +02001159static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1160 size_t count, loff_t *ppos)
1161{
1162 unsigned long value;
1163 int ret;
1164 bool taken;
1165
1166 ret = kstrtoul(buf, 10, &value);
1167 if (ret < 0)
1168 return ret;
1169
1170 mutex_lock(&mvm->mutex);
1171
Eliad Peller576eeee2014-07-01 18:38:38 +03001172 taken = mvm->refs[IWL_MVM_REF_USER];
Eliad Peller0eb83652013-11-11 18:56:35 +02001173 if (value == 1 && !taken)
1174 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1175 else if (value == 0 && taken)
1176 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1177 else
1178 ret = -EINVAL;
1179
1180 mutex_unlock(&mvm->mutex);
1181
1182 if (ret < 0)
1183 return ret;
1184 return count;
1185}
1186
Johannes Berg1fa3f572013-11-13 09:10:21 +01001187#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1188 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1189#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1190 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001191#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1192 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001193 &iwl_dbgfs_##name##_ops)) \
1194 goto err; \
1195 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +02001196#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1197 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001198
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001199static ssize_t
1200iwl_dbgfs_prph_reg_read(struct file *file,
1201 char __user *user_buf,
1202 size_t count, loff_t *ppos)
1203{
1204 struct iwl_mvm *mvm = file->private_data;
1205 int pos = 0;
1206 char buf[32];
1207 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001208 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001209
1210 if (!mvm->dbgfs_prph_reg_addr)
1211 return -EINVAL;
1212
Eliad Peller576eeee2014-07-01 18:38:38 +03001213 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1214 if (ret)
1215 return ret;
1216
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001217 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1218 mvm->dbgfs_prph_reg_addr,
1219 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1220
Eliad Peller576eeee2014-07-01 18:38:38 +03001221 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1222
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001223 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1224}
1225
1226static ssize_t
1227iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1228 size_t count, loff_t *ppos)
1229{
1230 u8 args;
1231 u32 value;
Eliad Peller576eeee2014-07-01 18:38:38 +03001232 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001233
1234 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1235 /* if we only want to set the reg address - nothing more to do */
1236 if (args == 1)
1237 goto out;
1238
1239 /* otherwise, make sure we have both address and value */
1240 if (args != 2)
1241 return -EINVAL;
1242
Eliad Peller576eeee2014-07-01 18:38:38 +03001243 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1244 if (ret)
1245 return ret;
1246
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001247 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
Eliad Peller576eeee2014-07-01 18:38:38 +03001248
1249 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001250out:
1251 return count;
1252}
1253
1254MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1255
Johannes Berg8ca151b2013-01-24 14:25:36 +01001256/* Device wide debugfs entries */
Johannes Berg1fa3f572013-11-13 09:10:21 +01001257MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1258MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1259MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001260MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001261MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001262MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001263MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001264MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001265MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001266MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1267MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001268MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001269MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001270MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001271MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Oren Givon91b05d12013-08-19 08:36:48 +03001272
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001273static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
Emmanuel Grumbach3a58d98e2014-04-13 09:38:48 +03001274 .open = iwl_dbgfs_fw_error_dump_open,
1275 .read = iwl_dbgfs_fw_error_dump_read,
1276 .release = iwl_dbgfs_fw_error_dump_release,
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001277};
1278
Eliad Pellerde06a592014-01-08 10:11:12 +02001279#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1280MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1281MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1282#endif
1283
Johannes Bergafc66bb2013-05-03 11:44:16 +02001284#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001285MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001286#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001287
1288int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1289{
Eliad Pellerde06a592014-01-08 10:11:12 +02001290 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001291 char buf[100];
1292
Johannes Bergd07913a2014-02-26 11:25:58 +01001293 spin_lock_init(&mvm->drv_stats_lock);
1294
Johannes Berg8ca151b2013-01-24 14:25:36 +01001295 mvm->debugfs_dir = dbgfs_dir;
1296
1297 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1298 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1299 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1300 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach1bd3cbc2014-03-18 21:15:06 +02001301 MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001302 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001303 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach639eaba2014-03-30 10:11:13 +03001304 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1305 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001306 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001307 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001308 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001309 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001310 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001311 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001312 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1313 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001314 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001315 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Eliad Pellerde06a592014-01-08 10:11:12 +02001316
1317#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1318 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1319 bcast_dir = debugfs_create_dir("bcast_filtering",
1320 mvm->debugfs_dir);
1321 if (!bcast_dir)
1322 goto err;
1323
1324 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1325 bcast_dir,
1326 &mvm->dbgfs_bcast_filtering.override))
1327 goto err;
1328
1329 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1330 bcast_dir, S_IWUSR | S_IRUSR);
1331 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1332 bcast_dir, S_IWUSR | S_IRUSR);
1333 }
1334#endif
1335
Johannes Bergafc66bb2013-05-03 11:44:16 +02001336#ifdef CONFIG_PM_SLEEP
1337 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001338 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001339 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1340 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1341 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001342#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001343
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001344 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1345 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1346 goto err;
1347 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1348 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1349 goto err;
1350 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1351 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1352 goto err;
1353 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1354 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1355 goto err;
1356
Johannes Berg8ca151b2013-01-24 14:25:36 +01001357 /*
1358 * Create a symlink with mac80211. It will be removed when mac80211
1359 * exists (before the opmode exists which removes the target.)
1360 */
1361 snprintf(buf, 100, "../../%s/%s",
1362 dbgfs_dir->d_parent->d_parent->d_name.name,
1363 dbgfs_dir->d_parent->d_name.name);
1364 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1365 goto err;
1366
1367 return 0;
1368err:
1369 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1370 return -ENOMEM;
1371}