blob: 26c53b37007e702a88d50a67dc1e7eaaa7947c60 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
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
67struct iwl_dbgfs_mvm_ctx {
68 struct iwl_mvm *mvm;
69 struct ieee80211_vif *vif;
70};
71
Johannes Berg8ca151b2013-01-24 14:25:36 +010072static 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
102static 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
138static 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
Johannes Berg60191d92013-05-15 13:08:51 +0200148 if (!mvm->ucode_loaded)
149 return -EINVAL;
150
Johannes Berg8ca151b2013-01-24 14:25:36 +0100151 /* default is to dump the entire data segment */
152 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100153 img = &mvm->fw->img[mvm->cur_ucode];
Johannes Berg60191d92013-05-15 13:08:51 +0200154 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;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160
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);
Johannes Berg60191d92013-05-15 13:08:51 +0200173 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100174
Johannes Berg60191d92013-05-15 13:08:51 +0200175 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176 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
193static 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
220static 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
249static 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
Djalal Harouni0e9d84e2013-08-24 14:35:53 +0100260 count = min_t(size_t, count, sizeof(buf) - 1);
261 if (copy_from_user(buf, user_buf, count))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100262 return -EFAULT;
263
264 if (sscanf(buf, "%d", &allow) != 1)
265 return -EINVAL;
266
267 IWL_DEBUG_POWER(mvm, "%s device power down\n",
268 allow ? "allow" : "prevent");
269
270 /*
271 * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
272 */
273
274 return count;
275}
276
277static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file,
278 const char __user *user_buf,
279 size_t count, loff_t *ppos)
280{
281 struct iwl_mvm *mvm = file->private_data;
282 char buf[8] = {};
283 int allow;
284
Djalal Harouni0e9d84e2013-08-24 14:35:53 +0100285 count = min_t(size_t, count, sizeof(buf) - 1);
286 if (copy_from_user(buf, user_buf, count))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100287 return -EFAULT;
288
289 if (sscanf(buf, "%d", &allow) != 1)
290 return -EINVAL;
291
292 IWL_DEBUG_POWER(mvm, "%s device power down in d3\n",
293 allow ? "allow" : "prevent");
294
295 /*
296 * TODO: When WoWLAN FW alive notification happens, driver will send
297 * REPLY_DEBUG_CMD setting power_down_allow flag according to
298 * mvm->prevent_power_down_d3
299 */
300 mvm->prevent_power_down_d3 = !allow;
301
302 return count;
303}
304
Alexander Bondarb571a692013-05-21 14:49:09 +0300305static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
306 struct ieee80211_vif *vif,
307 enum iwl_dbgfs_pm_mask param, int val)
308{
309 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
310 struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
311
312 dbgfs_pm->mask |= param;
313
314 switch (param) {
315 case MVM_DEBUGFS_PM_KEEP_ALIVE: {
316 struct ieee80211_hw *hw = mvm->hw;
317 int dtimper = hw->conf.ps_dtim_period ?: 1;
318 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
319
320 IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
321 if (val * MSEC_PER_SEC < 3 * dtimper_msec) {
322 IWL_WARN(mvm,
323 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
324 val * MSEC_PER_SEC, 3 * dtimper_msec);
325 }
326 dbgfs_pm->keep_alive_seconds = val;
327 break;
328 }
329 case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
330 IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
331 val ? "enabled" : "disabled");
332 dbgfs_pm->skip_over_dtim = val;
333 break;
334 case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
335 IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
336 dbgfs_pm->skip_dtim_periods = val;
337 break;
338 case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
339 IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
340 dbgfs_pm->rx_data_timeout = val;
341 break;
342 case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
343 IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
344 dbgfs_pm->tx_data_timeout = val;
345 break;
346 case MVM_DEBUGFS_PM_DISABLE_POWER_OFF:
347 IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val);
348 dbgfs_pm->disable_power_off = val;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200349 case MVM_DEBUGFS_PM_LPRX_ENA:
350 IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
351 dbgfs_pm->lprx_ena = val;
352 break;
353 case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
354 IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
355 dbgfs_pm->lprx_rssi_threshold = val;
Alexander Bondarb571a692013-05-21 14:49:09 +0300356 break;
Alexander Bondar89716342013-08-04 17:52:23 +0300357 case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
358 IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
359 dbgfs_pm->snooze_ena = val;
360 break;
Alexander Bondarb571a692013-05-21 14:49:09 +0300361 }
362}
363
364static ssize_t iwl_dbgfs_pm_params_write(struct file *file,
365 const char __user *user_buf,
366 size_t count, loff_t *ppos)
367{
368 struct ieee80211_vif *vif = file->private_data;
369 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
370 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
371 enum iwl_dbgfs_pm_mask param;
372 char buf[32] = {};
373 int val;
374 int ret;
375
Djalal Harouni0e9d84e2013-08-24 14:35:53 +0100376 count = min_t(size_t, count, sizeof(buf) - 1);
377 if (copy_from_user(buf, user_buf, count))
Alexander Bondarb571a692013-05-21 14:49:09 +0300378 return -EFAULT;
379
380 if (!strncmp("keep_alive=", buf, 11)) {
381 if (sscanf(buf + 11, "%d", &val) != 1)
382 return -EINVAL;
383 param = MVM_DEBUGFS_PM_KEEP_ALIVE;
384 } else if (!strncmp("skip_over_dtim=", buf, 15)) {
385 if (sscanf(buf + 15, "%d", &val) != 1)
386 return -EINVAL;
387 param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
388 } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
389 if (sscanf(buf + 18, "%d", &val) != 1)
390 return -EINVAL;
391 param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
392 } else if (!strncmp("rx_data_timeout=", buf, 16)) {
393 if (sscanf(buf + 16, "%d", &val) != 1)
394 return -EINVAL;
395 param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
396 } else if (!strncmp("tx_data_timeout=", buf, 16)) {
397 if (sscanf(buf + 16, "%d", &val) != 1)
398 return -EINVAL;
399 param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
400 } else if (!strncmp("disable_power_off=", buf, 18)) {
401 if (sscanf(buf + 18, "%d", &val) != 1)
402 return -EINVAL;
403 param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200404 } else if (!strncmp("lprx=", buf, 5)) {
405 if (sscanf(buf + 5, "%d", &val) != 1)
406 return -EINVAL;
407 param = MVM_DEBUGFS_PM_LPRX_ENA;
408 } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
409 if (sscanf(buf + 20, "%d", &val) != 1)
410 return -EINVAL;
411 if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
412 POWER_LPRX_RSSI_THRESHOLD_MIN)
413 return -EINVAL;
414 param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
Alexander Bondar89716342013-08-04 17:52:23 +0300415 } else if (!strncmp("snooze_enable=", buf, 14)) {
416 if (sscanf(buf + 14, "%d", &val) != 1)
417 return -EINVAL;
418 param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
Alexander Bondarb571a692013-05-21 14:49:09 +0300419 } else {
420 return -EINVAL;
421 }
422
423 mutex_lock(&mvm->mutex);
424 iwl_dbgfs_update_pm(mvm, vif, param, val);
425 ret = iwl_mvm_power_update_mode(mvm, vif);
426 mutex_unlock(&mvm->mutex);
427
428 return ret ?: count;
429}
430
431static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
432 char __user *user_buf,
433 size_t count, loff_t *ppos)
434{
435 struct ieee80211_vif *vif = file->private_data;
436 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
437 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
Alexander Bondare3c588e2013-04-07 14:08:59 +0300438 char buf[512];
Alexander Bondarb571a692013-05-21 14:49:09 +0300439 int bufsz = sizeof(buf);
Alexander Bondare811ada2013-03-10 15:29:44 +0200440 int pos;
Alexander Bondarb571a692013-05-21 14:49:09 +0300441
Alexander Bondare811ada2013-03-10 15:29:44 +0200442 pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz);
Alexander Bondarb571a692013-05-21 14:49:09 +0300443
444 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
445}
446
Johannes Berg63494372013-03-26 10:47:53 +0100447static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
448 char __user *user_buf,
449 size_t count, loff_t *ppos)
450{
451 struct ieee80211_vif *vif = file->private_data;
452 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
453 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
454 u8 ap_sta_id;
455 struct ieee80211_chanctx_conf *chanctx_conf;
456 char buf[512];
457 int bufsz = sizeof(buf);
458 int pos = 0;
459 int i;
460
461 mutex_lock(&mvm->mutex);
462
463 ap_sta_id = mvmvif->ap_sta_id;
464
465 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
466 mvmvif->id, mvmvif->color);
467 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
468 vif->bss_conf.bssid);
469 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
470 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
471 pos += scnprintf(buf+pos, bufsz-pos,
472 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
473 i, mvmvif->queue_params[i].txop,
474 mvmvif->queue_params[i].cw_min,
475 mvmvif->queue_params[i].cw_max,
476 mvmvif->queue_params[i].aifs,
477 mvmvif->queue_params[i].uapsd);
478 }
479
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200480 if (vif->type == NL80211_IFTYPE_STATION &&
481 ap_sta_id != IWL_MVM_STATION_COUNT) {
482 struct ieee80211_sta *sta;
483 struct iwl_mvm_sta *mvm_sta;
484
485 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
486 lockdep_is_held(&mvm->mutex));
487 mvm_sta = (void *)sta->drv_priv;
488 pos += scnprintf(buf+pos, bufsz-pos,
489 "ap_sta_id %d - reduced Tx power %d\n",
490 ap_sta_id, mvm_sta->bt_reduced_txpower);
491 }
Johannes Berg63494372013-03-26 10:47:53 +0100492
493 rcu_read_lock();
494 chanctx_conf = rcu_dereference(vif->chanctx_conf);
495 if (chanctx_conf) {
496 pos += scnprintf(buf+pos, bufsz-pos,
497 "idle rx chains %d, active rx chains: %d\n",
498 chanctx_conf->rx_chains_static,
499 chanctx_conf->rx_chains_dynamic);
500 }
501 rcu_read_unlock();
502
503 mutex_unlock(&mvm->mutex);
504
505 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
506}
507
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200508#define BT_MBOX_MSG(_notif, _num, _field) \
509 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
510 >> BT_MBOX##_num##_##_field##_POS)
511
512
513#define BT_MBOX_PRINT(_num, _field, _end) \
514 pos += scnprintf(buf + pos, bufsz - pos, \
515 "\t%s: %d%s", \
516 #_field, \
517 BT_MBOX_MSG(notif, _num, _field), \
518 true ? "\n" : ", ");
519
520static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
521 size_t count, loff_t *ppos)
522{
523 struct iwl_mvm *mvm = file->private_data;
524 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
525 char *buf;
526 int ret, pos = 0, bufsz = sizeof(char) * 1024;
527
528 buf = kmalloc(bufsz, GFP_KERNEL);
529 if (!buf)
530 return -ENOMEM;
531
532 mutex_lock(&mvm->mutex);
533
534 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
535
536 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
537 BT_MBOX_PRINT(0, LE_PROF1, false);
538 BT_MBOX_PRINT(0, LE_PROF2, false);
539 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
540 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
541 BT_MBOX_PRINT(0, INBAND_S, false);
542 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
543 BT_MBOX_PRINT(0, LE_SCAN, false);
544 BT_MBOX_PRINT(0, LE_ADV, false);
545 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
546 BT_MBOX_PRINT(0, OPEN_CON_1, true);
547
548 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
549
550 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
551 BT_MBOX_PRINT(1, IP_SR, false);
552 BT_MBOX_PRINT(1, LE_MSTR, false);
553 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
554 BT_MBOX_PRINT(1, MSG_TYPE, false);
555 BT_MBOX_PRINT(1, SSN, true);
556
557 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
558
559 BT_MBOX_PRINT(2, SNIFF_ACT, false);
560 BT_MBOX_PRINT(2, PAG, false);
561 BT_MBOX_PRINT(2, INQUIRY, false);
562 BT_MBOX_PRINT(2, CONN, false);
563 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
564 BT_MBOX_PRINT(2, DISC, false);
565 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
566 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
567 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
568 BT_MBOX_PRINT(2, SCO_DURATION, true);
569
570 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
571
572 BT_MBOX_PRINT(3, SCO_STATE, false);
573 BT_MBOX_PRINT(3, SNIFF_STATE, false);
574 BT_MBOX_PRINT(3, A2DP_STATE, false);
575 BT_MBOX_PRINT(3, ACL_STATE, false);
576 BT_MBOX_PRINT(3, MSTR_STATE, false);
577 BT_MBOX_PRINT(3, OBX_STATE, false);
578 BT_MBOX_PRINT(3, OPEN_CON_2, false);
579 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
580 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
581 BT_MBOX_PRINT(3, INBAND_P, false);
582 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
583 BT_MBOX_PRINT(3, SSN_2, false);
584 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
585
586 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
587 notif->bt_status);
588 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
589 notif->bt_open_conn);
590 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
591 notif->bt_traffic_load);
592 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
593 notif->bt_agg_traffic_load);
594 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
595 notif->bt_ci_compliance);
596
597 mutex_unlock(&mvm->mutex);
598
599 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
600 kfree(buf);
601
602 return ret;
603}
604#undef BT_MBOX_PRINT
605
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300606#define PRINT_STATS_LE32(_str, _val) \
607 pos += scnprintf(buf + pos, bufsz - pos, \
608 fmt_table, _str, \
609 le32_to_cpu(_val))
610
611static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
612 char __user *user_buf, size_t count,
613 loff_t *ppos)
614{
615 struct iwl_mvm *mvm = file->private_data;
616 static const char *fmt_table = "\t%-30s %10u\n";
617 static const char *fmt_header = "%-32s\n";
618 int pos = 0;
619 char *buf;
620 int ret;
621 int bufsz = sizeof(struct mvm_statistics_rx_phy) * 20 +
622 sizeof(struct mvm_statistics_rx_non_phy) * 10 +
623 sizeof(struct mvm_statistics_rx_ht_phy) * 10 + 200;
624 struct mvm_statistics_rx_phy *ofdm;
625 struct mvm_statistics_rx_phy *cck;
626 struct mvm_statistics_rx_non_phy *general;
627 struct mvm_statistics_rx_ht_phy *ht;
628
629 buf = kzalloc(bufsz, GFP_KERNEL);
630 if (!buf)
631 return -ENOMEM;
632
633 mutex_lock(&mvm->mutex);
634
635 ofdm = &mvm->rx_stats.ofdm;
636 cck = &mvm->rx_stats.cck;
637 general = &mvm->rx_stats.general;
638 ht = &mvm->rx_stats.ofdm_ht;
639
640 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
641 "Statistics_Rx - OFDM");
642 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
643 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
644 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
645 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
646 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
647 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
648 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
649 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
650 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
651 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
652 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
653 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
654 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
655 ofdm->rxe_frame_limit_overrun);
656 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
657 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
658 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
659 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
660 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
661 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
662 PRINT_STATS_LE32("reserved", ofdm->reserved);
663
664 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
665 "Statistics_Rx - CCK");
666 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
667 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
668 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
669 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
670 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
671 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
672 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
673 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
674 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
675 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
676 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
677 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
678 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
679 cck->rxe_frame_limit_overrun);
680 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
681 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
682 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
683 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
684 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
685 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
686 PRINT_STATS_LE32("reserved", cck->reserved);
687
688 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
689 "Statistics_Rx - GENERAL");
690 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
691 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
692 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
693 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
694 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
695 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
696 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
697 PRINT_STATS_LE32("adc_rx_saturation_time",
698 general->adc_rx_saturation_time);
699 PRINT_STATS_LE32("ina_detection_search_time",
700 general->ina_detection_search_time);
701 PRINT_STATS_LE32("beacon_silence_rssi_a",
702 general->beacon_silence_rssi_a);
703 PRINT_STATS_LE32("beacon_silence_rssi_b",
704 general->beacon_silence_rssi_b);
705 PRINT_STATS_LE32("beacon_silence_rssi_c",
706 general->beacon_silence_rssi_c);
707 PRINT_STATS_LE32("interference_data_flag",
708 general->interference_data_flag);
709 PRINT_STATS_LE32("channel_load", general->channel_load);
710 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
711 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
712 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
713 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
714 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
715 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
716 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
717 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
718 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
719
720 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
721 "Statistics_Rx - HT");
722 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
723 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
724 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
725 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
726 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
727 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
728 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
729 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
730 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
731 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
732
733 mutex_unlock(&mvm->mutex);
734
735 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
736 kfree(buf);
737
738 return ret;
739}
740#undef PRINT_STAT_LE32
741
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200742static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
743 const char __user *user_buf,
744 size_t count, loff_t *ppos)
745{
746 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200747 int ret;
748
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200749 mutex_lock(&mvm->mutex);
750
Eran Harary291aa7c2013-07-03 11:00:06 +0300751 /* allow one more restart that we're provoking here */
752 if (mvm->restart_fw >= 0)
753 mvm->restart_fw++;
754
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200755 /* take the return value to make compiler happy - it will fail anyway */
756 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
757
758 mutex_unlock(&mvm->mutex);
759
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200760 return count;
761}
762
Oren Givon91b05d12013-08-19 08:36:48 +0300763static ssize_t
764iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
765 char __user *user_buf,
766 size_t count, loff_t *ppos)
767{
768 struct iwl_mvm *mvm = file->private_data;
769 int pos = 0;
770 char buf[32];
771 const size_t bufsz = sizeof(buf);
772
773 /* print which antennas were set for the scan command by the user */
774 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
775 if (mvm->scan_rx_ant & ANT_A)
776 pos += scnprintf(buf + pos, bufsz - pos, "A");
777 if (mvm->scan_rx_ant & ANT_B)
778 pos += scnprintf(buf + pos, bufsz - pos, "B");
779 if (mvm->scan_rx_ant & ANT_C)
780 pos += scnprintf(buf + pos, bufsz - pos, "C");
781 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
782
783 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
784}
785
786static ssize_t
787iwl_dbgfs_scan_ant_rxchain_write(struct file *file,
788 const char __user *user_buf,
789 size_t count, loff_t *ppos)
790{
791 struct iwl_mvm *mvm = file->private_data;
792 char buf[8];
793 int buf_size;
794 u8 scan_rx_ant;
795
796 memset(buf, 0, sizeof(buf));
797 buf_size = min(count, sizeof(buf) - 1);
798
799 /* get the argument from the user and check if it is valid */
800 if (copy_from_user(buf, user_buf, buf_size))
801 return -EFAULT;
802 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
803 return -EINVAL;
804 if (scan_rx_ant > ANT_ABC)
805 return -EINVAL;
806 if (scan_rx_ant & ~iwl_fw_valid_rx_ant(mvm->fw))
807 return -EINVAL;
808
809 /* change the rx antennas for scan command */
810 mvm->scan_rx_ant = scan_rx_ant;
811
812 return count;
813}
814
815
Alexander Bondarb571a692013-05-21 14:49:09 +0300816static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
817 enum iwl_dbgfs_bf_mask param, int value)
818{
819 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
820 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
821
822 dbgfs_bf->mask |= param;
823
824 switch (param) {
825 case MVM_DEBUGFS_BF_ENERGY_DELTA:
826 dbgfs_bf->bf_energy_delta = value;
827 break;
828 case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
829 dbgfs_bf->bf_roaming_energy_delta = value;
830 break;
831 case MVM_DEBUGFS_BF_ROAMING_STATE:
832 dbgfs_bf->bf_roaming_state = value;
833 break;
Hila Gonen5dca7c22013-07-16 11:15:35 +0300834 case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
835 dbgfs_bf->bf_temp_threshold = value;
836 break;
837 case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
838 dbgfs_bf->bf_temp_fast_filter = value;
839 break;
840 case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
841 dbgfs_bf->bf_temp_slow_filter = value;
Alexander Bondarb571a692013-05-21 14:49:09 +0300842 break;
843 case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
844 dbgfs_bf->bf_enable_beacon_filter = value;
845 break;
846 case MVM_DEBUGFS_BF_DEBUG_FLAG:
847 dbgfs_bf->bf_debug_flag = value;
848 break;
849 case MVM_DEBUGFS_BF_ESCAPE_TIMER:
850 dbgfs_bf->bf_escape_timer = value;
851 break;
852 case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
853 dbgfs_bf->ba_enable_beacon_abort = value;
854 break;
855 case MVM_DEBUGFS_BA_ESCAPE_TIMER:
856 dbgfs_bf->ba_escape_timer = value;
857 break;
858 }
859}
860
861static ssize_t iwl_dbgfs_bf_params_write(struct file *file,
862 const char __user *user_buf,
863 size_t count, loff_t *ppos)
864{
865 struct ieee80211_vif *vif = file->private_data;
866 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
867 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
868 enum iwl_dbgfs_bf_mask param;
869 char buf[256];
870 int buf_size;
871 int value;
872 int ret = 0;
873
874 memset(buf, 0, sizeof(buf));
875 buf_size = min(count, sizeof(buf) - 1);
876 if (copy_from_user(buf, user_buf, buf_size))
877 return -EFAULT;
878
879 if (!strncmp("bf_energy_delta=", buf, 16)) {
880 if (sscanf(buf+16, "%d", &value) != 1)
881 return -EINVAL;
882 if (value < IWL_BF_ENERGY_DELTA_MIN ||
883 value > IWL_BF_ENERGY_DELTA_MAX)
884 return -EINVAL;
885 param = MVM_DEBUGFS_BF_ENERGY_DELTA;
886 } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
887 if (sscanf(buf+24, "%d", &value) != 1)
888 return -EINVAL;
889 if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
890 value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
891 return -EINVAL;
892 param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
893 } else if (!strncmp("bf_roaming_state=", buf, 17)) {
894 if (sscanf(buf+17, "%d", &value) != 1)
895 return -EINVAL;
896 if (value < IWL_BF_ROAMING_STATE_MIN ||
897 value > IWL_BF_ROAMING_STATE_MAX)
898 return -EINVAL;
899 param = MVM_DEBUGFS_BF_ROAMING_STATE;
Hila Gonen5dca7c22013-07-16 11:15:35 +0300900 } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
901 if (sscanf(buf+18, "%d", &value) != 1)
Alexander Bondarb571a692013-05-21 14:49:09 +0300902 return -EINVAL;
Hila Gonen5dca7c22013-07-16 11:15:35 +0300903 if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
904 value > IWL_BF_TEMP_THRESHOLD_MAX)
Alexander Bondarb571a692013-05-21 14:49:09 +0300905 return -EINVAL;
Hila Gonen5dca7c22013-07-16 11:15:35 +0300906 param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
907 } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
908 if (sscanf(buf+20, "%d", &value) != 1)
909 return -EINVAL;
910 if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
911 value > IWL_BF_TEMP_FAST_FILTER_MAX)
912 return -EINVAL;
913 param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
914 } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
915 if (sscanf(buf+20, "%d", &value) != 1)
916 return -EINVAL;
917 if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
918 value > IWL_BF_TEMP_SLOW_FILTER_MAX)
919 return -EINVAL;
920 param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
Alexander Bondarb571a692013-05-21 14:49:09 +0300921 } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
922 if (sscanf(buf+24, "%d", &value) != 1)
923 return -EINVAL;
924 if (value < 0 || value > 1)
925 return -EINVAL;
926 param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
927 } else if (!strncmp("bf_debug_flag=", buf, 14)) {
928 if (sscanf(buf+14, "%d", &value) != 1)
929 return -EINVAL;
930 if (value < 0 || value > 1)
931 return -EINVAL;
932 param = MVM_DEBUGFS_BF_DEBUG_FLAG;
933 } else if (!strncmp("bf_escape_timer=", buf, 16)) {
934 if (sscanf(buf+16, "%d", &value) != 1)
935 return -EINVAL;
936 if (value < IWL_BF_ESCAPE_TIMER_MIN ||
937 value > IWL_BF_ESCAPE_TIMER_MAX)
938 return -EINVAL;
939 param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
940 } else if (!strncmp("ba_escape_timer=", buf, 16)) {
941 if (sscanf(buf+16, "%d", &value) != 1)
942 return -EINVAL;
943 if (value < IWL_BA_ESCAPE_TIMER_MIN ||
944 value > IWL_BA_ESCAPE_TIMER_MAX)
945 return -EINVAL;
946 param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
947 } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
948 if (sscanf(buf+23, "%d", &value) != 1)
949 return -EINVAL;
950 if (value < 0 || value > 1)
951 return -EINVAL;
952 param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
953 } else {
954 return -EINVAL;
955 }
956
957 mutex_lock(&mvm->mutex);
958 iwl_dbgfs_update_bf(vif, param, value);
959 if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) {
960 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
961 } else {
Alexander Bondar495191c2013-08-05 14:16:45 +0300962 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
Alexander Bondarb571a692013-05-21 14:49:09 +0300963 }
964 mutex_unlock(&mvm->mutex);
965
966 return ret ?: count;
967}
968
969static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
970 char __user *user_buf,
971 size_t count, loff_t *ppos)
972{
973 struct ieee80211_vif *vif = file->private_data;
974 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
975 char buf[256];
976 int pos = 0;
977 const size_t bufsz = sizeof(buf);
978 struct iwl_beacon_filter_cmd cmd = {
Hila Gonen5dca7c22013-07-16 11:15:35 +0300979 IWL_BF_CMD_CONFIG_DEFAULTS,
980 .bf_enable_beacon_filter =
981 cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
982 .ba_enable_beacon_abort =
983 cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
Alexander Bondarb571a692013-05-21 14:49:09 +0300984 };
985
986 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300987 if (mvmvif->bf_data.bf_enabled)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300988 cmd.bf_enable_beacon_filter = cpu_to_le32(1);
Alexander Bondarb571a692013-05-21 14:49:09 +0300989 else
990 cmd.bf_enable_beacon_filter = 0;
991
992 pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +0300993 le32_to_cpu(cmd.bf_energy_delta));
Alexander Bondarb571a692013-05-21 14:49:09 +0300994 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +0300995 le32_to_cpu(cmd.bf_roaming_energy_delta));
Alexander Bondarb571a692013-05-21 14:49:09 +0300996 pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +0300997 le32_to_cpu(cmd.bf_roaming_state));
998 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
999 le32_to_cpu(cmd.bf_temp_threshold));
1000 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
1001 le32_to_cpu(cmd.bf_temp_fast_filter));
1002 pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
1003 le32_to_cpu(cmd.bf_temp_slow_filter));
Alexander Bondarb571a692013-05-21 14:49:09 +03001004 pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +03001005 le32_to_cpu(cmd.bf_enable_beacon_filter));
Alexander Bondarb571a692013-05-21 14:49:09 +03001006 pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +03001007 le32_to_cpu(cmd.bf_debug_flag));
Alexander Bondarb571a692013-05-21 14:49:09 +03001008 pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +03001009 le32_to_cpu(cmd.bf_escape_timer));
Alexander Bondarb571a692013-05-21 14:49:09 +03001010 pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +03001011 le32_to_cpu(cmd.ba_escape_timer));
Alexander Bondarb571a692013-05-21 14:49:09 +03001012 pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +03001013 le32_to_cpu(cmd.ba_enable_beacon_abort));
Alexander Bondarb571a692013-05-21 14:49:09 +03001014
1015 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1016}
1017
Johannes Bergafc66bb2013-05-03 11:44:16 +02001018#ifdef CONFIG_PM_SLEEP
1019static ssize_t iwl_dbgfs_d3_sram_write(struct file *file,
1020 const char __user *user_buf,
1021 size_t count, loff_t *ppos)
1022{
1023 struct iwl_mvm *mvm = file->private_data;
1024 char buf[8] = {};
1025 int store;
1026
Djalal Harouni0e9d84e2013-08-24 14:35:53 +01001027 count = min_t(size_t, count, sizeof(buf) - 1);
1028 if (copy_from_user(buf, user_buf, count))
Johannes Bergafc66bb2013-05-03 11:44:16 +02001029 return -EFAULT;
1030
1031 if (sscanf(buf, "%d", &store) != 1)
1032 return -EINVAL;
1033
1034 mvm->store_d3_resume_sram = store;
1035
1036 return count;
1037}
1038
1039static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1040 size_t count, loff_t *ppos)
1041{
1042 struct iwl_mvm *mvm = file->private_data;
1043 const struct fw_img *img;
1044 int ofs, len, pos = 0;
1045 size_t bufsz, ret;
1046 char *buf;
1047 u8 *ptr = mvm->d3_resume_sram;
1048
1049 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1050 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1051
1052 bufsz = len * 4 + 256;
1053 buf = kzalloc(bufsz, GFP_KERNEL);
1054 if (!buf)
1055 return -ENOMEM;
1056
1057 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1058 mvm->store_d3_resume_sram ? "en" : "dis");
1059
1060 if (ptr) {
1061 for (ofs = 0; ofs < len; ofs += 16) {
1062 pos += scnprintf(buf + pos, bufsz - pos,
1063 "0x%.4x ", ofs);
1064 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1065 bufsz - pos, false);
1066 pos += strlen(buf + pos);
1067 if (bufsz - pos > 0)
1068 buf[pos++] = '\n';
1069 }
1070 } else {
1071 pos += scnprintf(buf + pos, bufsz - pos,
1072 "(no data captured)\n");
1073 }
1074
1075 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1076
1077 kfree(buf);
1078
1079 return ret;
1080}
1081#endif
1082
Johannes Berg8ca151b2013-01-24 14:25:36 +01001083#define MVM_DEBUGFS_READ_FILE_OPS(name) \
1084static const struct file_operations iwl_dbgfs_##name##_ops = { \
1085 .read = iwl_dbgfs_##name##_read, \
Wei Yongjunba5295f2013-02-25 21:24:11 +08001086 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001087 .llseek = generic_file_llseek, \
1088}
1089
1090#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
1091static const struct file_operations iwl_dbgfs_##name##_ops = { \
1092 .write = iwl_dbgfs_##name##_write, \
1093 .read = iwl_dbgfs_##name##_read, \
Wei Yongjunba5295f2013-02-25 21:24:11 +08001094 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001095 .llseek = generic_file_llseek, \
1096};
1097
1098#define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
1099static const struct file_operations iwl_dbgfs_##name##_ops = { \
1100 .write = iwl_dbgfs_##name##_write, \
Wei Yongjunba5295f2013-02-25 21:24:11 +08001101 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001102 .llseek = generic_file_llseek, \
1103};
1104
1105#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
1106 if (!debugfs_create_file(#name, mode, parent, mvm, \
1107 &iwl_dbgfs_##name##_ops)) \
1108 goto err; \
1109 } while (0)
1110
1111#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
1112 if (!debugfs_create_file(#name, mode, parent, vif, \
1113 &iwl_dbgfs_##name##_ops)) \
1114 goto err; \
1115 } while (0)
1116
1117/* Device wide debugfs entries */
1118MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
1119MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
1120MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
1121MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001122MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001123MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
1124MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001125MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001126MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
Oren Givon91b05d12013-08-19 08:36:48 +03001127MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain);
1128
Johannes Bergafc66bb2013-05-03 11:44:16 +02001129#ifdef CONFIG_PM_SLEEP
1130MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram);
1131#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001132
Johannes Berg63494372013-03-26 10:47:53 +01001133/* Interface specific debugfs entries */
1134MVM_DEBUGFS_READ_FILE_OPS(mac_params);
Alexander Bondarb571a692013-05-21 14:49:09 +03001135MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params);
1136MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params);
Johannes Berg63494372013-03-26 10:47:53 +01001137
Johannes Berg8ca151b2013-01-24 14:25:36 +01001138int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1139{
1140 char buf[100];
1141
1142 mvm->debugfs_dir = dbgfs_dir;
1143
1144 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1145 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1146 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1147 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001148 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001149 MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
1150 MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001151 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001152 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001153 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1154 S_IWUSR | S_IRUSR);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001155#ifdef CONFIG_PM_SLEEP
1156 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001157 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001158 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1159 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1160 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001161#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001162
1163 /*
1164 * Create a symlink with mac80211. It will be removed when mac80211
1165 * exists (before the opmode exists which removes the target.)
1166 */
1167 snprintf(buf, 100, "../../%s/%s",
1168 dbgfs_dir->d_parent->d_parent->d_name.name,
1169 dbgfs_dir->d_parent->d_name.name);
1170 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1171 goto err;
1172
1173 return 0;
1174err:
1175 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1176 return -ENOMEM;
1177}
Johannes Berg63494372013-03-26 10:47:53 +01001178
1179void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1180{
1181 struct dentry *dbgfs_dir = vif->debugfs_dir;
1182 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1183 char buf[100];
1184
Alexander Bondar0ecb3762013-06-23 20:31:07 +03001185 /*
1186 * Check if debugfs directory already exist before creating it.
1187 * This may happen when, for example, resetting hw or suspend-resume
1188 */
1189 if (!dbgfs_dir || mvmvif->dbgfs_dir)
Johannes Berg63494372013-03-26 10:47:53 +01001190 return;
1191
1192 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
1193 mvmvif->dbgfs_data = mvm;
1194
1195 if (!mvmvif->dbgfs_dir) {
1196 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
1197 dbgfs_dir->d_name.name);
1198 return;
1199 }
1200
Alexander Bondarb571a692013-05-21 14:49:09 +03001201 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
1202 vif->type == NL80211_IFTYPE_STATION && !vif->p2p)
1203 MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR |
1204 S_IRUSR);
1205
Johannes Berg63494372013-03-26 10:47:53 +01001206 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
1207 S_IRUSR);
1208
Alexander Bondarb571a692013-05-21 14:49:09 +03001209 if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1210 mvmvif == mvm->bf_allowed_vif)
1211 MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir,
1212 S_IRUSR | S_IWUSR);
1213
Johannes Berg63494372013-03-26 10:47:53 +01001214 /*
1215 * Create symlink for convenience pointing to interface specific
1216 * debugfs entries for the driver. For example, under
1217 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
1218 * find
1219 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
1220 */
1221 snprintf(buf, 100, "../../../%s/%s/%s/%s",
1222 dbgfs_dir->d_parent->d_parent->d_name.name,
1223 dbgfs_dir->d_parent->d_name.name,
1224 dbgfs_dir->d_name.name,
1225 mvmvif->dbgfs_dir->d_name.name);
1226
1227 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
1228 mvm->debugfs_dir, buf);
1229 if (!mvmvif->dbgfs_slink)
1230 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
1231 dbgfs_dir->d_name.name);
1232 return;
1233err:
1234 IWL_ERR(mvm, "Can't create debugfs entity\n");
1235}
1236
1237void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1238{
1239 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1240
1241 debugfs_remove(mvmvif->dbgfs_slink);
1242 mvmvif->dbgfs_slink = NULL;
1243
1244 debugfs_remove_recursive(mvmvif->dbgfs_dir);
1245 mvmvif->dbgfs_dir = NULL;
1246}