blob: e3b42b4fa438f01398cac2f722ac90886eb7b5cd [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 *****************************************************************************/
63#include "mvm.h"
64#include "sta.h"
65#include "iwl-io.h"
Alexander Bondar119663c2013-10-17 14:26:50 +020066#include "iwl-prph.h"
Johannes Berg820a1a52013-11-12 16:58:41 +010067#include "debugfs.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010068
Johannes Berg1fa3f572013-11-13 09:10:21 +010069static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010070 size_t count, loff_t *ppos)
71{
Johannes Berg8a0bd162013-11-12 16:48:03 +010072 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +010073 u32 scd_q_msk;
74
75 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
76 return -EIO;
77
Johannes Berg8ca151b2013-01-24 14:25:36 +010078 if (sscanf(buf, "%x", &scd_q_msk) != 1)
79 return -EINVAL;
80
81 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
82
83 mutex_lock(&mvm->mutex);
84 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
85 mutex_unlock(&mvm->mutex);
86
87 return ret;
88}
89
Johannes Berg1fa3f572013-11-13 09:10:21 +010090static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010091 size_t count, loff_t *ppos)
92{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +020093 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +010094 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +010095
96 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
97 return -EIO;
98
Johannes Berg8ca151b2013-01-24 14:25:36 +010099 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
100 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200101 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
102 return -EINVAL;
103 if (drain < 0 || drain > 1)
104 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105
106 mutex_lock(&mvm->mutex);
107
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200108 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
109
110 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100111 ret = -ENOENT;
112 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200113 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100114
115 mutex_unlock(&mvm->mutex);
116
117 return ret;
118}
119
120static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
121 size_t count, loff_t *ppos)
122{
123 struct iwl_mvm *mvm = file->private_data;
124 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200125 unsigned int ofs, len;
126 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100127 u8 *ptr;
128
Johannes Berg60191d92013-05-15 13:08:51 +0200129 if (!mvm->ucode_loaded)
130 return -EINVAL;
131
Johannes Berg8ca151b2013-01-24 14:25:36 +0100132 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200133 img = &mvm->fw->img[mvm->cur_ucode];
134 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
135 len = img->sec[IWL_UCODE_SECTION_DATA].len;
136
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200137 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200138 ofs = mvm->dbgfs_sram_offset;
139 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100140 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141
Johannes Berg8ca151b2013-01-24 14:25:36 +0100142 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200143 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100144 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145
Johannes Berg60191d92013-05-15 13:08:51 +0200146 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100147
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200148 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100149
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150 kfree(ptr);
151
152 return ret;
153}
154
Johannes Berg1fa3f572013-11-13 09:10:21 +0100155static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
156 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100157{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200158 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200160 u32 img_offset, img_len;
161
162 if (!mvm->ucode_loaded)
163 return -EINVAL;
164
165 img = &mvm->fw->img[mvm->cur_ucode];
166 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
167 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100168
Johannes Berg8ca151b2013-01-24 14:25:36 +0100169 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
170 if ((offset & 0x3) || (len & 0x3))
171 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200172
173 if (offset + len > img_offset + img_len)
174 return -EINVAL;
175
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176 mvm->dbgfs_sram_offset = offset;
177 mvm->dbgfs_sram_len = len;
178 } else {
179 mvm->dbgfs_sram_offset = 0;
180 mvm->dbgfs_sram_len = 0;
181 }
182
183 return count;
184}
185
186static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
187 size_t count, loff_t *ppos)
188{
189 struct iwl_mvm *mvm = file->private_data;
190 struct ieee80211_sta *sta;
191 char buf[400];
192 int i, pos = 0, bufsz = sizeof(buf);
193
194 mutex_lock(&mvm->mutex);
195
196 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
197 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
198 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
199 lockdep_is_held(&mvm->mutex));
200 if (!sta)
201 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
202 else if (IS_ERR(sta))
203 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
204 PTR_ERR(sta));
205 else
206 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
207 sta->addr);
208 }
209
210 mutex_unlock(&mvm->mutex);
211
212 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
213}
214
Alexander Bondar64b928c2013-09-03 14:18:03 +0300215static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
216 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100217 size_t count, loff_t *ppos)
218{
219 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300220 char buf[64];
221 int bufsz = sizeof(buf);
222 int pos = 0;
223
224 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
225 mvm->disable_power_off);
226 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
227 mvm->disable_power_off_d3);
228
229 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
230}
231
Johannes Berg1fa3f572013-11-13 09:10:21 +0100232static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300233 size_t count, loff_t *ppos)
234{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100235 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100236
237 if (!mvm->ucode_loaded)
238 return -EIO;
239
Alexander Bondar64b928c2013-09-03 14:18:03 +0300240 if (!strncmp("disable_power_off_d0=", buf, 21)) {
241 if (sscanf(buf + 21, "%d", &val) != 1)
242 return -EINVAL;
243 mvm->disable_power_off = val;
244 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
245 if (sscanf(buf + 21, "%d", &val) != 1)
246 return -EINVAL;
247 mvm->disable_power_off_d3 = val;
248 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100249 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300250 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100251
Alexander Bondar64b928c2013-09-03 14:18:03 +0300252 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200253 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300254 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100255
Alexander Bondar64b928c2013-09-03 14:18:03 +0300256 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100257}
258
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200259#define BT_MBOX_MSG(_notif, _num, _field) \
260 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
261 >> BT_MBOX##_num##_##_field##_POS)
262
263
264#define BT_MBOX_PRINT(_num, _field, _end) \
265 pos += scnprintf(buf + pos, bufsz - pos, \
266 "\t%s: %d%s", \
267 #_field, \
268 BT_MBOX_MSG(notif, _num, _field), \
269 true ? "\n" : ", ");
270
271static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
272 size_t count, loff_t *ppos)
273{
274 struct iwl_mvm *mvm = file->private_data;
275 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
276 char *buf;
277 int ret, pos = 0, bufsz = sizeof(char) * 1024;
278
279 buf = kmalloc(bufsz, GFP_KERNEL);
280 if (!buf)
281 return -ENOMEM;
282
283 mutex_lock(&mvm->mutex);
284
285 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
286
287 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
288 BT_MBOX_PRINT(0, LE_PROF1, false);
289 BT_MBOX_PRINT(0, LE_PROF2, false);
290 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
291 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
292 BT_MBOX_PRINT(0, INBAND_S, false);
293 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
294 BT_MBOX_PRINT(0, LE_SCAN, false);
295 BT_MBOX_PRINT(0, LE_ADV, false);
296 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
297 BT_MBOX_PRINT(0, OPEN_CON_1, true);
298
299 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
300
301 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
302 BT_MBOX_PRINT(1, IP_SR, false);
303 BT_MBOX_PRINT(1, LE_MSTR, false);
304 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
305 BT_MBOX_PRINT(1, MSG_TYPE, false);
306 BT_MBOX_PRINT(1, SSN, true);
307
308 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
309
310 BT_MBOX_PRINT(2, SNIFF_ACT, false);
311 BT_MBOX_PRINT(2, PAG, false);
312 BT_MBOX_PRINT(2, INQUIRY, false);
313 BT_MBOX_PRINT(2, CONN, false);
314 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
315 BT_MBOX_PRINT(2, DISC, false);
316 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
317 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
318 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
319 BT_MBOX_PRINT(2, SCO_DURATION, true);
320
321 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
322
323 BT_MBOX_PRINT(3, SCO_STATE, false);
324 BT_MBOX_PRINT(3, SNIFF_STATE, false);
325 BT_MBOX_PRINT(3, A2DP_STATE, false);
326 BT_MBOX_PRINT(3, ACL_STATE, false);
327 BT_MBOX_PRINT(3, MSTR_STATE, false);
328 BT_MBOX_PRINT(3, OBX_STATE, false);
329 BT_MBOX_PRINT(3, OPEN_CON_2, false);
330 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
331 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
332 BT_MBOX_PRINT(3, INBAND_P, false);
333 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
334 BT_MBOX_PRINT(3, SSN_2, false);
335 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
336
337 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300338 notif->bt_status);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200339 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300340 notif->bt_open_conn);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200341 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300342 notif->bt_traffic_load);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200343 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300344 notif->bt_agg_traffic_load);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200345 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300346 notif->bt_ci_compliance);
347 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
348 le32_to_cpu(notif->primary_ch_lut));
349 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
350 le32_to_cpu(notif->secondary_ch_lut));
351 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
352 le32_to_cpu(notif->bt_activity_grading));
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200353
354 mutex_unlock(&mvm->mutex);
355
356 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
357 kfree(buf);
358
359 return ret;
360}
361#undef BT_MBOX_PRINT
362
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300363static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
364 size_t count, loff_t *ppos)
365{
366 struct iwl_mvm *mvm = file->private_data;
367 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
368 char buf[256];
369 int bufsz = sizeof(buf);
370 int pos = 0;
371
372 mutex_lock(&mvm->mutex);
373
374 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
375 pos += scnprintf(buf+pos, bufsz-pos,
376 "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
377 le64_to_cpu(cmd->bt_primary_ci),
378 !!cmd->co_run_bw_primary);
379 pos += scnprintf(buf+pos, bufsz-pos,
380 "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
381 le64_to_cpu(cmd->bt_secondary_ci),
382 !!cmd->co_run_bw_secondary);
383
384 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
385 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
386 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
387 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
388 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
389
390 mutex_unlock(&mvm->mutex);
391
392 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
393}
394
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300395#define PRINT_STATS_LE32(_str, _val) \
396 pos += scnprintf(buf + pos, bufsz - pos, \
397 fmt_table, _str, \
398 le32_to_cpu(_val))
399
400static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
401 char __user *user_buf, size_t count,
402 loff_t *ppos)
403{
404 struct iwl_mvm *mvm = file->private_data;
405 static const char *fmt_table = "\t%-30s %10u\n";
406 static const char *fmt_header = "%-32s\n";
407 int pos = 0;
408 char *buf;
409 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300410 /* 43 is the size of each data line, 33 is the size of each header */
411 size_t bufsz =
412 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
413 (4 * 33) + 1;
414
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300415 struct mvm_statistics_rx_phy *ofdm;
416 struct mvm_statistics_rx_phy *cck;
417 struct mvm_statistics_rx_non_phy *general;
418 struct mvm_statistics_rx_ht_phy *ht;
419
420 buf = kzalloc(bufsz, GFP_KERNEL);
421 if (!buf)
422 return -ENOMEM;
423
424 mutex_lock(&mvm->mutex);
425
426 ofdm = &mvm->rx_stats.ofdm;
427 cck = &mvm->rx_stats.cck;
428 general = &mvm->rx_stats.general;
429 ht = &mvm->rx_stats.ofdm_ht;
430
431 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
432 "Statistics_Rx - OFDM");
433 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
434 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
435 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
436 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
437 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
438 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
439 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
440 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
441 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
442 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
443 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
444 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
445 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
446 ofdm->rxe_frame_limit_overrun);
447 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
448 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
449 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
450 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
451 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
452 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
453 PRINT_STATS_LE32("reserved", ofdm->reserved);
454
455 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
456 "Statistics_Rx - CCK");
457 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
458 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
459 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
460 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
461 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
462 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
463 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
464 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
465 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
466 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
467 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
468 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
469 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
470 cck->rxe_frame_limit_overrun);
471 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
472 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
473 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
474 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
475 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
476 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
477 PRINT_STATS_LE32("reserved", cck->reserved);
478
479 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
480 "Statistics_Rx - GENERAL");
481 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
482 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
483 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
484 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
485 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
486 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
487 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
488 PRINT_STATS_LE32("adc_rx_saturation_time",
489 general->adc_rx_saturation_time);
490 PRINT_STATS_LE32("ina_detection_search_time",
491 general->ina_detection_search_time);
492 PRINT_STATS_LE32("beacon_silence_rssi_a",
493 general->beacon_silence_rssi_a);
494 PRINT_STATS_LE32("beacon_silence_rssi_b",
495 general->beacon_silence_rssi_b);
496 PRINT_STATS_LE32("beacon_silence_rssi_c",
497 general->beacon_silence_rssi_c);
498 PRINT_STATS_LE32("interference_data_flag",
499 general->interference_data_flag);
500 PRINT_STATS_LE32("channel_load", general->channel_load);
501 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
502 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
503 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
504 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
505 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
506 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
507 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
508 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
Luciano Coelho3f617282013-10-14 13:18:41 +0300509 PRINT_STATS_LE32("mac_id", general->mac_id);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300510 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
511
512 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
513 "Statistics_Rx - HT");
514 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
515 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
516 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
517 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
518 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
519 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
520 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
521 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
522 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
523 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
524
525 mutex_unlock(&mvm->mutex);
526
527 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
528 kfree(buf);
529
530 return ret;
531}
532#undef PRINT_STAT_LE32
533
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200534static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
535 char __user *user_buf, size_t count,
536 loff_t *ppos,
537 struct iwl_mvm_frame_stats *stats)
538{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200539 char *buff, *pos, *endpos;
540 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200541 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200542 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200543
544 buff = kmalloc(bufsz, GFP_KERNEL);
545 if (!buff)
546 return -ENOMEM;
547
548 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200549
550 pos = buff;
551 endpos = pos + bufsz;
552
553 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200554 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
555 stats->legacy_frames,
556 stats->ht_frames,
557 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200558 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200559 stats->bw_20_frames,
560 stats->bw_40_frames,
561 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200562 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200563 stats->ngi_frames,
564 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200565 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200566 stats->siso_frames,
567 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200568 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200569 stats->fail_frames,
570 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200571 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200572 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200573 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200574 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200575 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200576 stats->ampdu_count > 0 ?
577 (stats->agg_frames / stats->ampdu_count) : 0);
578
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200579 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200580
581 idx = stats->last_frame_idx - 1;
582 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
583 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
584 if (stats->last_rates[idx] == 0)
585 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200586 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200587 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200588 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200589 }
590 spin_unlock_bh(&mvm->drv_stats_lock);
591
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200592 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200593 kfree(buff);
594
595 return ret;
596}
597
598static ssize_t iwl_dbgfs_drv_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
604 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
605 &mvm->drv_rx_stats);
606}
607
Johannes Berg1fa3f572013-11-13 09:10:21 +0100608static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200609 size_t count, loff_t *ppos)
610{
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200611 int ret;
612
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200613 mutex_lock(&mvm->mutex);
614
Eran Harary291aa7c2013-07-03 11:00:06 +0300615 /* allow one more restart that we're provoking here */
616 if (mvm->restart_fw >= 0)
617 mvm->restart_fw++;
618
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200619 /* take the return value to make compiler happy - it will fail anyway */
620 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
621
622 mutex_unlock(&mvm->mutex);
623
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200624 return count;
625}
626
Johannes Berg1fa3f572013-11-13 09:10:21 +0100627static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200628 size_t count, loff_t *ppos)
629{
Alexander Bondar119663c2013-10-17 14:26:50 +0200630 iwl_write_prph(mvm->trans, DEVICE_SET_NMI_REG, 1);
631
632 return count;
633}
634
Oren Givon91b05d12013-08-19 08:36:48 +0300635static ssize_t
636iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
637 char __user *user_buf,
638 size_t count, loff_t *ppos)
639{
640 struct iwl_mvm *mvm = file->private_data;
641 int pos = 0;
642 char buf[32];
643 const size_t bufsz = sizeof(buf);
644
645 /* print which antennas were set for the scan command by the user */
646 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
647 if (mvm->scan_rx_ant & ANT_A)
648 pos += scnprintf(buf + pos, bufsz - pos, "A");
649 if (mvm->scan_rx_ant & ANT_B)
650 pos += scnprintf(buf + pos, bufsz - pos, "B");
651 if (mvm->scan_rx_ant & ANT_C)
652 pos += scnprintf(buf + pos, bufsz - pos, "C");
653 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
654
655 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
656}
657
658static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100659iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300660 size_t count, loff_t *ppos)
661{
Oren Givon91b05d12013-08-19 08:36:48 +0300662 u8 scan_rx_ant;
663
Oren Givon91b05d12013-08-19 08:36:48 +0300664 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
665 return -EINVAL;
666 if (scan_rx_ant > ANT_ABC)
667 return -EINVAL;
Johannes Berg4ed735e2014-02-12 21:47:44 +0100668 if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
Oren Givon91b05d12013-08-19 08:36:48 +0300669 return -EINVAL;
670
Oren Givon91b05d12013-08-19 08:36:48 +0300671 mvm->scan_rx_ant = scan_rx_ant;
672
673 return count;
674}
675
Eliad Pellerde06a592014-01-08 10:11:12 +0200676#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
677#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
678static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
679 char __user *user_buf,
680 size_t count, loff_t *ppos)
681{
682 struct iwl_mvm *mvm = file->private_data;
683 struct iwl_bcast_filter_cmd cmd;
684 const struct iwl_fw_bcast_filter *filter;
685 char *buf;
686 int bufsz = 1024;
687 int i, j, pos = 0;
688 ssize_t ret;
689
690 buf = kzalloc(bufsz, GFP_KERNEL);
691 if (!buf)
692 return -ENOMEM;
693
694 mutex_lock(&mvm->mutex);
695 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
696 ADD_TEXT("None\n");
697 mutex_unlock(&mvm->mutex);
698 goto out;
699 }
700 mutex_unlock(&mvm->mutex);
701
702 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
703 filter = &cmd.filters[i];
704
705 ADD_TEXT("Filter [%d]:\n", i);
706 ADD_TEXT("\tDiscard=%d\n", filter->discard);
707 ADD_TEXT("\tFrame Type: %s\n",
708 filter->frame_type ? "IPv4" : "Generic");
709
710 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
711 const struct iwl_fw_bcast_filter_attr *attr;
712
713 attr = &filter->attrs[j];
714 if (!attr->mask)
715 break;
716
717 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
718 j, attr->offset,
719 attr->offset_type ? "IP End" :
720 "Payload Start",
721 be32_to_cpu(attr->mask),
722 be32_to_cpu(attr->val),
723 le16_to_cpu(attr->reserved1));
724 }
725 }
726out:
727 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
728 kfree(buf);
729 return ret;
730}
731
732static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
733 size_t count, loff_t *ppos)
734{
735 int pos, next_pos;
736 struct iwl_fw_bcast_filter filter = {};
737 struct iwl_bcast_filter_cmd cmd;
738 u32 filter_id, attr_id, mask, value;
739 int err = 0;
740
741 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
742 &filter.frame_type, &pos) != 3)
743 return -EINVAL;
744
745 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
746 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
747 return -EINVAL;
748
749 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
750 attr_id++) {
751 struct iwl_fw_bcast_filter_attr *attr =
752 &filter.attrs[attr_id];
753
754 if (pos >= count)
755 break;
756
757 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
758 &attr->offset, &attr->offset_type,
759 &mask, &value, &next_pos) != 4)
760 return -EINVAL;
761
762 attr->mask = cpu_to_be32(mask);
763 attr->val = cpu_to_be32(value);
764 if (mask)
765 filter.num_attrs++;
766
767 pos += next_pos;
768 }
769
770 mutex_lock(&mvm->mutex);
771 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
772 &filter, sizeof(filter));
773
774 /* send updated bcast filtering configuration */
775 if (mvm->dbgfs_bcast_filtering.override &&
776 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
777 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
778 sizeof(cmd), &cmd);
779 mutex_unlock(&mvm->mutex);
780
781 return err ?: count;
782}
783
784static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
785 char __user *user_buf,
786 size_t count, loff_t *ppos)
787{
788 struct iwl_mvm *mvm = file->private_data;
789 struct iwl_bcast_filter_cmd cmd;
790 char *buf;
791 int bufsz = 1024;
792 int i, pos = 0;
793 ssize_t ret;
794
795 buf = kzalloc(bufsz, GFP_KERNEL);
796 if (!buf)
797 return -ENOMEM;
798
799 mutex_lock(&mvm->mutex);
800 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
801 ADD_TEXT("None\n");
802 mutex_unlock(&mvm->mutex);
803 goto out;
804 }
805 mutex_unlock(&mvm->mutex);
806
807 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
808 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
809
810 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
811 i, mac->default_discard, mac->attached_filters);
812 }
813out:
814 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
815 kfree(buf);
816 return ret;
817}
818
819static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
820 char *buf, size_t count,
821 loff_t *ppos)
822{
823 struct iwl_bcast_filter_cmd cmd;
824 struct iwl_fw_bcast_mac mac = {};
825 u32 mac_id, attached_filters;
826 int err = 0;
827
828 if (!mvm->bcast_filters)
829 return -ENOENT;
830
831 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
832 &attached_filters) != 3)
833 return -EINVAL;
834
835 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
836 mac.default_discard > 1 ||
837 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
838 return -EINVAL;
839
840 mac.attached_filters = cpu_to_le16(attached_filters);
841
842 mutex_lock(&mvm->mutex);
843 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
844 &mac, sizeof(mac));
845
846 /* send updated bcast filtering configuration */
847 if (mvm->dbgfs_bcast_filtering.override &&
848 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
849 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
850 sizeof(cmd), &cmd);
851 mutex_unlock(&mvm->mutex);
852
853 return err ?: count;
854}
855#endif
856
Johannes Bergafc66bb2013-05-03 11:44:16 +0200857#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +0100858static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +0200859 size_t count, loff_t *ppos)
860{
Johannes Bergafc66bb2013-05-03 11:44:16 +0200861 int store;
862
Johannes Bergafc66bb2013-05-03 11:44:16 +0200863 if (sscanf(buf, "%d", &store) != 1)
864 return -EINVAL;
865
866 mvm->store_d3_resume_sram = store;
867
868 return count;
869}
870
871static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
872 size_t count, loff_t *ppos)
873{
874 struct iwl_mvm *mvm = file->private_data;
875 const struct fw_img *img;
876 int ofs, len, pos = 0;
877 size_t bufsz, ret;
878 char *buf;
879 u8 *ptr = mvm->d3_resume_sram;
880
881 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
882 len = img->sec[IWL_UCODE_SECTION_DATA].len;
883
884 bufsz = len * 4 + 256;
885 buf = kzalloc(bufsz, GFP_KERNEL);
886 if (!buf)
887 return -ENOMEM;
888
889 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
890 mvm->store_d3_resume_sram ? "en" : "dis");
891
892 if (ptr) {
893 for (ofs = 0; ofs < len; ofs += 16) {
894 pos += scnprintf(buf + pos, bufsz - pos,
895 "0x%.4x ", ofs);
896 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
897 bufsz - pos, false);
898 pos += strlen(buf + pos);
899 if (bufsz - pos > 0)
900 buf[pos++] = '\n';
901 }
902 } else {
903 pos += scnprintf(buf + pos, bufsz - pos,
904 "(no data captured)\n");
905 }
906
907 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
908
909 kfree(buf);
910
911 return ret;
912}
913#endif
914
Eliad Peller70d6bab2013-11-05 14:45:16 +0200915#define PRINT_MVM_REF(ref) do { \
916 if (test_bit(ref, mvm->ref_bitmap)) \
917 pos += scnprintf(buf + pos, bufsz - pos, \
918 "\t(0x%lx) %s\n", \
919 BIT(ref), #ref); \
920} while (0)
921
922static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
923 char __user *user_buf,
924 size_t count, loff_t *ppos)
925{
926 struct iwl_mvm *mvm = file->private_data;
927 int pos = 0;
928 char buf[256];
929 const size_t bufsz = sizeof(buf);
930
931 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%lx\n",
932 mvm->ref_bitmap[0]);
933
934 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
935 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
936 PRINT_MVM_REF(IWL_MVM_REF_ROC);
937 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
938 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +0200939 PRINT_MVM_REF(IWL_MVM_REF_USER);
Eliad Peller70d6bab2013-11-05 14:45:16 +0200940
941 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
942}
943
Eliad Peller0eb83652013-11-11 18:56:35 +0200944static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
945 size_t count, loff_t *ppos)
946{
947 unsigned long value;
948 int ret;
949 bool taken;
950
951 ret = kstrtoul(buf, 10, &value);
952 if (ret < 0)
953 return ret;
954
955 mutex_lock(&mvm->mutex);
956
957 taken = test_bit(IWL_MVM_REF_USER, mvm->ref_bitmap);
958 if (value == 1 && !taken)
959 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
960 else if (value == 0 && taken)
961 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
962 else
963 ret = -EINVAL;
964
965 mutex_unlock(&mvm->mutex);
966
967 if (ret < 0)
968 return ret;
969 return count;
970}
971
Johannes Berg1fa3f572013-11-13 09:10:21 +0100972#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
973 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
974#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
975 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +0200976#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
977 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +0100978 &iwl_dbgfs_##name##_ops)) \
979 goto err; \
980 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +0200981#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
982 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100983
Eliad Pellerf3c221f2014-01-09 13:12:54 +0200984static ssize_t
985iwl_dbgfs_prph_reg_read(struct file *file,
986 char __user *user_buf,
987 size_t count, loff_t *ppos)
988{
989 struct iwl_mvm *mvm = file->private_data;
990 int pos = 0;
991 char buf[32];
992 const size_t bufsz = sizeof(buf);
993
994 if (!mvm->dbgfs_prph_reg_addr)
995 return -EINVAL;
996
997 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
998 mvm->dbgfs_prph_reg_addr,
999 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1000
1001 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1002}
1003
1004static ssize_t
1005iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1006 size_t count, loff_t *ppos)
1007{
1008 u8 args;
1009 u32 value;
1010
1011 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1012 /* if we only want to set the reg address - nothing more to do */
1013 if (args == 1)
1014 goto out;
1015
1016 /* otherwise, make sure we have both address and value */
1017 if (args != 2)
1018 return -EINVAL;
1019
1020 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1021out:
1022 return count;
1023}
1024
1025MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1026
Johannes Berg8ca151b2013-01-24 14:25:36 +01001027/* Device wide debugfs entries */
Johannes Berg1fa3f572013-11-13 09:10:21 +01001028MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1029MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1030MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001031MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001032MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001033MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001034MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001035MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001036MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001037MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1038MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1039MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001040MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Oren Givon91b05d12013-08-19 08:36:48 +03001041
Eliad Pellerde06a592014-01-08 10:11:12 +02001042#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1043MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1044MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1045#endif
1046
Johannes Bergafc66bb2013-05-03 11:44:16 +02001047#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001048MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001049#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001050
1051int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1052{
Eliad Pellerde06a592014-01-08 10:11:12 +02001053 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001054 char buf[100];
1055
Johannes Bergd07913a2014-02-26 11:25:58 +01001056 spin_lock_init(&mvm->drv_stats_lock);
1057
Johannes Berg8ca151b2013-01-24 14:25:36 +01001058 mvm->debugfs_dir = dbgfs_dir;
1059
1060 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1061 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1062 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1063 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001064 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001065 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001066 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
1067 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1068 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001069 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001070 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001071 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001072 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001073 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1074 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001075 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001076 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Eliad Pellerde06a592014-01-08 10:11:12 +02001077
1078#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1079 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1080 bcast_dir = debugfs_create_dir("bcast_filtering",
1081 mvm->debugfs_dir);
1082 if (!bcast_dir)
1083 goto err;
1084
1085 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1086 bcast_dir,
1087 &mvm->dbgfs_bcast_filtering.override))
1088 goto err;
1089
1090 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1091 bcast_dir, S_IWUSR | S_IRUSR);
1092 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1093 bcast_dir, S_IWUSR | S_IRUSR);
1094 }
1095#endif
1096
Johannes Bergafc66bb2013-05-03 11:44:16 +02001097#ifdef CONFIG_PM_SLEEP
1098 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001099 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001100 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1101 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1102 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001103#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001105 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1106 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1107 goto err;
1108 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1109 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1110 goto err;
1111 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1112 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1113 goto err;
1114 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1115 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1116 goto err;
1117
Johannes Berg8ca151b2013-01-24 14:25:36 +01001118 /*
1119 * Create a symlink with mac80211. It will be removed when mac80211
1120 * exists (before the opmode exists which removes the target.)
1121 */
1122 snprintf(buf, 100, "../../%s/%s",
1123 dbgfs_dir->d_parent->d_parent->d_name.name,
1124 dbgfs_dir->d_parent->d_name.name);
1125 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1126 goto err;
1127
1128 return 0;
1129err:
1130 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1131 return -ENOMEM;
1132}