iwlwifi: mvm: move interface-specific debugfs to a new file
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
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 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
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
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
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 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * 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"
119663c3 66#include "iwl-prph.h"
820a1a50 67#include "debugfs.h"
8ca151b5 68
8ca151b5
JB
69static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
70 const char __user *user_buf,
71 size_t count, loff_t *ppos)
72{
73 struct iwl_mvm *mvm = file->private_data;
8a0bd168
JB
74 char buf[16] = {};
75 size_t buf_size = min(count, sizeof(buf) - 1);
76 int ret;
8ca151b5
JB
77 u32 scd_q_msk;
78
79 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
80 return -EIO;
81
8ca151b5
JB
82 if (copy_from_user(buf, user_buf, buf_size))
83 return -EFAULT;
84
85 if (sscanf(buf, "%x", &scd_q_msk) != 1)
86 return -EINVAL;
87
88 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
89
90 mutex_lock(&mvm->mutex);
91 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
92 mutex_unlock(&mvm->mutex);
93
94 return ret;
95}
96
97static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
98 const char __user *user_buf,
99 size_t count, loff_t *ppos)
100{
101 struct iwl_mvm *mvm = file->private_data;
102 struct ieee80211_sta *sta;
8a0bd168
JB
103 char buf[8] = {};
104 size_t buf_size = min(count, sizeof(buf) - 1);
105 int sta_id, drain, ret;
8ca151b5
JB
106
107 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
108 return -EIO;
109
8ca151b5
JB
110 if (copy_from_user(buf, user_buf, buf_size))
111 return -EFAULT;
112
113 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
114 return -EINVAL;
60765a47
JB
115 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
116 return -EINVAL;
117 if (drain < 0 || drain > 1)
118 return -EINVAL;
8ca151b5
JB
119
120 mutex_lock(&mvm->mutex);
121
122 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
123 lockdep_is_held(&mvm->mutex));
124 if (IS_ERR_OR_NULL(sta))
125 ret = -ENOENT;
126 else
127 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
128 count;
129
130 mutex_unlock(&mvm->mutex);
131
132 return ret;
133}
134
135static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
136 size_t count, loff_t *ppos)
137{
138 struct iwl_mvm *mvm = file->private_data;
139 const struct fw_img *img;
140 int ofs, len, pos = 0;
141 size_t bufsz, ret;
142 char *buf;
143 u8 *ptr;
144
60191d99
JB
145 if (!mvm->ucode_loaded)
146 return -EINVAL;
147
8ca151b5
JB
148 /* default is to dump the entire data segment */
149 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
8ca151b5 150 img = &mvm->fw->img[mvm->cur_ucode];
60191d99
JB
151 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
152 len = img->sec[IWL_UCODE_SECTION_DATA].len;
153 } else {
154 ofs = mvm->dbgfs_sram_offset;
155 len = mvm->dbgfs_sram_len;
8ca151b5 156 }
8ca151b5
JB
157
158 bufsz = len * 4 + 256;
159 buf = kzalloc(bufsz, GFP_KERNEL);
160 if (!buf)
161 return -ENOMEM;
162
163 ptr = kzalloc(len, GFP_KERNEL);
164 if (!ptr) {
165 kfree(buf);
166 return -ENOMEM;
167 }
168
169 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
60191d99 170 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
8ca151b5 171
60191d99 172 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
8ca151b5
JB
173 for (ofs = 0; ofs < len; ofs += 16) {
174 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
175 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
176 bufsz - pos, false);
177 pos += strlen(buf + pos);
178 if (bufsz - pos > 0)
179 buf[pos++] = '\n';
180 }
181
182 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
183
184 kfree(buf);
185 kfree(ptr);
186
187 return ret;
188}
189
190static ssize_t iwl_dbgfs_sram_write(struct file *file,
191 const char __user *user_buf, size_t count,
192 loff_t *ppos)
193{
194 struct iwl_mvm *mvm = file->private_data;
8a0bd168
JB
195 char buf[64] = {};
196 size_t buf_size = min(count, sizeof(buf) - 1);
8ca151b5
JB
197 u32 offset, len;
198
8ca151b5
JB
199 if (copy_from_user(buf, user_buf, buf_size))
200 return -EFAULT;
201
202 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
203 if ((offset & 0x3) || (len & 0x3))
204 return -EINVAL;
205 mvm->dbgfs_sram_offset = offset;
206 mvm->dbgfs_sram_len = len;
207 } else {
208 mvm->dbgfs_sram_offset = 0;
209 mvm->dbgfs_sram_len = 0;
210 }
211
212 return count;
213}
214
215static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
216 size_t count, loff_t *ppos)
217{
218 struct iwl_mvm *mvm = file->private_data;
219 struct ieee80211_sta *sta;
220 char buf[400];
221 int i, pos = 0, bufsz = sizeof(buf);
222
223 mutex_lock(&mvm->mutex);
224
225 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
226 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
227 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
228 lockdep_is_held(&mvm->mutex));
229 if (!sta)
230 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
231 else if (IS_ERR(sta))
232 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
233 PTR_ERR(sta));
234 else
235 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
236 sta->addr);
237 }
238
239 mutex_unlock(&mvm->mutex);
240
241 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
242}
243
64b928c4
AB
244static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
245 char __user *user_buf,
8ca151b5
JB
246 size_t count, loff_t *ppos)
247{
248 struct iwl_mvm *mvm = file->private_data;
64b928c4
AB
249 char buf[64];
250 int bufsz = sizeof(buf);
251 int pos = 0;
8ca151b5 252
64b928c4
AB
253 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
254 mvm->disable_power_off);
255 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
256 mvm->disable_power_off_d3);
8ca151b5 257
64b928c4 258 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
8ca151b5
JB
259}
260
64b928c4
AB
261static ssize_t iwl_dbgfs_disable_power_off_write(struct file *file,
262 const char __user *user_buf,
263 size_t count, loff_t *ppos)
8ca151b5
JB
264{
265 struct iwl_mvm *mvm = file->private_data;
64b928c4 266 char buf[64] = {};
8a0bd168 267 size_t buf_size = min(count, sizeof(buf) - 1);
64b928c4
AB
268 int ret;
269 int val;
270
271 if (!mvm->ucode_loaded)
272 return -EIO;
8ca151b5 273
8a0bd168 274 if (copy_from_user(buf, user_buf, buf_size))
8ca151b5
JB
275 return -EFAULT;
276
64b928c4
AB
277 if (!strncmp("disable_power_off_d0=", buf, 21)) {
278 if (sscanf(buf + 21, "%d", &val) != 1)
279 return -EINVAL;
280 mvm->disable_power_off = val;
281 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
282 if (sscanf(buf + 21, "%d", &val) != 1)
283 return -EINVAL;
284 mvm->disable_power_off_d3 = val;
285 } else {
8ca151b5 286 return -EINVAL;
64b928c4 287 }
8ca151b5 288
64b928c4
AB
289 mutex_lock(&mvm->mutex);
290 ret = iwl_mvm_power_update_device_mode(mvm);
291 mutex_unlock(&mvm->mutex);
8ca151b5 292
64b928c4 293 return ret ?: count;
8ca151b5
JB
294}
295
10942342
EG
296#define BT_MBOX_MSG(_notif, _num, _field) \
297 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
298 >> BT_MBOX##_num##_##_field##_POS)
299
300
301#define BT_MBOX_PRINT(_num, _field, _end) \
302 pos += scnprintf(buf + pos, bufsz - pos, \
303 "\t%s: %d%s", \
304 #_field, \
305 BT_MBOX_MSG(notif, _num, _field), \
306 true ? "\n" : ", ");
307
308static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
309 size_t count, loff_t *ppos)
310{
311 struct iwl_mvm *mvm = file->private_data;
312 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
313 char *buf;
314 int ret, pos = 0, bufsz = sizeof(char) * 1024;
315
316 buf = kmalloc(bufsz, GFP_KERNEL);
317 if (!buf)
318 return -ENOMEM;
319
320 mutex_lock(&mvm->mutex);
321
322 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
323
324 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
325 BT_MBOX_PRINT(0, LE_PROF1, false);
326 BT_MBOX_PRINT(0, LE_PROF2, false);
327 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
328 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
329 BT_MBOX_PRINT(0, INBAND_S, false);
330 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
331 BT_MBOX_PRINT(0, LE_SCAN, false);
332 BT_MBOX_PRINT(0, LE_ADV, false);
333 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
334 BT_MBOX_PRINT(0, OPEN_CON_1, true);
335
336 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
337
338 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
339 BT_MBOX_PRINT(1, IP_SR, false);
340 BT_MBOX_PRINT(1, LE_MSTR, false);
341 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
342 BT_MBOX_PRINT(1, MSG_TYPE, false);
343 BT_MBOX_PRINT(1, SSN, true);
344
345 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
346
347 BT_MBOX_PRINT(2, SNIFF_ACT, false);
348 BT_MBOX_PRINT(2, PAG, false);
349 BT_MBOX_PRINT(2, INQUIRY, false);
350 BT_MBOX_PRINT(2, CONN, false);
351 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
352 BT_MBOX_PRINT(2, DISC, false);
353 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
354 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
355 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
356 BT_MBOX_PRINT(2, SCO_DURATION, true);
357
358 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
359
360 BT_MBOX_PRINT(3, SCO_STATE, false);
361 BT_MBOX_PRINT(3, SNIFF_STATE, false);
362 BT_MBOX_PRINT(3, A2DP_STATE, false);
363 BT_MBOX_PRINT(3, ACL_STATE, false);
364 BT_MBOX_PRINT(3, MSTR_STATE, false);
365 BT_MBOX_PRINT(3, OBX_STATE, false);
366 BT_MBOX_PRINT(3, OPEN_CON_2, false);
367 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
368 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
369 BT_MBOX_PRINT(3, INBAND_P, false);
370 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
371 BT_MBOX_PRINT(3, SSN_2, false);
372 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
373
374 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
2de13cae 375 notif->bt_status);
10942342 376 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
2de13cae 377 notif->bt_open_conn);
10942342 378 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
2de13cae 379 notif->bt_traffic_load);
10942342 380 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
2de13cae 381 notif->bt_agg_traffic_load);
10942342 382 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
2de13cae
EG
383 notif->bt_ci_compliance);
384 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
385 le32_to_cpu(notif->primary_ch_lut));
386 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
387 le32_to_cpu(notif->secondary_ch_lut));
388 pos += scnprintf(buf+pos, bufsz-pos, "bt_activity_grading = %d\n",
389 le32_to_cpu(notif->bt_activity_grading));
10942342
EG
390
391 mutex_unlock(&mvm->mutex);
392
393 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
394 kfree(buf);
395
396 return ret;
397}
398#undef BT_MBOX_PRINT
399
2de13cae
EG
400static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
401 size_t count, loff_t *ppos)
402{
403 struct iwl_mvm *mvm = file->private_data;
404 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
405 char buf[256];
406 int bufsz = sizeof(buf);
407 int pos = 0;
408
409 mutex_lock(&mvm->mutex);
410
411 pos += scnprintf(buf+pos, bufsz-pos, "Channel inhibition CMD\n");
412 pos += scnprintf(buf+pos, bufsz-pos,
413 "\tPrimary Channel Bitmap 0x%016llx Fat: %d\n",
414 le64_to_cpu(cmd->bt_primary_ci),
415 !!cmd->co_run_bw_primary);
416 pos += scnprintf(buf+pos, bufsz-pos,
417 "\tSecondary Channel Bitmap 0x%016llx Fat: %d\n",
418 le64_to_cpu(cmd->bt_secondary_ci),
419 !!cmd->co_run_bw_secondary);
420
421 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
422 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
423 iwl_bt_ack_kill_msk[mvm->bt_kill_msk]);
424 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
425 iwl_bt_cts_kill_msk[mvm->bt_kill_msk]);
426
427 mutex_unlock(&mvm->mutex);
428
429 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
430}
431
3848ab66
MG
432#define PRINT_STATS_LE32(_str, _val) \
433 pos += scnprintf(buf + pos, bufsz - pos, \
434 fmt_table, _str, \
435 le32_to_cpu(_val))
436
437static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
438 char __user *user_buf, size_t count,
439 loff_t *ppos)
440{
441 struct iwl_mvm *mvm = file->private_data;
442 static const char *fmt_table = "\t%-30s %10u\n";
443 static const char *fmt_header = "%-32s\n";
444 int pos = 0;
445 char *buf;
446 int ret;
3f617281
LC
447 /* 43 is the size of each data line, 33 is the size of each header */
448 size_t bufsz =
449 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
450 (4 * 33) + 1;
451
3848ab66
MG
452 struct mvm_statistics_rx_phy *ofdm;
453 struct mvm_statistics_rx_phy *cck;
454 struct mvm_statistics_rx_non_phy *general;
455 struct mvm_statistics_rx_ht_phy *ht;
456
457 buf = kzalloc(bufsz, GFP_KERNEL);
458 if (!buf)
459 return -ENOMEM;
460
461 mutex_lock(&mvm->mutex);
462
463 ofdm = &mvm->rx_stats.ofdm;
464 cck = &mvm->rx_stats.cck;
465 general = &mvm->rx_stats.general;
466 ht = &mvm->rx_stats.ofdm_ht;
467
468 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
469 "Statistics_Rx - OFDM");
470 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
471 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
472 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
473 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
474 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
475 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
476 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
477 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
478 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
479 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
480 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
481 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
482 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
483 ofdm->rxe_frame_limit_overrun);
484 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
485 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
486 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
487 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
488 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
489 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
490 PRINT_STATS_LE32("reserved", ofdm->reserved);
491
492 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
493 "Statistics_Rx - CCK");
494 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
495 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
496 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
497 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
498 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
499 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
500 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
501 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
502 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
503 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
504 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
505 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
506 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
507 cck->rxe_frame_limit_overrun);
508 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
509 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
510 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
511 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
512 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
513 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
514 PRINT_STATS_LE32("reserved", cck->reserved);
515
516 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
517 "Statistics_Rx - GENERAL");
518 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
519 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
520 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
521 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
522 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
523 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
524 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
525 PRINT_STATS_LE32("adc_rx_saturation_time",
526 general->adc_rx_saturation_time);
527 PRINT_STATS_LE32("ina_detection_search_time",
528 general->ina_detection_search_time);
529 PRINT_STATS_LE32("beacon_silence_rssi_a",
530 general->beacon_silence_rssi_a);
531 PRINT_STATS_LE32("beacon_silence_rssi_b",
532 general->beacon_silence_rssi_b);
533 PRINT_STATS_LE32("beacon_silence_rssi_c",
534 general->beacon_silence_rssi_c);
535 PRINT_STATS_LE32("interference_data_flag",
536 general->interference_data_flag);
537 PRINT_STATS_LE32("channel_load", general->channel_load);
538 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
539 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
540 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
541 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
542 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
543 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
544 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
545 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
3f617281 546 PRINT_STATS_LE32("mac_id", general->mac_id);
3848ab66
MG
547 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
548
549 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
550 "Statistics_Rx - HT");
551 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
552 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
553 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
554 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
555 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
556 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
557 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
558 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
559 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
560 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
561
562 mutex_unlock(&mvm->mutex);
563
564 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
565 kfree(buf);
566
567 return ret;
568}
569#undef PRINT_STAT_LE32
570
490953ac
EG
571static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
572 const char __user *user_buf,
573 size_t count, loff_t *ppos)
574{
575 struct iwl_mvm *mvm = file->private_data;
490953ac
EG
576 int ret;
577
490953ac
EG
578 mutex_lock(&mvm->mutex);
579
291aa7c4
EH
580 /* allow one more restart that we're provoking here */
581 if (mvm->restart_fw >= 0)
582 mvm->restart_fw++;
583
490953ac
EG
584 /* take the return value to make compiler happy - it will fail anyway */
585 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
586
587 mutex_unlock(&mvm->mutex);
588
490953ac
EG
589 return count;
590}
591
119663c3
AB
592static ssize_t iwl_dbgfs_fw_nmi_write(struct file *file,
593 const char __user *user_buf,
594 size_t count, loff_t *ppos)
595{
596 struct iwl_mvm *mvm = file->private_data;
597
598 iwl_write_prph(mvm->trans, DEVICE_SET_NMI_REG, 1);
599
600 return count;
601}
602
91b05d10
OG
603static ssize_t
604iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
605 char __user *user_buf,
606 size_t count, loff_t *ppos)
607{
608 struct iwl_mvm *mvm = file->private_data;
609 int pos = 0;
610 char buf[32];
611 const size_t bufsz = sizeof(buf);
612
613 /* print which antennas were set for the scan command by the user */
614 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
615 if (mvm->scan_rx_ant & ANT_A)
616 pos += scnprintf(buf + pos, bufsz - pos, "A");
617 if (mvm->scan_rx_ant & ANT_B)
618 pos += scnprintf(buf + pos, bufsz - pos, "B");
619 if (mvm->scan_rx_ant & ANT_C)
620 pos += scnprintf(buf + pos, bufsz - pos, "C");
621 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
622
623 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
624}
625
626static ssize_t
627iwl_dbgfs_scan_ant_rxchain_write(struct file *file,
628 const char __user *user_buf,
629 size_t count, loff_t *ppos)
630{
631 struct iwl_mvm *mvm = file->private_data;
8a0bd168
JB
632 char buf[8] = {};
633 size_t buf_size = min(count, sizeof(buf) - 1);
91b05d10
OG
634 u8 scan_rx_ant;
635
91b05d10
OG
636 if (copy_from_user(buf, user_buf, buf_size))
637 return -EFAULT;
638 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
639 return -EINVAL;
640 if (scan_rx_ant > ANT_ABC)
641 return -EINVAL;
642 if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
643 return -EINVAL;
644
91b05d10
OG
645 mvm->scan_rx_ant = scan_rx_ant;
646
647 return count;
648}
649
afc66bb7
JB
650#ifdef CONFIG_PM_SLEEP
651static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
652 const char __user *user_buf,
653 size_t count, loff_t *ppos)
654{
655 struct iwl_mvm *mvm = file->private_data;
656 char buf[8] = {};
8a0bd168 657 size_t buf_size = min(count, sizeof(buf) - 1);
afc66bb7
JB
658 int store;
659
8a0bd168 660 if (copy_from_user(buf, user_buf, buf_size))
afc66bb7
JB
661 return -EFAULT;
662
663 if (sscanf(buf, "%d", &store) != 1)
664 return -EINVAL;
665
666 mvm->store_d3_resume_sram = store;
667
668 return count;
669}
670
671static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
672 size_t count, loff_t *ppos)
673{
674 struct iwl_mvm *mvm = file->private_data;
675 const struct fw_img *img;
676 int ofs, len, pos = 0;
677 size_t bufsz, ret;
678 char *buf;
679 u8 *ptr = mvm->d3_resume_sram;
680
681 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
682 len = img->sec[IWL_UCODE_SECTION_DATA].len;
683
684 bufsz = len * 4 + 256;
685 buf = kzalloc(bufsz, GFP_KERNEL);
686 if (!buf)
687 return -ENOMEM;
688
689 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
690 mvm->store_d3_resume_sram ? "en" : "dis");
691
692 if (ptr) {
693 for (ofs = 0; ofs < len; ofs += 16) {
694 pos += scnprintf(buf + pos, bufsz - pos,
695 "0x%.4x ", ofs);
696 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
697 bufsz - pos, false);
698 pos += strlen(buf + pos);
699 if (bufsz - pos > 0)
700 buf[pos++] = '\n';
701 }
702 } else {
703 pos += scnprintf(buf + pos, bufsz - pos,
704 "(no data captured)\n");
705 }
706
707 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
708
709 kfree(buf);
710
711 return ret;
712}
713#endif
714
8ca151b5
JB
715#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
716 if (!debugfs_create_file(#name, mode, parent, mvm, \
717 &iwl_dbgfs_##name##_ops)) \
718 goto err; \
719 } while (0)
720
8ca151b5
JB
721/* Device wide debugfs entries */
722MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
723MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
724MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
725MVM_DEBUGFS_READ_FILE_OPS(stations);
10942342 726MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
2de13cae 727MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
64b928c4 728MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off);
3848ab66 729MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
490953ac 730MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
119663c3 731MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi);
91b05d10
OG
732MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain);
733
afc66bb7
JB
734#ifdef CONFIG_PM_SLEEP
735MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
736#endif
8ca151b5
JB
737
738int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
739{
740 char buf[100];
741
742 mvm->debugfs_dir = dbgfs_dir;
743
744 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
745 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
746 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
747 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
10942342 748 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
2de13cae 749 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
64b928c4
AB
750 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)
751 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
752 S_IRUSR | S_IWUSR);
3848ab66 753 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
490953ac 754 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
119663c3 755 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
91b05d10
OG
756 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
757 S_IWUSR | S_IRUSR);
afc66bb7
JB
758#ifdef CONFIG_PM_SLEEP
759 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
debff618 760 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
b0114714
JB
761 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
762 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
763 goto err;
afc66bb7 764#endif
8ca151b5
JB
765
766 /*
767 * Create a symlink with mac80211. It will be removed when mac80211
768 * exists (before the opmode exists which removes the target.)
769 */
770 snprintf(buf, 100, "../../%s/%s",
771 dbgfs_dir->d_parent->d_parent->d_name.name,
772 dbgfs_dir->d_parent->d_name.name);
773 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
774 goto err;
775
776 return 0;
777err:
778 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
779 return -ENOMEM;
780}
This page took 0.143805 seconds and 5 git commands to generate.