Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs.c
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
25 * in the file called COPYING.
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"
66
67 struct iwl_dbgfs_mvm_ctx {
68 struct iwl_mvm *mvm;
69 struct ieee80211_vif *vif;
70 };
71
72 static ssize_t iwl_dbgfs_tx_flush_write(struct file *file,
73 const char __user *user_buf,
74 size_t count, loff_t *ppos)
75 {
76 struct iwl_mvm *mvm = file->private_data;
77
78 char buf[16];
79 int buf_size, ret;
80 u32 scd_q_msk;
81
82 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
83 return -EIO;
84
85 memset(buf, 0, sizeof(buf));
86 buf_size = min(count, sizeof(buf) - 1);
87 if (copy_from_user(buf, user_buf, buf_size))
88 return -EFAULT;
89
90 if (sscanf(buf, "%x", &scd_q_msk) != 1)
91 return -EINVAL;
92
93 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
94
95 mutex_lock(&mvm->mutex);
96 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
97 mutex_unlock(&mvm->mutex);
98
99 return ret;
100 }
101
102 static ssize_t iwl_dbgfs_sta_drain_write(struct file *file,
103 const char __user *user_buf,
104 size_t count, loff_t *ppos)
105 {
106 struct iwl_mvm *mvm = file->private_data;
107 struct ieee80211_sta *sta;
108
109 char buf[8];
110 int buf_size, sta_id, drain, ret;
111
112 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
113 return -EIO;
114
115 memset(buf, 0, sizeof(buf));
116 buf_size = min(count, sizeof(buf) - 1);
117 if (copy_from_user(buf, user_buf, buf_size))
118 return -EFAULT;
119
120 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
121 return -EINVAL;
122
123 mutex_lock(&mvm->mutex);
124
125 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
126 lockdep_is_held(&mvm->mutex));
127 if (IS_ERR_OR_NULL(sta))
128 ret = -ENOENT;
129 else
130 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
131 count;
132
133 mutex_unlock(&mvm->mutex);
134
135 return ret;
136 }
137
138 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
139 size_t count, loff_t *ppos)
140 {
141 struct iwl_mvm *mvm = file->private_data;
142 const struct fw_img *img;
143 int ofs, len, pos = 0;
144 size_t bufsz, ret;
145 char *buf;
146 u8 *ptr;
147
148 if (!mvm->ucode_loaded)
149 return -EINVAL;
150
151 /* default is to dump the entire data segment */
152 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
153 img = &mvm->fw->img[mvm->cur_ucode];
154 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
155 len = img->sec[IWL_UCODE_SECTION_DATA].len;
156 } else {
157 ofs = mvm->dbgfs_sram_offset;
158 len = mvm->dbgfs_sram_len;
159 }
160
161 bufsz = len * 4 + 256;
162 buf = kzalloc(bufsz, GFP_KERNEL);
163 if (!buf)
164 return -ENOMEM;
165
166 ptr = kzalloc(len, GFP_KERNEL);
167 if (!ptr) {
168 kfree(buf);
169 return -ENOMEM;
170 }
171
172 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
173 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
174
175 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
176 for (ofs = 0; ofs < len; ofs += 16) {
177 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
178 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
179 bufsz - pos, false);
180 pos += strlen(buf + pos);
181 if (bufsz - pos > 0)
182 buf[pos++] = '\n';
183 }
184
185 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
186
187 kfree(buf);
188 kfree(ptr);
189
190 return ret;
191 }
192
193 static ssize_t iwl_dbgfs_sram_write(struct file *file,
194 const char __user *user_buf, size_t count,
195 loff_t *ppos)
196 {
197 struct iwl_mvm *mvm = file->private_data;
198 char buf[64];
199 int buf_size;
200 u32 offset, len;
201
202 memset(buf, 0, sizeof(buf));
203 buf_size = min(count, sizeof(buf) - 1);
204 if (copy_from_user(buf, user_buf, buf_size))
205 return -EFAULT;
206
207 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
208 if ((offset & 0x3) || (len & 0x3))
209 return -EINVAL;
210 mvm->dbgfs_sram_offset = offset;
211 mvm->dbgfs_sram_len = len;
212 } else {
213 mvm->dbgfs_sram_offset = 0;
214 mvm->dbgfs_sram_len = 0;
215 }
216
217 return count;
218 }
219
220 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
221 size_t count, loff_t *ppos)
222 {
223 struct iwl_mvm *mvm = file->private_data;
224 struct ieee80211_sta *sta;
225 char buf[400];
226 int i, pos = 0, bufsz = sizeof(buf);
227
228 mutex_lock(&mvm->mutex);
229
230 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
231 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
232 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
233 lockdep_is_held(&mvm->mutex));
234 if (!sta)
235 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
236 else if (IS_ERR(sta))
237 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
238 PTR_ERR(sta));
239 else
240 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
241 sta->addr);
242 }
243
244 mutex_unlock(&mvm->mutex);
245
246 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
247 }
248
249 static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file,
250 const char __user *user_buf,
251 size_t count, loff_t *ppos)
252 {
253 struct iwl_mvm *mvm = file->private_data;
254 char buf[8] = {};
255 int allow;
256
257 if (!mvm->ucode_loaded)
258 return -EIO;
259
260 if (copy_from_user(buf, user_buf, sizeof(buf)))
261 return -EFAULT;
262
263 if (sscanf(buf, "%d", &allow) != 1)
264 return -EINVAL;
265
266 IWL_DEBUG_POWER(mvm, "%s device power down\n",
267 allow ? "allow" : "prevent");
268
269 /*
270 * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
271 */
272
273 return count;
274 }
275
276 static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file,
277 const char __user *user_buf,
278 size_t count, loff_t *ppos)
279 {
280 struct iwl_mvm *mvm = file->private_data;
281 char buf[8] = {};
282 int allow;
283
284 if (copy_from_user(buf, user_buf, sizeof(buf)))
285 return -EFAULT;
286
287 if (sscanf(buf, "%d", &allow) != 1)
288 return -EINVAL;
289
290 IWL_DEBUG_POWER(mvm, "%s device power down in d3\n",
291 allow ? "allow" : "prevent");
292
293 /*
294 * TODO: When WoWLAN FW alive notification happens, driver will send
295 * REPLY_DEBUG_CMD setting power_down_allow flag according to
296 * mvm->prevent_power_down_d3
297 */
298 mvm->prevent_power_down_d3 = !allow;
299
300 return count;
301 }
302
303 static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
304 struct ieee80211_vif *vif,
305 enum iwl_dbgfs_pm_mask param, int val)
306 {
307 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
308 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
309
310 dbgfs_pm->mask |= param;
311
312 switch (param) {
313 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
314 struct ieee80211_hw *hw = mvm->hw;
315 int dtimper = hw->conf.ps_dtim_period ?: 1;
316 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
317
318 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
319 if (val * MSEC_PER_SEC < 3 * dtimper_msec) {
320 IWL_WARN(mvm,
321 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
322 val * MSEC_PER_SEC, 3 * dtimper_msec);
323 }
324 dbgfs_pm->keep_alive_seconds = val;
325 break;
326 }
327 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
328 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
329 val ? "enabled" : "disabled");
330 dbgfs_pm->skip_over_dtim = val;
331 break;
332 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
333 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
334 dbgfs_pm->skip_dtim_periods = val;
335 break;
336 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
337 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
338 dbgfs_pm->rx_data_timeout = val;
339 break;
340 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
341 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
342 dbgfs_pm->tx_data_timeout = val;
343 break;
344 case MVM_DEBUGFS_PM_DISABLE_POWER_OFF:
345 IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val);
346 dbgfs_pm->disable_power_off = val;
347 case MVM_DEBUGFS_PM_LPRX_ENA:
348 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
349 dbgfs_pm->lprx_ena = val;
350 break;
351 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
352 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
353 dbgfs_pm->lprx_rssi_threshold = val;
354 break;
355 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
356 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
357 dbgfs_pm->snooze_ena = val;
358 break;
359 }
360 }
361
362 static ssize_t iwl_dbgfs_pm_params_write(struct file *file,
363 const char __user *user_buf,
364 size_t count, loff_t *ppos)
365 {
366 struct ieee80211_vif *vif = file->private_data;
367 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
368 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
369 enum iwl_dbgfs_pm_mask param;
370 char buf[32] = {};
371 int val;
372 int ret;
373
374 if (copy_from_user(buf, user_buf, sizeof(buf)))
375 return -EFAULT;
376
377 if (!strncmp("keep_alive=", buf, 11)) {
378 if (sscanf(buf + 11, "%d", &val) != 1)
379 return -EINVAL;
380 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
381 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
382 if (sscanf(buf + 15, "%d", &val) != 1)
383 return -EINVAL;
384 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
385 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
386 if (sscanf(buf + 18, "%d", &val) != 1)
387 return -EINVAL;
388 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
389 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
390 if (sscanf(buf + 16, "%d", &val) != 1)
391 return -EINVAL;
392 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
393 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
394 if (sscanf(buf + 16, "%d", &val) != 1)
395 return -EINVAL;
396 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
397 } else if (!strncmp("disable_power_off=", buf, 18)) {
398 if (sscanf(buf + 18, "%d", &val) != 1)
399 return -EINVAL;
400 param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF;
401 } else if (!strncmp("lprx=", buf, 5)) {
402 if (sscanf(buf + 5, "%d", &val) != 1)
403 return -EINVAL;
404 param = MVM_DEBUGFS_PM_LPRX_ENA;
405 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
406 if (sscanf(buf + 20, "%d", &val) != 1)
407 return -EINVAL;
408 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
409 POWER_LPRX_RSSI_THRESHOLD_MIN)
410 return -EINVAL;
411 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
412 } else if (!strncmp("snooze_enable=", buf, 14)) {
413 if (sscanf(buf + 14, "%d", &val) != 1)
414 return -EINVAL;
415 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
416 } else {
417 return -EINVAL;
418 }
419
420 mutex_lock(&mvm->mutex);
421 iwl_dbgfs_update_pm(mvm, vif, param, val);
422 ret = iwl_mvm_power_update_mode(mvm, vif);
423 mutex_unlock(&mvm->mutex);
424
425 return ret ?: count;
426 }
427
428 static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
429 char __user *user_buf,
430 size_t count, loff_t *ppos)
431 {
432 struct ieee80211_vif *vif = file->private_data;
433 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
434 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
435 char buf[512];
436 int bufsz = sizeof(buf);
437 int pos;
438
439 pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz);
440
441 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
442 }
443
444 static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
445 char __user *user_buf,
446 size_t count, loff_t *ppos)
447 {
448 struct ieee80211_vif *vif = file->private_data;
449 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
450 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
451 u8 ap_sta_id;
452 struct ieee80211_chanctx_conf *chanctx_conf;
453 char buf[512];
454 int bufsz = sizeof(buf);
455 int pos = 0;
456 int i;
457
458 mutex_lock(&mvm->mutex);
459
460 ap_sta_id = mvmvif->ap_sta_id;
461
462 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
463 mvmvif->id, mvmvif->color);
464 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
465 vif->bss_conf.bssid);
466 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
467 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
468 pos += scnprintf(buf+pos, bufsz-pos,
469 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
470 i, mvmvif->queue_params[i].txop,
471 mvmvif->queue_params[i].cw_min,
472 mvmvif->queue_params[i].cw_max,
473 mvmvif->queue_params[i].aifs,
474 mvmvif->queue_params[i].uapsd);
475 }
476
477 if (vif->type == NL80211_IFTYPE_STATION &&
478 ap_sta_id != IWL_MVM_STATION_COUNT) {
479 struct ieee80211_sta *sta;
480 struct iwl_mvm_sta *mvm_sta;
481
482 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
483 lockdep_is_held(&mvm->mutex));
484 mvm_sta = (void *)sta->drv_priv;
485 pos += scnprintf(buf+pos, bufsz-pos,
486 "ap_sta_id %d - reduced Tx power %d\n",
487 ap_sta_id, mvm_sta->bt_reduced_txpower);
488 }
489
490 rcu_read_lock();
491 chanctx_conf = rcu_dereference(vif->chanctx_conf);
492 if (chanctx_conf) {
493 pos += scnprintf(buf+pos, bufsz-pos,
494 "idle rx chains %d, active rx chains: %d\n",
495 chanctx_conf->rx_chains_static,
496 chanctx_conf->rx_chains_dynamic);
497 }
498 rcu_read_unlock();
499
500 mutex_unlock(&mvm->mutex);
501
502 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
503 }
504
505 #define BT_MBOX_MSG(_notif, _num, _field) \
506 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
507 >> BT_MBOX##_num##_##_field##_POS)
508
509
510 #define BT_MBOX_PRINT(_num, _field, _end) \
511 pos += scnprintf(buf + pos, bufsz - pos, \
512 "\t%s: %d%s", \
513 #_field, \
514 BT_MBOX_MSG(notif, _num, _field), \
515 true ? "\n" : ", ");
516
517 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
518 size_t count, loff_t *ppos)
519 {
520 struct iwl_mvm *mvm = file->private_data;
521 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
522 char *buf;
523 int ret, pos = 0, bufsz = sizeof(char) * 1024;
524
525 buf = kmalloc(bufsz, GFP_KERNEL);
526 if (!buf)
527 return -ENOMEM;
528
529 mutex_lock(&mvm->mutex);
530
531 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
532
533 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
534 BT_MBOX_PRINT(0, LE_PROF1, false);
535 BT_MBOX_PRINT(0, LE_PROF2, false);
536 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
537 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
538 BT_MBOX_PRINT(0, INBAND_S, false);
539 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
540 BT_MBOX_PRINT(0, LE_SCAN, false);
541 BT_MBOX_PRINT(0, LE_ADV, false);
542 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
543 BT_MBOX_PRINT(0, OPEN_CON_1, true);
544
545 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
546
547 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
548 BT_MBOX_PRINT(1, IP_SR, false);
549 BT_MBOX_PRINT(1, LE_MSTR, false);
550 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
551 BT_MBOX_PRINT(1, MSG_TYPE, false);
552 BT_MBOX_PRINT(1, SSN, true);
553
554 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
555
556 BT_MBOX_PRINT(2, SNIFF_ACT, false);
557 BT_MBOX_PRINT(2, PAG, false);
558 BT_MBOX_PRINT(2, INQUIRY, false);
559 BT_MBOX_PRINT(2, CONN, false);
560 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
561 BT_MBOX_PRINT(2, DISC, false);
562 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
563 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
564 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
565 BT_MBOX_PRINT(2, SCO_DURATION, true);
566
567 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
568
569 BT_MBOX_PRINT(3, SCO_STATE, false);
570 BT_MBOX_PRINT(3, SNIFF_STATE, false);
571 BT_MBOX_PRINT(3, A2DP_STATE, false);
572 BT_MBOX_PRINT(3, ACL_STATE, false);
573 BT_MBOX_PRINT(3, MSTR_STATE, false);
574 BT_MBOX_PRINT(3, OBX_STATE, false);
575 BT_MBOX_PRINT(3, OPEN_CON_2, false);
576 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
577 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
578 BT_MBOX_PRINT(3, INBAND_P, false);
579 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
580 BT_MBOX_PRINT(3, SSN_2, false);
581 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
582
583 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
584 notif->bt_status);
585 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
586 notif->bt_open_conn);
587 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
588 notif->bt_traffic_load);
589 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
590 notif->bt_agg_traffic_load);
591 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
592 notif->bt_ci_compliance);
593
594 mutex_unlock(&mvm->mutex);
595
596 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
597 kfree(buf);
598
599 return ret;
600 }
601 #undef BT_MBOX_PRINT
602
603 #define PRINT_STATS_LE32(_str, _val) \
604 pos += scnprintf(buf + pos, bufsz - pos, \
605 fmt_table, _str, \
606 le32_to_cpu(_val))
607
608 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
609 char __user *user_buf, size_t count,
610 loff_t *ppos)
611 {
612 struct iwl_mvm *mvm = file->private_data;
613 static const char *fmt_table = "\t%-30s %10u\n";
614 static const char *fmt_header = "%-32s\n";
615 int pos = 0;
616 char *buf;
617 int ret;
618 int bufsz = sizeof(struct mvm_statistics_rx_phy) * 20 +
619 sizeof(struct mvm_statistics_rx_non_phy) * 10 +
620 sizeof(struct mvm_statistics_rx_ht_phy) * 10 + 200;
621 struct mvm_statistics_rx_phy *ofdm;
622 struct mvm_statistics_rx_phy *cck;
623 struct mvm_statistics_rx_non_phy *general;
624 struct mvm_statistics_rx_ht_phy *ht;
625
626 buf = kzalloc(bufsz, GFP_KERNEL);
627 if (!buf)
628 return -ENOMEM;
629
630 mutex_lock(&mvm->mutex);
631
632 ofdm = &mvm->rx_stats.ofdm;
633 cck = &mvm->rx_stats.cck;
634 general = &mvm->rx_stats.general;
635 ht = &mvm->rx_stats.ofdm_ht;
636
637 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
638 "Statistics_Rx - OFDM");
639 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
640 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
641 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
642 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
643 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
644 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
645 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
646 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
647 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
648 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
649 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
650 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
651 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
652 ofdm->rxe_frame_limit_overrun);
653 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
654 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
655 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
656 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
657 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
658 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
659 PRINT_STATS_LE32("reserved", ofdm->reserved);
660
661 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
662 "Statistics_Rx - CCK");
663 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
664 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
665 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
666 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
667 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
668 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
669 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
670 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
671 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
672 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
673 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
674 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
675 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
676 cck->rxe_frame_limit_overrun);
677 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
678 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
679 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
680 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
681 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
682 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
683 PRINT_STATS_LE32("reserved", cck->reserved);
684
685 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
686 "Statistics_Rx - GENERAL");
687 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
688 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
689 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
690 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
691 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
692 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
693 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
694 PRINT_STATS_LE32("adc_rx_saturation_time",
695 general->adc_rx_saturation_time);
696 PRINT_STATS_LE32("ina_detection_search_time",
697 general->ina_detection_search_time);
698 PRINT_STATS_LE32("beacon_silence_rssi_a",
699 general->beacon_silence_rssi_a);
700 PRINT_STATS_LE32("beacon_silence_rssi_b",
701 general->beacon_silence_rssi_b);
702 PRINT_STATS_LE32("beacon_silence_rssi_c",
703 general->beacon_silence_rssi_c);
704 PRINT_STATS_LE32("interference_data_flag",
705 general->interference_data_flag);
706 PRINT_STATS_LE32("channel_load", general->channel_load);
707 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
708 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
709 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
710 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
711 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
712 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
713 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
714 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
715 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
716
717 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
718 "Statistics_Rx - HT");
719 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
720 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
721 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
722 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
723 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
724 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
725 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
726 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
727 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
728 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
729
730 mutex_unlock(&mvm->mutex);
731
732 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
733 kfree(buf);
734
735 return ret;
736 }
737 #undef PRINT_STAT_LE32
738
739 static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
740 const char __user *user_buf,
741 size_t count, loff_t *ppos)
742 {
743 struct iwl_mvm *mvm = file->private_data;
744 int ret;
745
746 mutex_lock(&mvm->mutex);
747
748 /* allow one more restart that we're provoking here */
749 if (mvm->restart_fw >= 0)
750 mvm->restart_fw++;
751
752 /* take the return value to make compiler happy - it will fail anyway */
753 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
754
755 mutex_unlock(&mvm->mutex);
756
757 return count;
758 }
759
760 static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
761 enum iwl_dbgfs_bf_mask param, int value)
762 {
763 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
764 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
765
766 dbgfs_bf->mask |= param;
767
768 switch (param) {
769 case MVM_DEBUGFS_BF_ENERGY_DELTA:
770 dbgfs_bf->bf_energy_delta = value;
771 break;
772 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
773 dbgfs_bf->bf_roaming_energy_delta = value;
774 break;
775 case MVM_DEBUGFS_BF_ROAMING_STATE:
776 dbgfs_bf->bf_roaming_state = value;
777 break;
778 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
779 dbgfs_bf->bf_temp_threshold = value;
780 break;
781 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
782 dbgfs_bf->bf_temp_fast_filter = value;
783 break;
784 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
785 dbgfs_bf->bf_temp_slow_filter = value;
786 break;
787 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
788 dbgfs_bf->bf_enable_beacon_filter = value;
789 break;
790 case MVM_DEBUGFS_BF_DEBUG_FLAG:
791 dbgfs_bf->bf_debug_flag = value;
792 break;
793 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
794 dbgfs_bf->bf_escape_timer = value;
795 break;
796 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
797 dbgfs_bf->ba_enable_beacon_abort = value;
798 break;
799 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
800 dbgfs_bf->ba_escape_timer = value;
801 break;
802 }
803 }
804
805 static ssize_t iwl_dbgfs_bf_params_write(struct file *file,
806 const char __user *user_buf,
807 size_t count, loff_t *ppos)
808 {
809 struct ieee80211_vif *vif = file->private_data;
810 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
811 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
812 enum iwl_dbgfs_bf_mask param;
813 char buf[256];
814 int buf_size;
815 int value;
816 int ret = 0;
817
818 memset(buf, 0, sizeof(buf));
819 buf_size = min(count, sizeof(buf) - 1);
820 if (copy_from_user(buf, user_buf, buf_size))
821 return -EFAULT;
822
823 if (!strncmp("bf_energy_delta=", buf, 16)) {
824 if (sscanf(buf+16, "%d", &value) != 1)
825 return -EINVAL;
826 if (value < IWL_BF_ENERGY_DELTA_MIN ||
827 value > IWL_BF_ENERGY_DELTA_MAX)
828 return -EINVAL;
829 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
830 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
831 if (sscanf(buf+24, "%d", &value) != 1)
832 return -EINVAL;
833 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
834 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
835 return -EINVAL;
836 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
837 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
838 if (sscanf(buf+17, "%d", &value) != 1)
839 return -EINVAL;
840 if (value < IWL_BF_ROAMING_STATE_MIN ||
841 value > IWL_BF_ROAMING_STATE_MAX)
842 return -EINVAL;
843 param = MVM_DEBUGFS_BF_ROAMING_STATE;
844 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
845 if (sscanf(buf+18, "%d", &value) != 1)
846 return -EINVAL;
847 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
848 value > IWL_BF_TEMP_THRESHOLD_MAX)
849 return -EINVAL;
850 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
851 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
852 if (sscanf(buf+20, "%d", &value) != 1)
853 return -EINVAL;
854 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
855 value > IWL_BF_TEMP_FAST_FILTER_MAX)
856 return -EINVAL;
857 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
858 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
859 if (sscanf(buf+20, "%d", &value) != 1)
860 return -EINVAL;
861 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
862 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
863 return -EINVAL;
864 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
865 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
866 if (sscanf(buf+24, "%d", &value) != 1)
867 return -EINVAL;
868 if (value < 0 || value > 1)
869 return -EINVAL;
870 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
871 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
872 if (sscanf(buf+14, "%d", &value) != 1)
873 return -EINVAL;
874 if (value < 0 || value > 1)
875 return -EINVAL;
876 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
877 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
878 if (sscanf(buf+16, "%d", &value) != 1)
879 return -EINVAL;
880 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
881 value > IWL_BF_ESCAPE_TIMER_MAX)
882 return -EINVAL;
883 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
884 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
885 if (sscanf(buf+16, "%d", &value) != 1)
886 return -EINVAL;
887 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
888 value > IWL_BA_ESCAPE_TIMER_MAX)
889 return -EINVAL;
890 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
891 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
892 if (sscanf(buf+23, "%d", &value) != 1)
893 return -EINVAL;
894 if (value < 0 || value > 1)
895 return -EINVAL;
896 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
897 } else {
898 return -EINVAL;
899 }
900
901 mutex_lock(&mvm->mutex);
902 iwl_dbgfs_update_bf(vif, param, value);
903 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) {
904 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
905 } else {
906 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
907 }
908 mutex_unlock(&mvm->mutex);
909
910 return ret ?: count;
911 }
912
913 static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
914 char __user *user_buf,
915 size_t count, loff_t *ppos)
916 {
917 struct ieee80211_vif *vif = file->private_data;
918 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
919 char buf[256];
920 int pos = 0;
921 const size_t bufsz = sizeof(buf);
922 struct iwl_beacon_filter_cmd cmd = {
923 IWL_BF_CMD_CONFIG_DEFAULTS,
924 .bf_enable_beacon_filter =
925 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
926 .ba_enable_beacon_abort =
927 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
928 };
929
930 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
931 if (mvmvif->bf_data.bf_enabled)
932 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
933 else
934 cmd.bf_enable_beacon_filter = 0;
935
936 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
937 le32_to_cpu(cmd.bf_energy_delta));
938 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
939 le32_to_cpu(cmd.bf_roaming_energy_delta));
940 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
941 le32_to_cpu(cmd.bf_roaming_state));
942 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
943 le32_to_cpu(cmd.bf_temp_threshold));
944 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
945 le32_to_cpu(cmd.bf_temp_fast_filter));
946 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
947 le32_to_cpu(cmd.bf_temp_slow_filter));
948 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
949 le32_to_cpu(cmd.bf_enable_beacon_filter));
950 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
951 le32_to_cpu(cmd.bf_debug_flag));
952 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
953 le32_to_cpu(cmd.bf_escape_timer));
954 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
955 le32_to_cpu(cmd.ba_escape_timer));
956 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
957 le32_to_cpu(cmd.ba_enable_beacon_abort));
958
959 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
960 }
961
962 #ifdef CONFIG_PM_SLEEP
963 static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
964 const char __user *user_buf,
965 size_t count, loff_t *ppos)
966 {
967 struct iwl_mvm *mvm = file->private_data;
968 char buf[8] = {};
969 int store;
970
971 if (copy_from_user(buf, user_buf, sizeof(buf)))
972 return -EFAULT;
973
974 if (sscanf(buf, "%d", &store) != 1)
975 return -EINVAL;
976
977 mvm->store_d3_resume_sram = store;
978
979 return count;
980 }
981
982 static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
983 size_t count, loff_t *ppos)
984 {
985 struct iwl_mvm *mvm = file->private_data;
986 const struct fw_img *img;
987 int ofs, len, pos = 0;
988 size_t bufsz, ret;
989 char *buf;
990 u8 *ptr = mvm->d3_resume_sram;
991
992 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
993 len = img->sec[IWL_UCODE_SECTION_DATA].len;
994
995 bufsz = len * 4 + 256;
996 buf = kzalloc(bufsz, GFP_KERNEL);
997 if (!buf)
998 return -ENOMEM;
999
1000 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1001 mvm->store_d3_resume_sram ? "en" : "dis");
1002
1003 if (ptr) {
1004 for (ofs = 0; ofs < len; ofs += 16) {
1005 pos += scnprintf(buf + pos, bufsz - pos,
1006 "0x%.4x ", ofs);
1007 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1008 bufsz - pos, false);
1009 pos += strlen(buf + pos);
1010 if (bufsz - pos > 0)
1011 buf[pos++] = '\n';
1012 }
1013 } else {
1014 pos += scnprintf(buf + pos, bufsz - pos,
1015 "(no data captured)\n");
1016 }
1017
1018 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1019
1020 kfree(buf);
1021
1022 return ret;
1023 }
1024 #endif
1025
1026 #define MVM_DEBUGFS_READ_FILE_OPS(name) \
1027 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1028 .read = iwl_dbgfs_##name##_read, \
1029 .open = simple_open, \
1030 .llseek = generic_file_llseek, \
1031 }
1032
1033 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
1034 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1035 .write = iwl_dbgfs_##name##_write, \
1036 .read = iwl_dbgfs_##name##_read, \
1037 .open = simple_open, \
1038 .llseek = generic_file_llseek, \
1039 };
1040
1041 #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
1042 static const struct file_operations iwl_dbgfs_##name##_ops = { \
1043 .write = iwl_dbgfs_##name##_write, \
1044 .open = simple_open, \
1045 .llseek = generic_file_llseek, \
1046 };
1047
1048 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
1049 if (!debugfs_create_file(#name, mode, parent, mvm, \
1050 &iwl_dbgfs_##name##_ops)) \
1051 goto err; \
1052 } while (0)
1053
1054 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1055 if (!debugfs_create_file(#name, mode, parent, vif, \
1056 &iwl_dbgfs_##name##_ops)) \
1057 goto err; \
1058 } while (0)
1059
1060 /* Device wide debugfs entries */
1061 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
1062 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
1063 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
1064 MVM_DEBUGFS_READ_FILE_OPS(stations);
1065 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1066 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
1067 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
1068 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1069 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
1070 #ifdef CONFIG_PM_SLEEP
1071 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
1072 #endif
1073
1074 /* Interface specific debugfs entries */
1075 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
1076 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
1077 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
1078
1079 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1080 {
1081 char buf[100];
1082
1083 mvm->debugfs_dir = dbgfs_dir;
1084
1085 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1086 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1087 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1088 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1089 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1090 MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
1091 MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
1092 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1093 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1094 #ifdef CONFIG_PM_SLEEP
1095 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1096 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1097 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1098 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1099 goto err;
1100 #endif
1101
1102 /*
1103 * Create a symlink with mac80211. It will be removed when mac80211
1104 * exists (before the opmode exists which removes the target.)
1105 */
1106 snprintf(buf, 100, "../../%s/%s",
1107 dbgfs_dir->d_parent->d_parent->d_name.name,
1108 dbgfs_dir->d_parent->d_name.name);
1109 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1110 goto err;
1111
1112 return 0;
1113 err:
1114 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1115 return -ENOMEM;
1116 }
1117
1118 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1119 {
1120 struct dentry *dbgfs_dir = vif->debugfs_dir;
1121 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1122 char buf[100];
1123
1124 /*
1125 * Check if debugfs directory already exist before creating it.
1126 * This may happen when, for example, resetting hw or suspend-resume
1127 */
1128 if (!dbgfs_dir || mvmvif->dbgfs_dir)
1129 return;
1130
1131 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1132 mvmvif->dbgfs_data = mvm;
1133
1134 if (!mvmvif->dbgfs_dir) {
1135 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
1136 dbgfs_dir->d_name.name);
1137 return;
1138 }
1139
1140 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1141 vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
1142 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1143 S_IRUSR);
1144
1145 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
1146 S_IRUSR);
1147
1148 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1149 mvmvif == mvm->bf_allowed_vif)
1150 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1151 S_IRUSR | S_IWUSR);
1152
1153 /*
1154 * Create symlink for convenience pointing to interface specific
1155 * debugfs entries for the driver. For example, under
1156 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1157 * find
1158 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1159 */
1160 snprintf(buf, 100, "../../../%s/%s/%s/%s",
1161 dbgfs_dir->d_parent->d_parent->d_name.name,
1162 dbgfs_dir->d_parent->d_name.name,
1163 dbgfs_dir->d_name.name,
1164 mvmvif->dbgfs_dir->d_name.name);
1165
1166 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1167 mvm->debugfs_dir, buf);
1168 if (!mvmvif->dbgfs_slink)
1169 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
1170 dbgfs_dir->d_name.name);
1171 return;
1172 err:
1173 IWL_ERR(mvm, "Can't create debugfs entity\n");
1174 }
1175
1176 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1177 {
1178 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1179
1180 debugfs_remove(mvmvif->dbgfs_slink);
1181 mvmvif->dbgfs_slink = NULL;
1182
1183 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1184 mvmvif->dbgfs_dir = NULL;
1185 }
This page took 0.056467 seconds and 6 git commands to generate.