blob: 5c0f93997b7be58df144fd70a6c4f0829a13165a [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eliad Pellerc7792732015-04-19 11:41:04 +03009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020029 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010030 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eliad Pellerc7792732015-04-19 11:41:04 +030035 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
Emmanuel Grumbach192c80a2014-03-19 08:25:05 +020065#include <linux/vmalloc.h>
66
Johannes Berg8ca151b2013-01-24 14:25:36 +010067#include "mvm.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020068#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010069#include "sta.h"
70#include "iwl-io.h"
Johannes Berg820a1a52013-11-12 16:58:41 +010071#include "debugfs.h"
Johannes Berg4d075002014-04-24 10:41:31 +020072#include "iwl-fw-error-dump.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010073
Johannes Berg1fa3f572013-11-13 09:10:21 +010074static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010075 size_t count, loff_t *ppos)
76{
Johannes Berg8a0bd162013-11-12 16:48:03 +010077 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +010078 u32 scd_q_msk;
79
80 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
81 return -EIO;
82
Johannes Berg8ca151b2013-01-24 14:25:36 +010083 if (sscanf(buf, "%x", &scd_q_msk) != 1)
84 return -EINVAL;
85
86 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
87
88 mutex_lock(&mvm->mutex);
Luca Coelho5888a402015-10-06 09:54:57 +030089 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +010090 mutex_unlock(&mvm->mutex);
91
92 return ret;
93}
94
Johannes Berg1fa3f572013-11-13 09:10:21 +010095static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +010096 size_t count, loff_t *ppos)
97{
Emmanuel Grumbachf327b042014-01-14 08:30:32 +020098 struct iwl_mvm_sta *mvmsta;
Johannes Berg8a0bd162013-11-12 16:48:03 +010099 int sta_id, drain, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100
101 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
102 return -EIO;
103
Johannes Berg8ca151b2013-01-24 14:25:36 +0100104 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
105 return -EINVAL;
Johannes Berg60765a42013-10-25 13:06:06 +0200106 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
107 return -EINVAL;
108 if (drain < 0 || drain > 1)
109 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110
111 mutex_lock(&mvm->mutex);
112
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200113 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
114
115 if (!mvmsta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116 ret = -ENOENT;
117 else
Emmanuel Grumbachf327b042014-01-14 08:30:32 +0200118 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119
120 mutex_unlock(&mvm->mutex);
121
122 return ret;
123}
124
125static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
126 size_t count, loff_t *ppos)
127{
128 struct iwl_mvm *mvm = file->private_data;
129 const struct fw_img *img;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200130 unsigned int ofs, len;
131 size_t ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100132 u8 *ptr;
133
Johannes Berg60191d92013-05-15 13:08:51 +0200134 if (!mvm->ucode_loaded)
135 return -EINVAL;
136
Johannes Berg8ca151b2013-01-24 14:25:36 +0100137 /* default is to dump the entire data segment */
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200138 img = &mvm->fw->img[mvm->cur_ucode];
139 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
140 len = img->sec[IWL_UCODE_SECTION_DATA].len;
141
Emmanuel Grumbach01e0efe2014-01-06 09:05:54 +0200142 if (mvm->dbgfs_sram_len) {
Johannes Berg60191d92013-05-15 13:08:51 +0200143 ofs = mvm->dbgfs_sram_offset;
144 len = mvm->dbgfs_sram_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100146
Johannes Berg8ca151b2013-01-24 14:25:36 +0100147 ptr = kzalloc(len, GFP_KERNEL);
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200148 if (!ptr)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100149 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150
Johannes Berg60191d92013-05-15 13:08:51 +0200151 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100152
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200153 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100154
Johannes Berg8ca151b2013-01-24 14:25:36 +0100155 kfree(ptr);
156
157 return ret;
158}
159
Johannes Berg1fa3f572013-11-13 09:10:21 +0100160static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
161 size_t count, loff_t *ppos)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100162{
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200163 const struct fw_img *img;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100164 u32 offset, len;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200165 u32 img_offset, img_len;
166
167 if (!mvm->ucode_loaded)
168 return -EINVAL;
169
170 img = &mvm->fw->img[mvm->cur_ucode];
171 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
172 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100173
Johannes Berg8ca151b2013-01-24 14:25:36 +0100174 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
175 if ((offset & 0x3) || (len & 0x3))
176 return -EINVAL;
Emmanuel Grumbachd5103422013-12-24 14:58:29 +0200177
178 if (offset + len > img_offset + img_len)
179 return -EINVAL;
180
Johannes Berg8ca151b2013-01-24 14:25:36 +0100181 mvm->dbgfs_sram_offset = offset;
182 mvm->dbgfs_sram_len = len;
183 } else {
184 mvm->dbgfs_sram_offset = 0;
185 mvm->dbgfs_sram_len = 0;
186 }
187
188 return count;
189}
190
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300191static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
192 char __user *user_buf,
193 size_t count, loff_t *ppos)
194{
195 struct iwl_mvm *mvm = file->private_data;
196 char buf[16];
197 int pos;
198
199 if (!mvm->temperature_test)
200 pos = scnprintf(buf , sizeof(buf), "disabled\n");
201 else
202 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
203
204 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
205}
206
207/*
208 * Set NIC Temperature
209 * Cause the driver to ignore the actual NIC temperature reported by the FW
210 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
211 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
212 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
213 */
214static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
215 char *buf, size_t count,
216 loff_t *ppos)
217{
218 int temperature;
219
Luciano Coelhoa26d4e72014-08-20 10:21:07 +0300220 if (!mvm->ucode_loaded && !mvm->temperature_test)
221 return -EIO;
222
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300223 if (kstrtoint(buf, 10, &temperature))
224 return -EINVAL;
225 /* not a legal temperature */
226 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
227 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
228 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
229 return -EINVAL;
230
231 mutex_lock(&mvm->mutex);
232 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
Luciano Coelhob689fa72014-08-20 17:26:58 +0300233 if (!mvm->temperature_test)
234 goto out;
235
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300236 mvm->temperature_test = false;
Luciano Coelhob689fa72014-08-20 17:26:58 +0300237 /* Since we can't read the temp while awake, just set
238 * it to zero until we get the next RX stats from the
239 * firmware.
240 */
241 mvm->temperature = 0;
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300242 } else {
243 mvm->temperature_test = true;
244 mvm->temperature = temperature;
245 }
246 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
247 mvm->temperature_test ? "En" : "Dis" ,
248 mvm->temperature);
249 /* handle the temperature change */
250 iwl_mvm_tt_handler(mvm);
Luciano Coelhob689fa72014-08-20 17:26:58 +0300251
252out:
Matti Gottlieb7280d1f2014-07-17 16:41:14 +0300253 mutex_unlock(&mvm->mutex);
254
255 return count;
256}
257
Luciano Coelhoc549e392014-09-04 15:58:47 +0300258static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
259 char __user *user_buf,
260 size_t count, loff_t *ppos)
261{
262 struct iwl_mvm *mvm = file->private_data;
263 char buf[16];
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200264 int pos, ret;
265 s32 temp;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300266
267 if (!mvm->ucode_loaded)
268 return -EIO;
269
270 mutex_lock(&mvm->mutex);
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200271 ret = iwl_mvm_get_temp(mvm, &temp);
Luciano Coelhoc549e392014-09-04 15:58:47 +0300272 mutex_unlock(&mvm->mutex);
273
Chaya Rachel Ivgi78693182015-12-27 13:45:42 +0200274 if (ret)
275 return -EIO;
Luciano Coelhoc549e392014-09-04 15:58:47 +0300276
277 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
278
279 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
280}
281
Johannes Berg8ca151b2013-01-24 14:25:36 +0100282static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
283 size_t count, loff_t *ppos)
284{
285 struct iwl_mvm *mvm = file->private_data;
286 struct ieee80211_sta *sta;
287 char buf[400];
288 int i, pos = 0, bufsz = sizeof(buf);
289
290 mutex_lock(&mvm->mutex);
291
292 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
293 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
294 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
295 lockdep_is_held(&mvm->mutex));
296 if (!sta)
297 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
298 else if (IS_ERR(sta))
299 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
300 PTR_ERR(sta));
301 else
302 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
303 sta->addr);
304 }
305
306 mutex_unlock(&mvm->mutex);
307
308 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
309}
310
Alexander Bondar64b928c2013-09-03 14:18:03 +0300311static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
312 char __user *user_buf,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313 size_t count, loff_t *ppos)
314{
315 struct iwl_mvm *mvm = file->private_data;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300316 char buf[64];
317 int bufsz = sizeof(buf);
318 int pos = 0;
319
320 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
321 mvm->disable_power_off);
322 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
323 mvm->disable_power_off_d3);
324
325 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
326}
327
Johannes Berg1fa3f572013-11-13 09:10:21 +0100328static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300329 size_t count, loff_t *ppos)
330{
Johannes Berg1fa3f572013-11-13 09:10:21 +0100331 int ret, val;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100332
333 if (!mvm->ucode_loaded)
334 return -EIO;
335
Alexander Bondar64b928c2013-09-03 14:18:03 +0300336 if (!strncmp("disable_power_off_d0=", buf, 21)) {
337 if (sscanf(buf + 21, "%d", &val) != 1)
338 return -EINVAL;
339 mvm->disable_power_off = val;
340 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
341 if (sscanf(buf + 21, "%d", &val) != 1)
342 return -EINVAL;
343 mvm->disable_power_off_d3 = val;
344 } else {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100345 return -EINVAL;
Alexander Bondar64b928c2013-09-03 14:18:03 +0300346 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100347
Alexander Bondar64b928c2013-09-03 14:18:03 +0300348 mutex_lock(&mvm->mutex);
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200349 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300350 mutex_unlock(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100351
Alexander Bondar64b928c2013-09-03 14:18:03 +0300352 return ret ?: count;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100353}
354
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200355#define BT_MBOX_MSG(_notif, _num, _field) \
356 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
357 >> BT_MBOX##_num##_##_field##_POS)
358
359
360#define BT_MBOX_PRINT(_num, _field, _end) \
361 pos += scnprintf(buf + pos, bufsz - pos, \
362 "\t%s: %d%s", \
363 #_field, \
364 BT_MBOX_MSG(notif, _num, _field), \
365 true ? "\n" : ", ");
366
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300367static
368int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
369 int pos, int bufsz)
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200370{
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200371 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
372
373 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
374 BT_MBOX_PRINT(0, LE_PROF1, false);
375 BT_MBOX_PRINT(0, LE_PROF2, false);
376 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
377 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
378 BT_MBOX_PRINT(0, INBAND_S, false);
379 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
380 BT_MBOX_PRINT(0, LE_SCAN, false);
381 BT_MBOX_PRINT(0, LE_ADV, false);
382 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
383 BT_MBOX_PRINT(0, OPEN_CON_1, true);
384
385 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
386
387 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
388 BT_MBOX_PRINT(1, IP_SR, false);
389 BT_MBOX_PRINT(1, LE_MSTR, false);
390 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
391 BT_MBOX_PRINT(1, MSG_TYPE, false);
392 BT_MBOX_PRINT(1, SSN, true);
393
394 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
395
396 BT_MBOX_PRINT(2, SNIFF_ACT, false);
397 BT_MBOX_PRINT(2, PAG, false);
398 BT_MBOX_PRINT(2, INQUIRY, false);
399 BT_MBOX_PRINT(2, CONN, false);
400 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
401 BT_MBOX_PRINT(2, DISC, false);
402 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
403 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
404 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
405 BT_MBOX_PRINT(2, SCO_DURATION, true);
406
407 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
408
409 BT_MBOX_PRINT(3, SCO_STATE, false);
410 BT_MBOX_PRINT(3, SNIFF_STATE, false);
411 BT_MBOX_PRINT(3, A2DP_STATE, false);
412 BT_MBOX_PRINT(3, ACL_STATE, false);
413 BT_MBOX_PRINT(3, MSTR_STATE, false);
414 BT_MBOX_PRINT(3, OBX_STATE, false);
415 BT_MBOX_PRINT(3, OPEN_CON_2, false);
416 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
417 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
418 BT_MBOX_PRINT(3, INBAND_P, false);
419 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
420 BT_MBOX_PRINT(3, SSN_2, false);
421 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
422
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300423 return pos;
424}
425
426static
427int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
428 char *buf, int pos, int bufsz)
429{
430 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
431
432 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
433 BT_MBOX_PRINT(0, LE_PROF1, false);
434 BT_MBOX_PRINT(0, LE_PROF2, false);
435 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
436 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
437 BT_MBOX_PRINT(0, INBAND_S, false);
438 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
439 BT_MBOX_PRINT(0, LE_SCAN, false);
440 BT_MBOX_PRINT(0, LE_ADV, false);
441 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
442 BT_MBOX_PRINT(0, OPEN_CON_1, true);
443
444 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
445
446 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
447 BT_MBOX_PRINT(1, IP_SR, false);
448 BT_MBOX_PRINT(1, LE_MSTR, false);
449 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
450 BT_MBOX_PRINT(1, MSG_TYPE, false);
451 BT_MBOX_PRINT(1, SSN, true);
452
453 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
454
455 BT_MBOX_PRINT(2, SNIFF_ACT, false);
456 BT_MBOX_PRINT(2, PAG, false);
457 BT_MBOX_PRINT(2, INQUIRY, false);
458 BT_MBOX_PRINT(2, CONN, false);
459 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
460 BT_MBOX_PRINT(2, DISC, false);
461 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
462 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
463 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
464 BT_MBOX_PRINT(2, SCO_DURATION, true);
465
466 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
467
468 BT_MBOX_PRINT(3, SCO_STATE, false);
469 BT_MBOX_PRINT(3, SNIFF_STATE, false);
470 BT_MBOX_PRINT(3, A2DP_STATE, false);
471 BT_MBOX_PRINT(3, ACL_STATE, false);
472 BT_MBOX_PRINT(3, MSTR_STATE, false);
473 BT_MBOX_PRINT(3, OBX_STATE, false);
474 BT_MBOX_PRINT(3, OPEN_CON_2, false);
475 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
476 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
477 BT_MBOX_PRINT(3, INBAND_P, false);
478 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
479 BT_MBOX_PRINT(3, SSN_2, false);
480 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
481
482 return pos;
483}
484
485static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
486 size_t count, loff_t *ppos)
487{
488 struct iwl_mvm *mvm = file->private_data;
489 char *buf;
490 int ret, pos = 0, bufsz = sizeof(char) * 1024;
491
492 buf = kmalloc(bufsz, GFP_KERNEL);
493 if (!buf)
494 return -ENOMEM;
495
496 mutex_lock(&mvm->mutex);
497
Johannes Berg859d9142015-06-01 17:11:11 +0200498 if (!fw_has_api(&mvm->fw->ucode_capa,
499 IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300500 struct iwl_bt_coex_profile_notif_old *notif =
501 &mvm->last_bt_notif_old;
502
503 pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
504
505 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
506 notif->bt_ci_compliance);
507 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
508 le32_to_cpu(notif->primary_ch_lut));
509 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
510 le32_to_cpu(notif->secondary_ch_lut));
511 pos += scnprintf(buf+pos,
512 bufsz-pos, "bt_activity_grading = %d\n",
513 le32_to_cpu(notif->bt_activity_grading));
514 pos += scnprintf(buf+pos, bufsz-pos,
515 "antenna isolation = %d CORUN LUT index = %d\n",
516 mvm->last_ant_isol, mvm->last_corun_lut);
Moshe Harel48f0a032015-10-26 11:33:49 +0200517 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
518 notif->rrc_enabled);
519 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
520 notif->ttc_enabled);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300521 } else {
522 struct iwl_bt_coex_profile_notif *notif =
523 &mvm->last_bt_notif;
524
525 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
526
527 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
528 notif->bt_ci_compliance);
529 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
530 le32_to_cpu(notif->primary_ch_lut));
531 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
532 le32_to_cpu(notif->secondary_ch_lut));
533 pos += scnprintf(buf+pos,
534 bufsz-pos, "bt_activity_grading = %d\n",
535 le32_to_cpu(notif->bt_activity_grading));
536 pos += scnprintf(buf+pos, bufsz-pos,
537 "antenna isolation = %d CORUN LUT index = %d\n",
538 mvm->last_ant_isol, mvm->last_corun_lut);
Moshe Harel48f0a032015-10-26 11:33:49 +0200539 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
540 (notif->ttc_rrc_status >> 4) & 0xF);
541 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
542 notif->ttc_rrc_status & 0xF);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300543 }
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200544
Moshe Harelc725a462015-10-27 14:04:12 +0200545 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
546 IWL_MVM_BT_COEX_SYNC2SCO);
547 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
548 IWL_MVM_BT_COEX_MPLUT);
549 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
550 IWL_MVM_BT_COEX_CORUNNING);
551
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200552 mutex_unlock(&mvm->mutex);
553
554 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
555 kfree(buf);
556
557 return ret;
558}
559#undef BT_MBOX_PRINT
560
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300561static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
562 size_t count, loff_t *ppos)
563{
564 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300565 char buf[256];
566 int bufsz = sizeof(buf);
567 int pos = 0;
568
569 mutex_lock(&mvm->mutex);
570
Johannes Berg859d9142015-06-01 17:11:11 +0200571 if (!fw_has_api(&mvm->fw->ucode_capa,
572 IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300573 struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300574
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300575 pos += scnprintf(buf+pos, bufsz-pos,
576 "Channel inhibition CMD\n");
577 pos += scnprintf(buf+pos, bufsz-pos,
578 "\tPrimary Channel Bitmap 0x%016llx\n",
579 le64_to_cpu(cmd->bt_primary_ci));
580 pos += scnprintf(buf+pos, bufsz-pos,
581 "\tSecondary Channel Bitmap 0x%016llx\n",
582 le64_to_cpu(cmd->bt_secondary_ci));
583
Emmanuel Grumbachaee8bf52015-02-19 15:00:18 +0200584 pos += scnprintf(buf+pos, bufsz-pos,
585 "BT Configuration CMD - 0=default, 1=never, 2=always\n");
586 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill msk idx %d\n",
587 mvm->bt_ack_kill_msk[0]);
588 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill msk idx %d\n",
589 mvm->bt_cts_kill_msk[0]);
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300590
591 } else {
592 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
593
594 pos += scnprintf(buf+pos, bufsz-pos,
595 "Channel inhibition CMD\n");
596 pos += scnprintf(buf+pos, bufsz-pos,
597 "\tPrimary Channel Bitmap 0x%016llx\n",
598 le64_to_cpu(cmd->bt_primary_ci));
599 pos += scnprintf(buf+pos, bufsz-pos,
600 "\tSecondary Channel Bitmap 0x%016llx\n",
601 le64_to_cpu(cmd->bt_secondary_ci));
Emmanuel Grumbach160be572014-07-02 17:33:52 +0300602 }
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +0300603
604 mutex_unlock(&mvm->mutex);
605
606 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
607}
608
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +0200609static ssize_t
610iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
611 size_t count, loff_t *ppos)
612{
613 u32 bt_tx_prio;
614
615 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
616 return -EINVAL;
617 if (bt_tx_prio > 4)
618 return -EINVAL;
619
620 mvm->bt_tx_prio = bt_tx_prio;
621
622 return count;
623}
624
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +0300625static ssize_t
626iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
627 size_t count, loff_t *ppos)
628{
629 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
630 [BT_FORCE_ANT_DIS] = "dis",
631 [BT_FORCE_ANT_AUTO] = "auto",
632 [BT_FORCE_ANT_BT] = "bt",
633 [BT_FORCE_ANT_WIFI] = "wifi",
634 };
635 int ret, bt_force_ant_mode;
636
637 for (bt_force_ant_mode = 0;
638 bt_force_ant_mode < ARRAY_SIZE(modes_str);
639 bt_force_ant_mode++) {
640 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
641 break;
642 }
643
644 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
645 return -EINVAL;
646
647 ret = 0;
648 mutex_lock(&mvm->mutex);
649 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
650 goto out;
651
652 mvm->bt_force_ant_mode = bt_force_ant_mode;
653 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
654 modes_str[mvm->bt_force_ant_mode]);
655 ret = iwl_send_bt_init_conf(mvm);
656
657out:
658 mutex_unlock(&mvm->mutex);
659 return ret ?: count;
660}
661
Johannes Berg93d17cc2015-01-15 12:59:26 +0100662#define PRINT_STATS_LE32(_struct, _memb) \
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300663 pos += scnprintf(buf + pos, bufsz - pos, \
Johannes Berg93d17cc2015-01-15 12:59:26 +0100664 fmt_table, #_memb, \
665 le32_to_cpu(_struct->_memb))
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300666
667static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
668 char __user *user_buf, size_t count,
669 loff_t *ppos)
670{
671 struct iwl_mvm *mvm = file->private_data;
672 static const char *fmt_table = "\t%-30s %10u\n";
673 static const char *fmt_header = "%-32s\n";
674 int pos = 0;
675 char *buf;
676 int ret;
Luciano Coelho3f617282013-10-14 13:18:41 +0300677 /* 43 is the size of each data line, 33 is the size of each header */
678 size_t bufsz =
679 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
680 (4 * 33) + 1;
681
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300682 struct mvm_statistics_rx_phy *ofdm;
683 struct mvm_statistics_rx_phy *cck;
684 struct mvm_statistics_rx_non_phy *general;
685 struct mvm_statistics_rx_ht_phy *ht;
686
687 buf = kzalloc(bufsz, GFP_KERNEL);
688 if (!buf)
689 return -ENOMEM;
690
691 mutex_lock(&mvm->mutex);
692
693 ofdm = &mvm->rx_stats.ofdm;
694 cck = &mvm->rx_stats.cck;
695 general = &mvm->rx_stats.general;
696 ht = &mvm->rx_stats.ofdm_ht;
697
698 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
699 "Statistics_Rx - OFDM");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100700 PRINT_STATS_LE32(ofdm, ina_cnt);
701 PRINT_STATS_LE32(ofdm, fina_cnt);
702 PRINT_STATS_LE32(ofdm, plcp_err);
703 PRINT_STATS_LE32(ofdm, crc32_err);
704 PRINT_STATS_LE32(ofdm, overrun_err);
705 PRINT_STATS_LE32(ofdm, early_overrun_err);
706 PRINT_STATS_LE32(ofdm, crc32_good);
707 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
708 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
709 PRINT_STATS_LE32(ofdm, sfd_timeout);
710 PRINT_STATS_LE32(ofdm, fina_timeout);
711 PRINT_STATS_LE32(ofdm, unresponded_rts);
712 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
713 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
714 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
715 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
716 PRINT_STATS_LE32(ofdm, dsp_self_kill);
717 PRINT_STATS_LE32(ofdm, mh_format_err);
718 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
719 PRINT_STATS_LE32(ofdm, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300720
721 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
722 "Statistics_Rx - CCK");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100723 PRINT_STATS_LE32(cck, ina_cnt);
724 PRINT_STATS_LE32(cck, fina_cnt);
725 PRINT_STATS_LE32(cck, plcp_err);
726 PRINT_STATS_LE32(cck, crc32_err);
727 PRINT_STATS_LE32(cck, overrun_err);
728 PRINT_STATS_LE32(cck, early_overrun_err);
729 PRINT_STATS_LE32(cck, crc32_good);
730 PRINT_STATS_LE32(cck, false_alarm_cnt);
731 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
732 PRINT_STATS_LE32(cck, sfd_timeout);
733 PRINT_STATS_LE32(cck, fina_timeout);
734 PRINT_STATS_LE32(cck, unresponded_rts);
735 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
736 PRINT_STATS_LE32(cck, sent_ack_cnt);
737 PRINT_STATS_LE32(cck, sent_cts_cnt);
738 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
739 PRINT_STATS_LE32(cck, dsp_self_kill);
740 PRINT_STATS_LE32(cck, mh_format_err);
741 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
742 PRINT_STATS_LE32(cck, reserved);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300743
744 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
745 "Statistics_Rx - GENERAL");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100746 PRINT_STATS_LE32(general, bogus_cts);
747 PRINT_STATS_LE32(general, bogus_ack);
748 PRINT_STATS_LE32(general, non_bssid_frames);
749 PRINT_STATS_LE32(general, filtered_frames);
750 PRINT_STATS_LE32(general, non_channel_beacons);
751 PRINT_STATS_LE32(general, channel_beacons);
752 PRINT_STATS_LE32(general, num_missed_bcon);
753 PRINT_STATS_LE32(general, adc_rx_saturation_time);
754 PRINT_STATS_LE32(general, ina_detection_search_time);
755 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
756 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
757 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
758 PRINT_STATS_LE32(general, interference_data_flag);
759 PRINT_STATS_LE32(general, channel_load);
760 PRINT_STATS_LE32(general, dsp_false_alarms);
761 PRINT_STATS_LE32(general, beacon_rssi_a);
762 PRINT_STATS_LE32(general, beacon_rssi_b);
763 PRINT_STATS_LE32(general, beacon_rssi_c);
764 PRINT_STATS_LE32(general, beacon_energy_a);
765 PRINT_STATS_LE32(general, beacon_energy_b);
766 PRINT_STATS_LE32(general, beacon_energy_c);
767 PRINT_STATS_LE32(general, num_bt_kills);
768 PRINT_STATS_LE32(general, mac_id);
769 PRINT_STATS_LE32(general, directed_data_mpdu);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300770
771 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
772 "Statistics_Rx - HT");
Johannes Berg93d17cc2015-01-15 12:59:26 +0100773 PRINT_STATS_LE32(ht, plcp_err);
774 PRINT_STATS_LE32(ht, overrun_err);
775 PRINT_STATS_LE32(ht, early_overrun_err);
776 PRINT_STATS_LE32(ht, crc32_good);
777 PRINT_STATS_LE32(ht, crc32_err);
778 PRINT_STATS_LE32(ht, mh_format_err);
779 PRINT_STATS_LE32(ht, agg_crc32_good);
780 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
781 PRINT_STATS_LE32(ht, agg_cnt);
782 PRINT_STATS_LE32(ht, unsupport_mcs);
Matti Gottlieb3848ab62013-07-30 15:29:37 +0300783
784 mutex_unlock(&mvm->mutex);
785
786 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
787 kfree(buf);
788
789 return ret;
790}
791#undef PRINT_STAT_LE32
792
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200793static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
794 char __user *user_buf, size_t count,
795 loff_t *ppos,
796 struct iwl_mvm_frame_stats *stats)
797{
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200798 char *buff, *pos, *endpos;
799 int idx, i;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200800 int ret;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200801 static const size_t bufsz = 1024;
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200802
803 buff = kmalloc(bufsz, GFP_KERNEL);
804 if (!buff)
805 return -ENOMEM;
806
807 spin_lock_bh(&mvm->drv_stats_lock);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200808
809 pos = buff;
810 endpos = pos + bufsz;
811
812 pos += scnprintf(pos, endpos - pos,
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200813 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
814 stats->legacy_frames,
815 stats->ht_frames,
816 stats->vht_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200817 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200818 stats->bw_20_frames,
819 stats->bw_40_frames,
820 stats->bw_80_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200821 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200822 stats->ngi_frames,
823 stats->sgi_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200824 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200825 stats->siso_frames,
826 stats->mimo2_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200827 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200828 stats->fail_frames,
829 stats->success_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200830 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200831 stats->agg_frames);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200832 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200833 stats->ampdu_count);
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200834 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200835 stats->ampdu_count > 0 ?
836 (stats->agg_frames / stats->ampdu_count) : 0);
837
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200838 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200839
840 idx = stats->last_frame_idx - 1;
841 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
842 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
843 if (stats->last_rates[idx] == 0)
844 continue;
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200845 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200846 (int)(ARRAY_SIZE(stats->last_rates) - i));
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200847 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200848 }
849 spin_unlock_bh(&mvm->drv_stats_lock);
850
Eyal Shapiraf754b5c2014-02-24 10:24:34 +0200851 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
Eyal Shapira5fc0f762014-01-28 01:35:32 +0200852 kfree(buff);
853
854 return ret;
855}
856
857static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
858 char __user *user_buf, size_t count,
859 loff_t *ppos)
860{
861 struct iwl_mvm *mvm = file->private_data;
862
863 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
864 &mvm->drv_rx_stats);
865}
866
Johannes Berg1fa3f572013-11-13 09:10:21 +0100867static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200868 size_t count, loff_t *ppos)
869{
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200870 int ret;
871
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200872 mutex_lock(&mvm->mutex);
873
Eran Harary291aa7c2013-07-03 11:00:06 +0300874 /* allow one more restart that we're provoking here */
875 if (mvm->restart_fw >= 0)
876 mvm->restart_fw++;
877
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200878 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300879 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200880
881 mutex_unlock(&mvm->mutex);
882
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200883 return count;
884}
885
Johannes Berg1fa3f572013-11-13 09:10:21 +0100886static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
Alexander Bondar119663c2013-10-17 14:26:50 +0200887 size_t count, loff_t *ppos)
888{
Eliad Peller576eeee2014-07-01 18:38:38 +0300889 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
890 if (ret)
891 return ret;
892
Liad Kaufman4c9706d2014-04-27 16:46:09 +0300893 iwl_force_nmi(mvm->trans);
Alexander Bondar119663c2013-10-17 14:26:50 +0200894
Eliad Peller576eeee2014-07-01 18:38:38 +0300895 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
896
Alexander Bondar119663c2013-10-17 14:26:50 +0200897 return count;
898}
899
Oren Givon91b05d12013-08-19 08:36:48 +0300900static ssize_t
901iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
902 char __user *user_buf,
903 size_t count, loff_t *ppos)
904{
905 struct iwl_mvm *mvm = file->private_data;
906 int pos = 0;
907 char buf[32];
908 const size_t bufsz = sizeof(buf);
909
910 /* print which antennas were set for the scan command by the user */
911 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
912 if (mvm->scan_rx_ant & ANT_A)
913 pos += scnprintf(buf + pos, bufsz - pos, "A");
914 if (mvm->scan_rx_ant & ANT_B)
915 pos += scnprintf(buf + pos, bufsz - pos, "B");
916 if (mvm->scan_rx_ant & ANT_C)
917 pos += scnprintf(buf + pos, bufsz - pos, "C");
918 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
919
920 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
921}
922
923static ssize_t
Johannes Berg1fa3f572013-11-13 09:10:21 +0100924iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
Oren Givon91b05d12013-08-19 08:36:48 +0300925 size_t count, loff_t *ppos)
926{
Oren Givon91b05d12013-08-19 08:36:48 +0300927 u8 scan_rx_ant;
928
Oren Givon91b05d12013-08-19 08:36:48 +0300929 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
930 return -EINVAL;
931 if (scan_rx_ant > ANT_ABC)
932 return -EINVAL;
Moshe Harela0544272014-12-08 21:13:14 +0200933 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
Oren Givon91b05d12013-08-19 08:36:48 +0300934 return -EINVAL;
935
David Spinadeld2496222014-05-20 12:46:37 +0300936 if (mvm->scan_rx_ant != scan_rx_ant) {
937 mvm->scan_rx_ant = scan_rx_ant;
Johannes Berg859d9142015-06-01 17:11:11 +0200938 if (fw_has_capa(&mvm->fw->ucode_capa,
939 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
David Spinadeld2496222014-05-20 12:46:37 +0300940 iwl_mvm_config_scan(mvm);
941 }
Oren Givon91b05d12013-08-19 08:36:48 +0300942
943 return count;
944}
945
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200946static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
947 char __user *user_buf,
948 size_t count, loff_t *ppos)
949{
950 struct iwl_mvm *mvm = file->private_data;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +0200951 int conf;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200952 char buf[8];
953 const size_t bufsz = sizeof(buf);
954 int pos = 0;
955
956 mutex_lock(&mvm->mutex);
957 conf = mvm->fw_dbg_conf;
958 mutex_unlock(&mvm->mutex);
959
960 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
961
962 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
963}
964
Golan Ben Ami321c2102015-07-27 17:02:35 +0300965/*
966 * Enable / Disable continuous recording.
967 * Cause the FW to start continuous recording, by sending the relevant hcmd.
968 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
969 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
970 */
971static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
972 char *buf, size_t count,
973 loff_t *ppos)
974{
975 struct iwl_trans *trans = mvm->trans;
976 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
977 struct iwl_continuous_record_cmd cont_rec = {};
978 int ret, rec_mode;
979
980 if (!dest)
981 return -EOPNOTSUPP;
982
983 if (dest->monitor_mode != SMEM_MODE ||
984 trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
985 return -EOPNOTSUPP;
986
Johannes Berg27e070d2016-01-14 10:55:22 +0100987 ret = kstrtoint(buf, 0, &rec_mode);
Golan Ben Ami321c2102015-07-27 17:02:35 +0300988 if (ret)
989 return ret;
990
991 cont_rec.record_mode.enable_recording = rec_mode ?
992 cpu_to_le16(ENABLE_CONT_RECORDING) :
993 cpu_to_le16(DISABLE_CONT_RECORDING);
994
995 mutex_lock(&mvm->mutex);
996 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
997 sizeof(cont_rec), &cont_rec);
998 mutex_unlock(&mvm->mutex);
999
1000 return ret ?: count;
1001}
1002
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001003static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1004 char *buf, size_t count,
1005 loff_t *ppos)
1006{
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001007 unsigned int conf_id;
1008 int ret;
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001009
Dan Carpenter8e8114d2015-08-21 11:48:21 +03001010 ret = kstrtouint(buf, 0, &conf_id);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001011 if (ret)
1012 return ret;
1013
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001014 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001015 return -EINVAL;
1016
1017 mutex_lock(&mvm->mutex);
1018 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1019 mutex_unlock(&mvm->mutex);
1020
1021 return ret ?: count;
1022}
1023
1024static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1025 char *buf, size_t count,
1026 loff_t *ppos)
1027{
Liad Kaufmane93475a2015-01-04 11:03:13 +02001028 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1029
1030 if (ret)
1031 return ret;
1032
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001033 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1034 (count - 1), NULL);
Liad Kaufmane93475a2015-01-04 11:03:13 +02001035
1036 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001037
1038 return count;
1039}
1040
Eliad Pellerde06a592014-01-08 10:11:12 +02001041#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1042#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1043static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1044 char __user *user_buf,
1045 size_t count, loff_t *ppos)
1046{
1047 struct iwl_mvm *mvm = file->private_data;
1048 struct iwl_bcast_filter_cmd cmd;
1049 const struct iwl_fw_bcast_filter *filter;
1050 char *buf;
1051 int bufsz = 1024;
1052 int i, j, pos = 0;
1053 ssize_t ret;
1054
1055 buf = kzalloc(bufsz, GFP_KERNEL);
1056 if (!buf)
1057 return -ENOMEM;
1058
1059 mutex_lock(&mvm->mutex);
1060 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1061 ADD_TEXT("None\n");
1062 mutex_unlock(&mvm->mutex);
1063 goto out;
1064 }
1065 mutex_unlock(&mvm->mutex);
1066
1067 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1068 filter = &cmd.filters[i];
1069
1070 ADD_TEXT("Filter [%d]:\n", i);
1071 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1072 ADD_TEXT("\tFrame Type: %s\n",
1073 filter->frame_type ? "IPv4" : "Generic");
1074
1075 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1076 const struct iwl_fw_bcast_filter_attr *attr;
1077
1078 attr = &filter->attrs[j];
1079 if (!attr->mask)
1080 break;
1081
1082 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1083 j, attr->offset,
1084 attr->offset_type ? "IP End" :
1085 "Payload Start",
1086 be32_to_cpu(attr->mask),
1087 be32_to_cpu(attr->val),
1088 le16_to_cpu(attr->reserved1));
1089 }
1090 }
1091out:
1092 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1093 kfree(buf);
1094 return ret;
1095}
1096
1097static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1098 size_t count, loff_t *ppos)
1099{
1100 int pos, next_pos;
1101 struct iwl_fw_bcast_filter filter = {};
1102 struct iwl_bcast_filter_cmd cmd;
1103 u32 filter_id, attr_id, mask, value;
1104 int err = 0;
1105
1106 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1107 &filter.frame_type, &pos) != 3)
1108 return -EINVAL;
1109
1110 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1111 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1112 return -EINVAL;
1113
1114 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1115 attr_id++) {
1116 struct iwl_fw_bcast_filter_attr *attr =
1117 &filter.attrs[attr_id];
1118
1119 if (pos >= count)
1120 break;
1121
1122 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1123 &attr->offset, &attr->offset_type,
1124 &mask, &value, &next_pos) != 4)
1125 return -EINVAL;
1126
1127 attr->mask = cpu_to_be32(mask);
1128 attr->val = cpu_to_be32(value);
1129 if (mask)
1130 filter.num_attrs++;
1131
1132 pos += next_pos;
1133 }
1134
1135 mutex_lock(&mvm->mutex);
1136 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1137 &filter, sizeof(filter));
1138
1139 /* send updated bcast filtering configuration */
1140 if (mvm->dbgfs_bcast_filtering.override &&
1141 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001142 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001143 sizeof(cmd), &cmd);
1144 mutex_unlock(&mvm->mutex);
1145
1146 return err ?: count;
1147}
1148
1149static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1150 char __user *user_buf,
1151 size_t count, loff_t *ppos)
1152{
1153 struct iwl_mvm *mvm = file->private_data;
1154 struct iwl_bcast_filter_cmd cmd;
1155 char *buf;
1156 int bufsz = 1024;
1157 int i, pos = 0;
1158 ssize_t ret;
1159
1160 buf = kzalloc(bufsz, GFP_KERNEL);
1161 if (!buf)
1162 return -ENOMEM;
1163
1164 mutex_lock(&mvm->mutex);
1165 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1166 ADD_TEXT("None\n");
1167 mutex_unlock(&mvm->mutex);
1168 goto out;
1169 }
1170 mutex_unlock(&mvm->mutex);
1171
1172 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1173 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1174
1175 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1176 i, mac->default_discard, mac->attached_filters);
1177 }
1178out:
1179 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1180 kfree(buf);
1181 return ret;
1182}
1183
1184static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1185 char *buf, size_t count,
1186 loff_t *ppos)
1187{
1188 struct iwl_bcast_filter_cmd cmd;
1189 struct iwl_fw_bcast_mac mac = {};
1190 u32 mac_id, attached_filters;
1191 int err = 0;
1192
1193 if (!mvm->bcast_filters)
1194 return -ENOENT;
1195
1196 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1197 &attached_filters) != 3)
1198 return -EINVAL;
1199
1200 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1201 mac.default_discard > 1 ||
1202 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1203 return -EINVAL;
1204
1205 mac.attached_filters = cpu_to_le16(attached_filters);
1206
1207 mutex_lock(&mvm->mutex);
1208 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1209 &mac, sizeof(mac));
1210
1211 /* send updated bcast filtering configuration */
1212 if (mvm->dbgfs_bcast_filtering.override &&
1213 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001214 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
Eliad Pellerde06a592014-01-08 10:11:12 +02001215 sizeof(cmd), &cmd);
1216 mutex_unlock(&mvm->mutex);
1217
1218 return err ?: count;
1219}
1220#endif
1221
Johannes Bergafc66bb2013-05-03 11:44:16 +02001222#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001223static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
Johannes Bergafc66bb2013-05-03 11:44:16 +02001224 size_t count, loff_t *ppos)
1225{
Johannes Bergafc66bb2013-05-03 11:44:16 +02001226 int store;
1227
Johannes Bergafc66bb2013-05-03 11:44:16 +02001228 if (sscanf(buf, "%d", &store) != 1)
1229 return -EINVAL;
1230
1231 mvm->store_d3_resume_sram = store;
1232
1233 return count;
1234}
1235
1236static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1237 size_t count, loff_t *ppos)
1238{
1239 struct iwl_mvm *mvm = file->private_data;
1240 const struct fw_img *img;
1241 int ofs, len, pos = 0;
1242 size_t bufsz, ret;
1243 char *buf;
1244 u8 *ptr = mvm->d3_resume_sram;
1245
1246 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1247 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1248
1249 bufsz = len * 4 + 256;
1250 buf = kzalloc(bufsz, GFP_KERNEL);
1251 if (!buf)
1252 return -ENOMEM;
1253
1254 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1255 mvm->store_d3_resume_sram ? "en" : "dis");
1256
1257 if (ptr) {
1258 for (ofs = 0; ofs < len; ofs += 16) {
1259 pos += scnprintf(buf + pos, bufsz - pos,
Andy Shevchenko3cd6e2f2015-07-16 15:42:14 +03001260 "0x%.4x %16ph\n", ofs, ptr + ofs);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001261 }
1262 } else {
1263 pos += scnprintf(buf + pos, bufsz - pos,
1264 "(no data captured)\n");
1265 }
1266
1267 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1268
1269 kfree(buf);
1270
1271 return ret;
1272}
1273#endif
1274
Eliad Peller576eeee2014-07-01 18:38:38 +03001275#define PRINT_MVM_REF(ref) do { \
1276 if (mvm->refs[ref]) \
1277 pos += scnprintf(buf + pos, bufsz - pos, \
1278 "\t(0x%lx): %d %s\n", \
1279 BIT(ref), mvm->refs[ref], #ref); \
Eliad Peller70d6bab2013-11-05 14:45:16 +02001280} while (0)
1281
1282static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1283 char __user *user_buf,
1284 size_t count, loff_t *ppos)
1285{
1286 struct iwl_mvm *mvm = file->private_data;
Eliad Peller576eeee2014-07-01 18:38:38 +03001287 int i, pos = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001288 char buf[256];
1289 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001290 u32 refs = 0;
Eliad Peller70d6bab2013-11-05 14:45:16 +02001291
Eliad Peller576eeee2014-07-01 18:38:38 +03001292 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1293 if (mvm->refs[i])
1294 refs |= BIT(i);
1295
1296 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1297 refs);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001298
1299 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1300 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1301 PRINT_MVM_REF(IWL_MVM_REF_ROC);
Eliad Pellerc7792732015-04-19 11:41:04 +03001302 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001303 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1304 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
Eliad Peller0eb83652013-11-11 18:56:35 +02001305 PRINT_MVM_REF(IWL_MVM_REF_USER);
Johannes Berg34e611e2014-09-12 10:28:01 +02001306 PRINT_MVM_REF(IWL_MVM_REF_TX);
1307 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1308 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1309 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1310 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1311 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1312 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1313 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1314 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1315 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1316 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1317 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
Eliad Pellerd15a7472014-03-27 18:53:12 +02001318 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
Eliad Peller160acc02014-11-25 12:34:45 +02001319 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
Liad Kaufmanfb2380a2015-01-01 17:42:46 +02001320 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
Eliad Peller08f0d232015-12-10 15:47:11 +02001321 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
Eliad Peller70d6bab2013-11-05 14:45:16 +02001322
1323 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1324}
1325
Eliad Peller0eb83652013-11-11 18:56:35 +02001326static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1327 size_t count, loff_t *ppos)
1328{
1329 unsigned long value;
1330 int ret;
1331 bool taken;
1332
1333 ret = kstrtoul(buf, 10, &value);
1334 if (ret < 0)
1335 return ret;
1336
1337 mutex_lock(&mvm->mutex);
1338
Eliad Peller576eeee2014-07-01 18:38:38 +03001339 taken = mvm->refs[IWL_MVM_REF_USER];
Eliad Peller0eb83652013-11-11 18:56:35 +02001340 if (value == 1 && !taken)
1341 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1342 else if (value == 0 && taken)
1343 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1344 else
1345 ret = -EINVAL;
1346
1347 mutex_unlock(&mvm->mutex);
1348
1349 if (ret < 0)
1350 return ret;
1351 return count;
1352}
1353
Johannes Berg1fa3f572013-11-13 09:10:21 +01001354#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1355 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1356#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1357 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
Eliad Pellerde06a592014-01-08 10:11:12 +02001358#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1359 if (!debugfs_create_file(alias, mode, parent, mvm, \
Johannes Berg8ca151b2013-01-24 14:25:36 +01001360 &iwl_dbgfs_##name##_ops)) \
1361 goto err; \
1362 } while (0)
Eliad Pellerde06a592014-01-08 10:11:12 +02001363#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1364 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001365
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001366static ssize_t
1367iwl_dbgfs_prph_reg_read(struct file *file,
1368 char __user *user_buf,
1369 size_t count, loff_t *ppos)
1370{
1371 struct iwl_mvm *mvm = file->private_data;
1372 int pos = 0;
1373 char buf[32];
1374 const size_t bufsz = sizeof(buf);
Eliad Peller576eeee2014-07-01 18:38:38 +03001375 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001376
1377 if (!mvm->dbgfs_prph_reg_addr)
1378 return -EINVAL;
1379
Eliad Peller576eeee2014-07-01 18:38:38 +03001380 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1381 if (ret)
1382 return ret;
1383
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001384 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1385 mvm->dbgfs_prph_reg_addr,
1386 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1387
Eliad Peller576eeee2014-07-01 18:38:38 +03001388 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1389
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001390 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1391}
1392
1393static ssize_t
1394iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1395 size_t count, loff_t *ppos)
1396{
1397 u8 args;
1398 u32 value;
Eliad Peller576eeee2014-07-01 18:38:38 +03001399 int ret;
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001400
1401 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1402 /* if we only want to set the reg address - nothing more to do */
1403 if (args == 1)
1404 goto out;
1405
1406 /* otherwise, make sure we have both address and value */
1407 if (args != 2)
1408 return -EINVAL;
1409
Eliad Peller576eeee2014-07-01 18:38:38 +03001410 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1411 if (ret)
1412 return ret;
1413
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001414 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
Eliad Peller576eeee2014-07-01 18:38:38 +03001415
1416 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001417out:
1418 return count;
1419}
1420
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001421static ssize_t
1422iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1423 size_t count, loff_t *ppos)
1424{
1425 int ret;
1426
1427 mutex_lock(&mvm->mutex);
1428 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1429 mutex_unlock(&mvm->mutex);
1430
1431 return ret ?: count;
1432}
1433
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001434MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1435
Johannes Berg8ca151b2013-01-24 14:25:36 +01001436/* Device wide debugfs entries */
Johannes Berg1fa3f572013-11-13 09:10:21 +01001437MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1438MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001439MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001440MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001441MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001442MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001443MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001444MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001445MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001446MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001447MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001448MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001449MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1450MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001451MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001452MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
Johannes Berg1fa3f572013-11-13 09:10:21 +01001453MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
Eliad Peller0eb83652013-11-11 18:56:35 +02001454MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001455MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
Golan Ben-Amic91b8652015-11-30 14:30:21 +02001456MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001457MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
Oren Givon91b05d12013-08-19 08:36:48 +03001458
Eliad Pellerde06a592014-01-08 10:11:12 +02001459#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1460MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1461MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1462#endif
1463
Johannes Bergafc66bb2013-05-03 11:44:16 +02001464#ifdef CONFIG_PM_SLEEP
Johannes Berg1fa3f572013-11-13 09:10:21 +01001465MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
Johannes Bergafc66bb2013-05-03 11:44:16 +02001466#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001467
1468int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1469{
Eliad Pellerde06a592014-01-08 10:11:12 +02001470 struct dentry *bcast_dir __maybe_unused;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001471 char buf[100];
1472
Johannes Bergd07913a2014-02-26 11:25:58 +01001473 spin_lock_init(&mvm->drv_stats_lock);
1474
Johannes Berg8ca151b2013-01-24 14:25:36 +01001475 mvm->debugfs_dir = dbgfs_dir;
1476
1477 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1478 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1479 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Matti Gottlieb7280d1f2014-07-17 16:41:14 +03001480 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1481 S_IWUSR | S_IRUSR);
Luciano Coelhoc549e392014-09-04 15:58:47 +03001482 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001483 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +02001484 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach2de13ca2013-06-30 07:43:28 +03001485 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach639eaba2014-03-30 10:11:13 +03001486 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1487 S_IRUSR | S_IWUSR);
Matti Gottlieb3848ab62013-07-30 15:29:37 +03001488 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
Eyal Shapira5fc0f762014-01-28 01:35:32 +02001489 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02001490 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Alexander Bondar119663c2013-10-17 14:26:50 +02001491 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbachcdb00562014-03-16 21:55:43 +02001492 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbacha39979a2014-05-28 12:06:41 +03001493 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
Oren Givon91b05d12013-08-19 08:36:48 +03001494 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1495 S_IWUSR | S_IRUSR);
Eliad Pellerf3c221f2014-01-09 13:12:54 +02001496 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
Eliad Peller0eb83652013-11-11 18:56:35 +02001497 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +02001498 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1499 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbache5046012015-08-17 10:45:50 +03001500 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
Golan Ben Ami321c2102015-07-27 17:02:35 +03001501 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
Luciano Coelhocb2513b2015-02-27 16:26:57 +02001502 if (!debugfs_create_bool("enable_scan_iteration_notif",
1503 S_IRUSR | S_IWUSR,
1504 mvm->debugfs_dir,
1505 &mvm->scan_iter_notif_enabled))
1506 goto err;
Eliad Pellerde06a592014-01-08 10:11:12 +02001507
1508#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1509 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1510 bcast_dir = debugfs_create_dir("bcast_filtering",
1511 mvm->debugfs_dir);
1512 if (!bcast_dir)
1513 goto err;
1514
1515 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1516 bcast_dir,
1517 &mvm->dbgfs_bcast_filtering.override))
1518 goto err;
1519
1520 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1521 bcast_dir, S_IWUSR | S_IRUSR);
1522 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1523 bcast_dir, S_IWUSR | S_IRUSR);
1524 }
1525#endif
1526
Johannes Bergafc66bb2013-05-03 11:44:16 +02001527#ifdef CONFIG_PM_SLEEP
1528 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
Johannes Bergdebff612013-05-14 13:53:45 +02001529 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
Johannes Bergb0114712013-06-12 14:55:40 +02001530 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1531 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1532 goto err;
Luciano Coelho484b3d12015-03-30 20:46:32 +03001533 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1534 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1535 goto err;
Johannes Bergafc66bb2013-05-03 11:44:16 +02001536#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +01001537
Luciano Coelhobdd54832014-08-07 18:08:56 +03001538 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1539 mvm->debugfs_dir, &mvm->ps_disabled))
1540 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001541 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1542 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1543 goto err;
1544 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1545 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1546 goto err;
1547 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1548 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1549 goto err;
1550 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1551 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1552 goto err;
Moshe Harel91fac942015-09-02 12:45:12 +03001553 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1554 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1555 goto err;
Emmanuel Grumbach086f7362013-11-18 17:00:03 +02001556
Johannes Berg8ca151b2013-01-24 14:25:36 +01001557 /*
1558 * Create a symlink with mac80211. It will be removed when mac80211
1559 * exists (before the opmode exists which removes the target.)
1560 */
1561 snprintf(buf, 100, "../../%s/%s",
1562 dbgfs_dir->d_parent->d_parent->d_name.name,
1563 dbgfs_dir->d_parent->d_name.name);
1564 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1565 goto err;
1566
1567 return 0;
1568err:
1569 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1570 return -ENOMEM;
1571}