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