iwlwifi: mvm: update d0i3 debugfs
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / debugfs.c
1 /******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10 *
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
26 * in the file called COPYING.
27 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * 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 *****************************************************************************/
65 #include <linux/vmalloc.h>
66
67 #include "mvm.h"
68 #include "sta.h"
69 #include "iwl-io.h"
70 #include "debugfs.h"
71 #include "iwl-fw-error-dump.h"
72
73 static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
74 size_t count, loff_t *ppos)
75 {
76 int ret;
77 u32 scd_q_msk;
78
79 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
80 return -EIO;
81
82 if (sscanf(buf, "%x", &scd_q_msk) != 1)
83 return -EINVAL;
84
85 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
86
87 mutex_lock(&mvm->mutex);
88 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
89 mutex_unlock(&mvm->mutex);
90
91 return ret;
92 }
93
94 static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
95 size_t count, loff_t *ppos)
96 {
97 struct iwl_mvm_sta *mvmsta;
98 int sta_id, drain, ret;
99
100 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
101 return -EIO;
102
103 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
104 return -EINVAL;
105 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
106 return -EINVAL;
107 if (drain < 0 || drain > 1)
108 return -EINVAL;
109
110 mutex_lock(&mvm->mutex);
111
112 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
113
114 if (!mvmsta)
115 ret = -ENOENT;
116 else
117 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
118
119 mutex_unlock(&mvm->mutex);
120
121 return ret;
122 }
123
124 static int iwl_dbgfs_fw_error_dump_open(struct inode *inode, struct file *file)
125 {
126 struct iwl_mvm *mvm = inode->i_private;
127 int ret;
128
129 if (!mvm)
130 return -EINVAL;
131
132 mutex_lock(&mvm->mutex);
133 if (!mvm->fw_error_dump) {
134 ret = -ENODATA;
135 goto out;
136 }
137
138 file->private_data = mvm->fw_error_dump;
139 mvm->fw_error_dump = NULL;
140 ret = 0;
141
142 out:
143 mutex_unlock(&mvm->mutex);
144 return ret;
145 }
146
147 static ssize_t iwl_dbgfs_fw_error_dump_read(struct file *file,
148 char __user *user_buf,
149 size_t count, loff_t *ppos)
150 {
151 struct iwl_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
152 ssize_t bytes_read = 0;
153 ssize_t bytes_read_trans = 0;
154
155 if (*ppos < dump_ptrs->op_mode_len)
156 bytes_read +=
157 simple_read_from_buffer(user_buf, count, ppos,
158 dump_ptrs->op_mode_ptr,
159 dump_ptrs->op_mode_len);
160
161 if (bytes_read < 0 || *ppos < dump_ptrs->op_mode_len)
162 return bytes_read;
163
164 if (dump_ptrs->trans_ptr) {
165 *ppos -= dump_ptrs->op_mode_len;
166 bytes_read_trans =
167 simple_read_from_buffer(user_buf + bytes_read,
168 count - bytes_read, ppos,
169 dump_ptrs->trans_ptr->data,
170 dump_ptrs->trans_ptr->len);
171 *ppos += dump_ptrs->op_mode_len;
172
173 if (bytes_read_trans >= 0)
174 bytes_read += bytes_read_trans;
175 else if (!bytes_read)
176 /* propagate the failure */
177 return bytes_read_trans;
178 }
179
180 return bytes_read;
181
182 }
183
184 static int iwl_dbgfs_fw_error_dump_release(struct inode *inode,
185 struct file *file)
186 {
187 struct iwl_mvm_dump_ptrs *dump_ptrs = (void *)file->private_data;
188
189 vfree(dump_ptrs->op_mode_ptr);
190 vfree(dump_ptrs->trans_ptr);
191 kfree(dump_ptrs);
192
193 return 0;
194 }
195
196 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
197 size_t count, loff_t *ppos)
198 {
199 struct iwl_mvm *mvm = file->private_data;
200 const struct fw_img *img;
201 unsigned int ofs, len;
202 size_t ret;
203 u8 *ptr;
204
205 if (!mvm->ucode_loaded)
206 return -EINVAL;
207
208 /* default is to dump the entire data segment */
209 img = &mvm->fw->img[mvm->cur_ucode];
210 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
211 len = img->sec[IWL_UCODE_SECTION_DATA].len;
212
213 if (mvm->dbgfs_sram_len) {
214 ofs = mvm->dbgfs_sram_offset;
215 len = mvm->dbgfs_sram_len;
216 }
217
218 ptr = kzalloc(len, GFP_KERNEL);
219 if (!ptr)
220 return -ENOMEM;
221
222 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
223
224 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
225
226 kfree(ptr);
227
228 return ret;
229 }
230
231 static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
232 size_t count, loff_t *ppos)
233 {
234 const struct fw_img *img;
235 u32 offset, len;
236 u32 img_offset, img_len;
237
238 if (!mvm->ucode_loaded)
239 return -EINVAL;
240
241 img = &mvm->fw->img[mvm->cur_ucode];
242 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
243 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
244
245 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
246 if ((offset & 0x3) || (len & 0x3))
247 return -EINVAL;
248
249 if (offset + len > img_offset + img_len)
250 return -EINVAL;
251
252 mvm->dbgfs_sram_offset = offset;
253 mvm->dbgfs_sram_len = len;
254 } else {
255 mvm->dbgfs_sram_offset = 0;
256 mvm->dbgfs_sram_len = 0;
257 }
258
259 return count;
260 }
261
262 static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
263 char __user *user_buf,
264 size_t count, loff_t *ppos)
265 {
266 struct iwl_mvm *mvm = file->private_data;
267 char buf[16];
268 int pos;
269
270 if (!mvm->temperature_test)
271 pos = scnprintf(buf , sizeof(buf), "disabled\n");
272 else
273 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
274
275 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
276 }
277
278 /*
279 * Set NIC Temperature
280 * Cause the driver to ignore the actual NIC temperature reported by the FW
281 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
282 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
283 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
284 */
285 static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
286 char *buf, size_t count,
287 loff_t *ppos)
288 {
289 int temperature;
290
291 if (!mvm->ucode_loaded && !mvm->temperature_test)
292 return -EIO;
293
294 if (kstrtoint(buf, 10, &temperature))
295 return -EINVAL;
296 /* not a legal temperature */
297 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
298 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
299 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
300 return -EINVAL;
301
302 mutex_lock(&mvm->mutex);
303 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
304 if (!mvm->temperature_test)
305 goto out;
306
307 mvm->temperature_test = false;
308 /* Since we can't read the temp while awake, just set
309 * it to zero until we get the next RX stats from the
310 * firmware.
311 */
312 mvm->temperature = 0;
313 } else {
314 mvm->temperature_test = true;
315 mvm->temperature = temperature;
316 }
317 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
318 mvm->temperature_test ? "En" : "Dis" ,
319 mvm->temperature);
320 /* handle the temperature change */
321 iwl_mvm_tt_handler(mvm);
322
323 out:
324 mutex_unlock(&mvm->mutex);
325
326 return count;
327 }
328
329 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
330 size_t count, loff_t *ppos)
331 {
332 struct iwl_mvm *mvm = file->private_data;
333 struct ieee80211_sta *sta;
334 char buf[400];
335 int i, pos = 0, bufsz = sizeof(buf);
336
337 mutex_lock(&mvm->mutex);
338
339 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
340 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
341 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
342 lockdep_is_held(&mvm->mutex));
343 if (!sta)
344 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
345 else if (IS_ERR(sta))
346 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
347 PTR_ERR(sta));
348 else
349 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
350 sta->addr);
351 }
352
353 mutex_unlock(&mvm->mutex);
354
355 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
356 }
357
358 static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
359 char __user *user_buf,
360 size_t count, loff_t *ppos)
361 {
362 struct iwl_mvm *mvm = file->private_data;
363 char buf[64];
364 int bufsz = sizeof(buf);
365 int pos = 0;
366
367 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
368 mvm->disable_power_off);
369 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
370 mvm->disable_power_off_d3);
371
372 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
373 }
374
375 static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
376 size_t count, loff_t *ppos)
377 {
378 int ret, val;
379
380 if (!mvm->ucode_loaded)
381 return -EIO;
382
383 if (!strncmp("disable_power_off_d0=", buf, 21)) {
384 if (sscanf(buf + 21, "%d", &val) != 1)
385 return -EINVAL;
386 mvm->disable_power_off = val;
387 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
388 if (sscanf(buf + 21, "%d", &val) != 1)
389 return -EINVAL;
390 mvm->disable_power_off_d3 = val;
391 } else {
392 return -EINVAL;
393 }
394
395 mutex_lock(&mvm->mutex);
396 ret = iwl_mvm_power_update_device(mvm);
397 mutex_unlock(&mvm->mutex);
398
399 return ret ?: count;
400 }
401
402 #define BT_MBOX_MSG(_notif, _num, _field) \
403 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
404 >> BT_MBOX##_num##_##_field##_POS)
405
406
407 #define BT_MBOX_PRINT(_num, _field, _end) \
408 pos += scnprintf(buf + pos, bufsz - pos, \
409 "\t%s: %d%s", \
410 #_field, \
411 BT_MBOX_MSG(notif, _num, _field), \
412 true ? "\n" : ", ");
413
414 static
415 int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
416 int pos, int bufsz)
417 {
418 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
419
420 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
421 BT_MBOX_PRINT(0, LE_PROF1, false);
422 BT_MBOX_PRINT(0, LE_PROF2, false);
423 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
424 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
425 BT_MBOX_PRINT(0, INBAND_S, false);
426 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
427 BT_MBOX_PRINT(0, LE_SCAN, false);
428 BT_MBOX_PRINT(0, LE_ADV, false);
429 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
430 BT_MBOX_PRINT(0, OPEN_CON_1, true);
431
432 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
433
434 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
435 BT_MBOX_PRINT(1, IP_SR, false);
436 BT_MBOX_PRINT(1, LE_MSTR, false);
437 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
438 BT_MBOX_PRINT(1, MSG_TYPE, false);
439 BT_MBOX_PRINT(1, SSN, true);
440
441 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
442
443 BT_MBOX_PRINT(2, SNIFF_ACT, false);
444 BT_MBOX_PRINT(2, PAG, false);
445 BT_MBOX_PRINT(2, INQUIRY, false);
446 BT_MBOX_PRINT(2, CONN, false);
447 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
448 BT_MBOX_PRINT(2, DISC, false);
449 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
450 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
451 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
452 BT_MBOX_PRINT(2, SCO_DURATION, true);
453
454 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
455
456 BT_MBOX_PRINT(3, SCO_STATE, false);
457 BT_MBOX_PRINT(3, SNIFF_STATE, false);
458 BT_MBOX_PRINT(3, A2DP_STATE, false);
459 BT_MBOX_PRINT(3, ACL_STATE, false);
460 BT_MBOX_PRINT(3, MSTR_STATE, false);
461 BT_MBOX_PRINT(3, OBX_STATE, false);
462 BT_MBOX_PRINT(3, OPEN_CON_2, false);
463 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
464 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
465 BT_MBOX_PRINT(3, INBAND_P, false);
466 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
467 BT_MBOX_PRINT(3, SSN_2, false);
468 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
469
470 return pos;
471 }
472
473 static
474 int iwl_mvm_coex_dump_mbox_old(struct iwl_bt_coex_profile_notif_old *notif,
475 char *buf, int pos, int bufsz)
476 {
477 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
478
479 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
480 BT_MBOX_PRINT(0, LE_PROF1, false);
481 BT_MBOX_PRINT(0, LE_PROF2, false);
482 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
483 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
484 BT_MBOX_PRINT(0, INBAND_S, false);
485 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
486 BT_MBOX_PRINT(0, LE_SCAN, false);
487 BT_MBOX_PRINT(0, LE_ADV, false);
488 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
489 BT_MBOX_PRINT(0, OPEN_CON_1, true);
490
491 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
492
493 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
494 BT_MBOX_PRINT(1, IP_SR, false);
495 BT_MBOX_PRINT(1, LE_MSTR, false);
496 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
497 BT_MBOX_PRINT(1, MSG_TYPE, false);
498 BT_MBOX_PRINT(1, SSN, true);
499
500 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
501
502 BT_MBOX_PRINT(2, SNIFF_ACT, false);
503 BT_MBOX_PRINT(2, PAG, false);
504 BT_MBOX_PRINT(2, INQUIRY, false);
505 BT_MBOX_PRINT(2, CONN, false);
506 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
507 BT_MBOX_PRINT(2, DISC, false);
508 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
509 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
510 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
511 BT_MBOX_PRINT(2, SCO_DURATION, true);
512
513 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
514
515 BT_MBOX_PRINT(3, SCO_STATE, false);
516 BT_MBOX_PRINT(3, SNIFF_STATE, false);
517 BT_MBOX_PRINT(3, A2DP_STATE, false);
518 BT_MBOX_PRINT(3, ACL_STATE, false);
519 BT_MBOX_PRINT(3, MSTR_STATE, false);
520 BT_MBOX_PRINT(3, OBX_STATE, false);
521 BT_MBOX_PRINT(3, OPEN_CON_2, false);
522 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
523 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
524 BT_MBOX_PRINT(3, INBAND_P, false);
525 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
526 BT_MBOX_PRINT(3, SSN_2, false);
527 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
528
529 return pos;
530 }
531
532 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
533 size_t count, loff_t *ppos)
534 {
535 struct iwl_mvm *mvm = file->private_data;
536 char *buf;
537 int ret, pos = 0, bufsz = sizeof(char) * 1024;
538
539 buf = kmalloc(bufsz, GFP_KERNEL);
540 if (!buf)
541 return -ENOMEM;
542
543 mutex_lock(&mvm->mutex);
544
545 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
546 struct iwl_bt_coex_profile_notif_old *notif =
547 &mvm->last_bt_notif_old;
548
549 pos += iwl_mvm_coex_dump_mbox_old(notif, buf, pos, bufsz);
550
551 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
552 notif->bt_ci_compliance);
553 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
554 le32_to_cpu(notif->primary_ch_lut));
555 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
556 le32_to_cpu(notif->secondary_ch_lut));
557 pos += scnprintf(buf+pos,
558 bufsz-pos, "bt_activity_grading = %d\n",
559 le32_to_cpu(notif->bt_activity_grading));
560 pos += scnprintf(buf+pos, bufsz-pos,
561 "antenna isolation = %d CORUN LUT index = %d\n",
562 mvm->last_ant_isol, mvm->last_corun_lut);
563 } else {
564 struct iwl_bt_coex_profile_notif *notif =
565 &mvm->last_bt_notif;
566
567 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
568
569 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
570 notif->bt_ci_compliance);
571 pos += scnprintf(buf+pos, bufsz-pos, "primary_ch_lut = %d\n",
572 le32_to_cpu(notif->primary_ch_lut));
573 pos += scnprintf(buf+pos, bufsz-pos, "secondary_ch_lut = %d\n",
574 le32_to_cpu(notif->secondary_ch_lut));
575 pos += scnprintf(buf+pos,
576 bufsz-pos, "bt_activity_grading = %d\n",
577 le32_to_cpu(notif->bt_activity_grading));
578 pos += scnprintf(buf+pos, bufsz-pos,
579 "antenna isolation = %d CORUN LUT index = %d\n",
580 mvm->last_ant_isol, mvm->last_corun_lut);
581 }
582
583 mutex_unlock(&mvm->mutex);
584
585 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
586 kfree(buf);
587
588 return ret;
589 }
590 #undef BT_MBOX_PRINT
591
592 static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
593 size_t count, loff_t *ppos)
594 {
595 struct iwl_mvm *mvm = file->private_data;
596 char buf[256];
597 int bufsz = sizeof(buf);
598 int pos = 0;
599
600 mutex_lock(&mvm->mutex);
601
602 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BT_COEX_SPLIT)) {
603 struct iwl_bt_coex_ci_cmd_old *cmd = &mvm->last_bt_ci_cmd_old;
604
605 pos += scnprintf(buf+pos, bufsz-pos,
606 "Channel inhibition CMD\n");
607 pos += scnprintf(buf+pos, bufsz-pos,
608 "\tPrimary Channel Bitmap 0x%016llx\n",
609 le64_to_cpu(cmd->bt_primary_ci));
610 pos += scnprintf(buf+pos, bufsz-pos,
611 "\tSecondary Channel Bitmap 0x%016llx\n",
612 le64_to_cpu(cmd->bt_secondary_ci));
613
614 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
615 pos += scnprintf(buf+pos, bufsz-pos, "\tACK Kill Mask 0x%08x\n",
616 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
617 pos += scnprintf(buf+pos, bufsz-pos, "\tCTS Kill Mask 0x%08x\n",
618 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
619
620 } else {
621 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
622
623 pos += scnprintf(buf+pos, bufsz-pos,
624 "Channel inhibition CMD\n");
625 pos += scnprintf(buf+pos, bufsz-pos,
626 "\tPrimary Channel Bitmap 0x%016llx\n",
627 le64_to_cpu(cmd->bt_primary_ci));
628 pos += scnprintf(buf+pos, bufsz-pos,
629 "\tSecondary Channel Bitmap 0x%016llx\n",
630 le64_to_cpu(cmd->bt_secondary_ci));
631
632 pos += scnprintf(buf+pos, bufsz-pos, "BT Configuration CMD\n");
633 pos += scnprintf(buf+pos, bufsz-pos,
634 "\tPrimary: ACK Kill Mask 0x%08x\n",
635 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[0]]);
636 pos += scnprintf(buf+pos, bufsz-pos,
637 "\tPrimary: CTS Kill Mask 0x%08x\n",
638 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[0]]);
639 pos += scnprintf(buf+pos, bufsz-pos,
640 "\tSecondary: ACK Kill Mask 0x%08x\n",
641 iwl_bt_ctl_kill_msk[mvm->bt_ack_kill_msk[1]]);
642 pos += scnprintf(buf+pos, bufsz-pos,
643 "\tSecondary: CTS Kill Mask 0x%08x\n",
644 iwl_bt_ctl_kill_msk[mvm->bt_cts_kill_msk[1]]);
645
646 }
647
648 mutex_unlock(&mvm->mutex);
649
650 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
651 }
652
653 static ssize_t
654 iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
655 size_t count, loff_t *ppos)
656 {
657 u32 bt_tx_prio;
658
659 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
660 return -EINVAL;
661 if (bt_tx_prio > 4)
662 return -EINVAL;
663
664 mvm->bt_tx_prio = bt_tx_prio;
665
666 return count;
667 }
668
669 static ssize_t
670 iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
671 size_t count, loff_t *ppos)
672 {
673 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
674 [BT_FORCE_ANT_DIS] = "dis",
675 [BT_FORCE_ANT_AUTO] = "auto",
676 [BT_FORCE_ANT_BT] = "bt",
677 [BT_FORCE_ANT_WIFI] = "wifi",
678 };
679 int ret, bt_force_ant_mode;
680
681 for (bt_force_ant_mode = 0;
682 bt_force_ant_mode < ARRAY_SIZE(modes_str);
683 bt_force_ant_mode++) {
684 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
685 break;
686 }
687
688 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
689 return -EINVAL;
690
691 ret = 0;
692 mutex_lock(&mvm->mutex);
693 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
694 goto out;
695
696 mvm->bt_force_ant_mode = bt_force_ant_mode;
697 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
698 modes_str[mvm->bt_force_ant_mode]);
699 ret = iwl_send_bt_init_conf(mvm);
700
701 out:
702 mutex_unlock(&mvm->mutex);
703 return ret ?: count;
704 }
705
706 #define PRINT_STATS_LE32(_str, _val) \
707 pos += scnprintf(buf + pos, bufsz - pos, \
708 fmt_table, _str, \
709 le32_to_cpu(_val))
710
711 static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
712 char __user *user_buf, size_t count,
713 loff_t *ppos)
714 {
715 struct iwl_mvm *mvm = file->private_data;
716 static const char *fmt_table = "\t%-30s %10u\n";
717 static const char *fmt_header = "%-32s\n";
718 int pos = 0;
719 char *buf;
720 int ret;
721 /* 43 is the size of each data line, 33 is the size of each header */
722 size_t bufsz =
723 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
724 (4 * 33) + 1;
725
726 struct mvm_statistics_rx_phy *ofdm;
727 struct mvm_statistics_rx_phy *cck;
728 struct mvm_statistics_rx_non_phy *general;
729 struct mvm_statistics_rx_ht_phy *ht;
730
731 buf = kzalloc(bufsz, GFP_KERNEL);
732 if (!buf)
733 return -ENOMEM;
734
735 mutex_lock(&mvm->mutex);
736
737 ofdm = &mvm->rx_stats.ofdm;
738 cck = &mvm->rx_stats.cck;
739 general = &mvm->rx_stats.general;
740 ht = &mvm->rx_stats.ofdm_ht;
741
742 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
743 "Statistics_Rx - OFDM");
744 PRINT_STATS_LE32("ina_cnt", ofdm->ina_cnt);
745 PRINT_STATS_LE32("fina_cnt", ofdm->fina_cnt);
746 PRINT_STATS_LE32("plcp_err", ofdm->plcp_err);
747 PRINT_STATS_LE32("crc32_err", ofdm->crc32_err);
748 PRINT_STATS_LE32("overrun_err", ofdm->overrun_err);
749 PRINT_STATS_LE32("early_overrun_err", ofdm->early_overrun_err);
750 PRINT_STATS_LE32("crc32_good", ofdm->crc32_good);
751 PRINT_STATS_LE32("false_alarm_cnt", ofdm->false_alarm_cnt);
752 PRINT_STATS_LE32("fina_sync_err_cnt", ofdm->fina_sync_err_cnt);
753 PRINT_STATS_LE32("sfd_timeout", ofdm->sfd_timeout);
754 PRINT_STATS_LE32("fina_timeout", ofdm->fina_timeout);
755 PRINT_STATS_LE32("unresponded_rts", ofdm->unresponded_rts);
756 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
757 ofdm->rxe_frame_limit_overrun);
758 PRINT_STATS_LE32("sent_ack_cnt", ofdm->sent_ack_cnt);
759 PRINT_STATS_LE32("sent_cts_cnt", ofdm->sent_cts_cnt);
760 PRINT_STATS_LE32("sent_ba_rsp_cnt", ofdm->sent_ba_rsp_cnt);
761 PRINT_STATS_LE32("dsp_self_kill", ofdm->dsp_self_kill);
762 PRINT_STATS_LE32("mh_format_err", ofdm->mh_format_err);
763 PRINT_STATS_LE32("re_acq_main_rssi_sum", ofdm->re_acq_main_rssi_sum);
764 PRINT_STATS_LE32("reserved", ofdm->reserved);
765
766 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
767 "Statistics_Rx - CCK");
768 PRINT_STATS_LE32("ina_cnt", cck->ina_cnt);
769 PRINT_STATS_LE32("fina_cnt", cck->fina_cnt);
770 PRINT_STATS_LE32("plcp_err", cck->plcp_err);
771 PRINT_STATS_LE32("crc32_err", cck->crc32_err);
772 PRINT_STATS_LE32("overrun_err", cck->overrun_err);
773 PRINT_STATS_LE32("early_overrun_err", cck->early_overrun_err);
774 PRINT_STATS_LE32("crc32_good", cck->crc32_good);
775 PRINT_STATS_LE32("false_alarm_cnt", cck->false_alarm_cnt);
776 PRINT_STATS_LE32("fina_sync_err_cnt", cck->fina_sync_err_cnt);
777 PRINT_STATS_LE32("sfd_timeout", cck->sfd_timeout);
778 PRINT_STATS_LE32("fina_timeout", cck->fina_timeout);
779 PRINT_STATS_LE32("unresponded_rts", cck->unresponded_rts);
780 PRINT_STATS_LE32("rxe_frame_lmt_overrun",
781 cck->rxe_frame_limit_overrun);
782 PRINT_STATS_LE32("sent_ack_cnt", cck->sent_ack_cnt);
783 PRINT_STATS_LE32("sent_cts_cnt", cck->sent_cts_cnt);
784 PRINT_STATS_LE32("sent_ba_rsp_cnt", cck->sent_ba_rsp_cnt);
785 PRINT_STATS_LE32("dsp_self_kill", cck->dsp_self_kill);
786 PRINT_STATS_LE32("mh_format_err", cck->mh_format_err);
787 PRINT_STATS_LE32("re_acq_main_rssi_sum", cck->re_acq_main_rssi_sum);
788 PRINT_STATS_LE32("reserved", cck->reserved);
789
790 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
791 "Statistics_Rx - GENERAL");
792 PRINT_STATS_LE32("bogus_cts", general->bogus_cts);
793 PRINT_STATS_LE32("bogus_ack", general->bogus_ack);
794 PRINT_STATS_LE32("non_bssid_frames", general->non_bssid_frames);
795 PRINT_STATS_LE32("filtered_frames", general->filtered_frames);
796 PRINT_STATS_LE32("non_channel_beacons", general->non_channel_beacons);
797 PRINT_STATS_LE32("channel_beacons", general->channel_beacons);
798 PRINT_STATS_LE32("num_missed_bcon", general->num_missed_bcon);
799 PRINT_STATS_LE32("adc_rx_saturation_time",
800 general->adc_rx_saturation_time);
801 PRINT_STATS_LE32("ina_detection_search_time",
802 general->ina_detection_search_time);
803 PRINT_STATS_LE32("beacon_silence_rssi_a",
804 general->beacon_silence_rssi_a);
805 PRINT_STATS_LE32("beacon_silence_rssi_b",
806 general->beacon_silence_rssi_b);
807 PRINT_STATS_LE32("beacon_silence_rssi_c",
808 general->beacon_silence_rssi_c);
809 PRINT_STATS_LE32("interference_data_flag",
810 general->interference_data_flag);
811 PRINT_STATS_LE32("channel_load", general->channel_load);
812 PRINT_STATS_LE32("dsp_false_alarms", general->dsp_false_alarms);
813 PRINT_STATS_LE32("beacon_rssi_a", general->beacon_rssi_a);
814 PRINT_STATS_LE32("beacon_rssi_b", general->beacon_rssi_b);
815 PRINT_STATS_LE32("beacon_rssi_c", general->beacon_rssi_c);
816 PRINT_STATS_LE32("beacon_energy_a", general->beacon_energy_a);
817 PRINT_STATS_LE32("beacon_energy_b", general->beacon_energy_b);
818 PRINT_STATS_LE32("beacon_energy_c", general->beacon_energy_c);
819 PRINT_STATS_LE32("num_bt_kills", general->num_bt_kills);
820 PRINT_STATS_LE32("mac_id", general->mac_id);
821 PRINT_STATS_LE32("directed_data_mpdu", general->directed_data_mpdu);
822
823 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
824 "Statistics_Rx - HT");
825 PRINT_STATS_LE32("plcp_err", ht->plcp_err);
826 PRINT_STATS_LE32("overrun_err", ht->overrun_err);
827 PRINT_STATS_LE32("early_overrun_err", ht->early_overrun_err);
828 PRINT_STATS_LE32("crc32_good", ht->crc32_good);
829 PRINT_STATS_LE32("crc32_err", ht->crc32_err);
830 PRINT_STATS_LE32("mh_format_err", ht->mh_format_err);
831 PRINT_STATS_LE32("agg_crc32_good", ht->agg_crc32_good);
832 PRINT_STATS_LE32("agg_mpdu_cnt", ht->agg_mpdu_cnt);
833 PRINT_STATS_LE32("agg_cnt", ht->agg_cnt);
834 PRINT_STATS_LE32("unsupport_mcs", ht->unsupport_mcs);
835
836 mutex_unlock(&mvm->mutex);
837
838 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
839 kfree(buf);
840
841 return ret;
842 }
843 #undef PRINT_STAT_LE32
844
845 static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
846 char __user *user_buf, size_t count,
847 loff_t *ppos,
848 struct iwl_mvm_frame_stats *stats)
849 {
850 char *buff, *pos, *endpos;
851 int idx, i;
852 int ret;
853 static const size_t bufsz = 1024;
854
855 buff = kmalloc(bufsz, GFP_KERNEL);
856 if (!buff)
857 return -ENOMEM;
858
859 spin_lock_bh(&mvm->drv_stats_lock);
860
861 pos = buff;
862 endpos = pos + bufsz;
863
864 pos += scnprintf(pos, endpos - pos,
865 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
866 stats->legacy_frames,
867 stats->ht_frames,
868 stats->vht_frames);
869 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
870 stats->bw_20_frames,
871 stats->bw_40_frames,
872 stats->bw_80_frames);
873 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
874 stats->ngi_frames,
875 stats->sgi_frames);
876 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
877 stats->siso_frames,
878 stats->mimo2_frames);
879 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
880 stats->fail_frames,
881 stats->success_frames);
882 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
883 stats->agg_frames);
884 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
885 stats->ampdu_count);
886 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
887 stats->ampdu_count > 0 ?
888 (stats->agg_frames / stats->ampdu_count) : 0);
889
890 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
891
892 idx = stats->last_frame_idx - 1;
893 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
894 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
895 if (stats->last_rates[idx] == 0)
896 continue;
897 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
898 (int)(ARRAY_SIZE(stats->last_rates) - i));
899 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
900 }
901 spin_unlock_bh(&mvm->drv_stats_lock);
902
903 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
904 kfree(buff);
905
906 return ret;
907 }
908
909 static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
910 char __user *user_buf, size_t count,
911 loff_t *ppos)
912 {
913 struct iwl_mvm *mvm = file->private_data;
914
915 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
916 &mvm->drv_rx_stats);
917 }
918
919 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
920 size_t count, loff_t *ppos)
921 {
922 int ret;
923
924 mutex_lock(&mvm->mutex);
925
926 /* allow one more restart that we're provoking here */
927 if (mvm->restart_fw >= 0)
928 mvm->restart_fw++;
929
930 /* take the return value to make compiler happy - it will fail anyway */
931 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
932
933 mutex_unlock(&mvm->mutex);
934
935 return count;
936 }
937
938 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
939 size_t count, loff_t *ppos)
940 {
941 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
942 if (ret)
943 return ret;
944
945 iwl_force_nmi(mvm->trans);
946
947 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
948
949 return count;
950 }
951
952 static ssize_t
953 iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
954 char __user *user_buf,
955 size_t count, loff_t *ppos)
956 {
957 struct iwl_mvm *mvm = file->private_data;
958 int pos = 0;
959 char buf[32];
960 const size_t bufsz = sizeof(buf);
961
962 /* print which antennas were set for the scan command by the user */
963 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
964 if (mvm->scan_rx_ant & ANT_A)
965 pos += scnprintf(buf + pos, bufsz - pos, "A");
966 if (mvm->scan_rx_ant & ANT_B)
967 pos += scnprintf(buf + pos, bufsz - pos, "B");
968 if (mvm->scan_rx_ant & ANT_C)
969 pos += scnprintf(buf + pos, bufsz - pos, "C");
970 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
971
972 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
973 }
974
975 static ssize_t
976 iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
977 size_t count, loff_t *ppos)
978 {
979 u8 scan_rx_ant;
980
981 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
982 return -EINVAL;
983 if (scan_rx_ant > ANT_ABC)
984 return -EINVAL;
985 if (scan_rx_ant & ~mvm->fw->valid_rx_ant)
986 return -EINVAL;
987
988 mvm->scan_rx_ant = scan_rx_ant;
989
990 return count;
991 }
992
993 #define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
994 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
995 static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
996 char __user *user_buf,
997 size_t count, loff_t *ppos)
998 {
999 struct iwl_mvm *mvm = file->private_data;
1000 struct iwl_bcast_filter_cmd cmd;
1001 const struct iwl_fw_bcast_filter *filter;
1002 char *buf;
1003 int bufsz = 1024;
1004 int i, j, pos = 0;
1005 ssize_t ret;
1006
1007 buf = kzalloc(bufsz, GFP_KERNEL);
1008 if (!buf)
1009 return -ENOMEM;
1010
1011 mutex_lock(&mvm->mutex);
1012 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1013 ADD_TEXT("None\n");
1014 mutex_unlock(&mvm->mutex);
1015 goto out;
1016 }
1017 mutex_unlock(&mvm->mutex);
1018
1019 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1020 filter = &cmd.filters[i];
1021
1022 ADD_TEXT("Filter [%d]:\n", i);
1023 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1024 ADD_TEXT("\tFrame Type: %s\n",
1025 filter->frame_type ? "IPv4" : "Generic");
1026
1027 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1028 const struct iwl_fw_bcast_filter_attr *attr;
1029
1030 attr = &filter->attrs[j];
1031 if (!attr->mask)
1032 break;
1033
1034 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1035 j, attr->offset,
1036 attr->offset_type ? "IP End" :
1037 "Payload Start",
1038 be32_to_cpu(attr->mask),
1039 be32_to_cpu(attr->val),
1040 le16_to_cpu(attr->reserved1));
1041 }
1042 }
1043 out:
1044 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1045 kfree(buf);
1046 return ret;
1047 }
1048
1049 static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1050 size_t count, loff_t *ppos)
1051 {
1052 int pos, next_pos;
1053 struct iwl_fw_bcast_filter filter = {};
1054 struct iwl_bcast_filter_cmd cmd;
1055 u32 filter_id, attr_id, mask, value;
1056 int err = 0;
1057
1058 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1059 &filter.frame_type, &pos) != 3)
1060 return -EINVAL;
1061
1062 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1063 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1064 return -EINVAL;
1065
1066 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1067 attr_id++) {
1068 struct iwl_fw_bcast_filter_attr *attr =
1069 &filter.attrs[attr_id];
1070
1071 if (pos >= count)
1072 break;
1073
1074 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1075 &attr->offset, &attr->offset_type,
1076 &mask, &value, &next_pos) != 4)
1077 return -EINVAL;
1078
1079 attr->mask = cpu_to_be32(mask);
1080 attr->val = cpu_to_be32(value);
1081 if (mask)
1082 filter.num_attrs++;
1083
1084 pos += next_pos;
1085 }
1086
1087 mutex_lock(&mvm->mutex);
1088 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1089 &filter, sizeof(filter));
1090
1091 /* send updated bcast filtering configuration */
1092 if (mvm->dbgfs_bcast_filtering.override &&
1093 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1094 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1095 sizeof(cmd), &cmd);
1096 mutex_unlock(&mvm->mutex);
1097
1098 return err ?: count;
1099 }
1100
1101 static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1102 char __user *user_buf,
1103 size_t count, loff_t *ppos)
1104 {
1105 struct iwl_mvm *mvm = file->private_data;
1106 struct iwl_bcast_filter_cmd cmd;
1107 char *buf;
1108 int bufsz = 1024;
1109 int i, pos = 0;
1110 ssize_t ret;
1111
1112 buf = kzalloc(bufsz, GFP_KERNEL);
1113 if (!buf)
1114 return -ENOMEM;
1115
1116 mutex_lock(&mvm->mutex);
1117 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1118 ADD_TEXT("None\n");
1119 mutex_unlock(&mvm->mutex);
1120 goto out;
1121 }
1122 mutex_unlock(&mvm->mutex);
1123
1124 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1125 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1126
1127 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1128 i, mac->default_discard, mac->attached_filters);
1129 }
1130 out:
1131 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1132 kfree(buf);
1133 return ret;
1134 }
1135
1136 static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1137 char *buf, size_t count,
1138 loff_t *ppos)
1139 {
1140 struct iwl_bcast_filter_cmd cmd;
1141 struct iwl_fw_bcast_mac mac = {};
1142 u32 mac_id, attached_filters;
1143 int err = 0;
1144
1145 if (!mvm->bcast_filters)
1146 return -ENOENT;
1147
1148 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1149 &attached_filters) != 3)
1150 return -EINVAL;
1151
1152 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1153 mac.default_discard > 1 ||
1154 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1155 return -EINVAL;
1156
1157 mac.attached_filters = cpu_to_le16(attached_filters);
1158
1159 mutex_lock(&mvm->mutex);
1160 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1161 &mac, sizeof(mac));
1162
1163 /* send updated bcast filtering configuration */
1164 if (mvm->dbgfs_bcast_filtering.override &&
1165 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1166 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1167 sizeof(cmd), &cmd);
1168 mutex_unlock(&mvm->mutex);
1169
1170 return err ?: count;
1171 }
1172 #endif
1173
1174 #ifdef CONFIG_PM_SLEEP
1175 static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
1176 size_t count, loff_t *ppos)
1177 {
1178 int store;
1179
1180 if (sscanf(buf, "%d", &store) != 1)
1181 return -EINVAL;
1182
1183 mvm->store_d3_resume_sram = store;
1184
1185 return count;
1186 }
1187
1188 static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1189 size_t count, loff_t *ppos)
1190 {
1191 struct iwl_mvm *mvm = file->private_data;
1192 const struct fw_img *img;
1193 int ofs, len, pos = 0;
1194 size_t bufsz, ret;
1195 char *buf;
1196 u8 *ptr = mvm->d3_resume_sram;
1197
1198 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1199 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1200
1201 bufsz = len * 4 + 256;
1202 buf = kzalloc(bufsz, GFP_KERNEL);
1203 if (!buf)
1204 return -ENOMEM;
1205
1206 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1207 mvm->store_d3_resume_sram ? "en" : "dis");
1208
1209 if (ptr) {
1210 for (ofs = 0; ofs < len; ofs += 16) {
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 "0x%.4x ", ofs);
1213 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
1214 bufsz - pos, false);
1215 pos += strlen(buf + pos);
1216 if (bufsz - pos > 0)
1217 buf[pos++] = '\n';
1218 }
1219 } else {
1220 pos += scnprintf(buf + pos, bufsz - pos,
1221 "(no data captured)\n");
1222 }
1223
1224 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1225
1226 kfree(buf);
1227
1228 return ret;
1229 }
1230 #endif
1231
1232 #define PRINT_MVM_REF(ref) do { \
1233 if (mvm->refs[ref]) \
1234 pos += scnprintf(buf + pos, bufsz - pos, \
1235 "\t(0x%lx): %d %s\n", \
1236 BIT(ref), mvm->refs[ref], #ref); \
1237 } while (0)
1238
1239 static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1240 char __user *user_buf,
1241 size_t count, loff_t *ppos)
1242 {
1243 struct iwl_mvm *mvm = file->private_data;
1244 int i, pos = 0;
1245 char buf[256];
1246 const size_t bufsz = sizeof(buf);
1247 u32 refs = 0;
1248
1249 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1250 if (mvm->refs[i])
1251 refs |= BIT(i);
1252
1253 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1254 refs);
1255
1256 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1257 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1258 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1259 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1260 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
1261 PRINT_MVM_REF(IWL_MVM_REF_USER);
1262 PRINT_MVM_REF(IWL_MVM_REF_TX);
1263 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1264 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1265 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1266 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1267 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1268 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1269 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1270 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1271 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1272 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1273 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
1274 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
1275
1276 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1277 }
1278
1279 static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1280 size_t count, loff_t *ppos)
1281 {
1282 unsigned long value;
1283 int ret;
1284 bool taken;
1285
1286 ret = kstrtoul(buf, 10, &value);
1287 if (ret < 0)
1288 return ret;
1289
1290 mutex_lock(&mvm->mutex);
1291
1292 taken = mvm->refs[IWL_MVM_REF_USER];
1293 if (value == 1 && !taken)
1294 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1295 else if (value == 0 && taken)
1296 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1297 else
1298 ret = -EINVAL;
1299
1300 mutex_unlock(&mvm->mutex);
1301
1302 if (ret < 0)
1303 return ret;
1304 return count;
1305 }
1306
1307 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1308 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1309 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1310 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1311 #define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1312 if (!debugfs_create_file(alias, mode, parent, mvm, \
1313 &iwl_dbgfs_##name##_ops)) \
1314 goto err; \
1315 } while (0)
1316 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1317 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1318
1319 static ssize_t
1320 iwl_dbgfs_prph_reg_read(struct file *file,
1321 char __user *user_buf,
1322 size_t count, loff_t *ppos)
1323 {
1324 struct iwl_mvm *mvm = file->private_data;
1325 int pos = 0;
1326 char buf[32];
1327 const size_t bufsz = sizeof(buf);
1328 int ret;
1329
1330 if (!mvm->dbgfs_prph_reg_addr)
1331 return -EINVAL;
1332
1333 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1334 if (ret)
1335 return ret;
1336
1337 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1338 mvm->dbgfs_prph_reg_addr,
1339 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1340
1341 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1342
1343 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1344 }
1345
1346 static ssize_t
1347 iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1348 size_t count, loff_t *ppos)
1349 {
1350 u8 args;
1351 u32 value;
1352 int ret;
1353
1354 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1355 /* if we only want to set the reg address - nothing more to do */
1356 if (args == 1)
1357 goto out;
1358
1359 /* otherwise, make sure we have both address and value */
1360 if (args != 2)
1361 return -EINVAL;
1362
1363 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1364 if (ret)
1365 return ret;
1366
1367 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1368
1369 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1370 out:
1371 return count;
1372 }
1373
1374 MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1375
1376 /* Device wide debugfs entries */
1377 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1378 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1379 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1380 MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
1381 MVM_DEBUGFS_READ_FILE_OPS(stations);
1382 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1383 MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1384 MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1385 MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1386 MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1387 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1388 MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1389 MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1390 MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1391 MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1392 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1393
1394 static const struct file_operations iwl_dbgfs_fw_error_dump_ops = {
1395 .open = iwl_dbgfs_fw_error_dump_open,
1396 .read = iwl_dbgfs_fw_error_dump_read,
1397 .release = iwl_dbgfs_fw_error_dump_release,
1398 };
1399
1400 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1401 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1402 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1403 #endif
1404
1405 #ifdef CONFIG_PM_SLEEP
1406 MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1407 #endif
1408
1409 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1410 {
1411 struct dentry *bcast_dir __maybe_unused;
1412 char buf[100];
1413
1414 spin_lock_init(&mvm->drv_stats_lock);
1415
1416 mvm->debugfs_dir = dbgfs_dir;
1417
1418 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1419 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1420 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1421 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1422 S_IWUSR | S_IRUSR);
1423 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1424 MVM_DEBUGFS_ADD_FILE(fw_error_dump, dbgfs_dir, S_IRUSR);
1425 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1426 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1427 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1428 S_IRUSR | S_IWUSR);
1429 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1430 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
1431 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1432 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
1433 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
1434 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
1435 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1436 S_IWUSR | S_IRUSR);
1437 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1438 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1439
1440 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1441 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1442 bcast_dir = debugfs_create_dir("bcast_filtering",
1443 mvm->debugfs_dir);
1444 if (!bcast_dir)
1445 goto err;
1446
1447 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1448 bcast_dir,
1449 &mvm->dbgfs_bcast_filtering.override))
1450 goto err;
1451
1452 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1453 bcast_dir, S_IWUSR | S_IRUSR);
1454 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1455 bcast_dir, S_IWUSR | S_IRUSR);
1456 }
1457 #endif
1458
1459 #ifdef CONFIG_PM_SLEEP
1460 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1461 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1462 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1463 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1464 goto err;
1465 #endif
1466
1467 if (!debugfs_create_u8("low_latency_agg_frame_limit", S_IRUSR | S_IWUSR,
1468 mvm->debugfs_dir,
1469 &mvm->low_latency_agg_frame_limit))
1470 goto err;
1471 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1472 mvm->debugfs_dir, &mvm->ps_disabled))
1473 goto err;
1474 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1475 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1476 goto err;
1477 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1478 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1479 goto err;
1480 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1481 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1482 goto err;
1483 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1484 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1485 goto err;
1486
1487 /*
1488 * Create a symlink with mac80211. It will be removed when mac80211
1489 * exists (before the opmode exists which removes the target.)
1490 */
1491 snprintf(buf, 100, "../../%s/%s",
1492 dbgfs_dir->d_parent->d_parent->d_name.name,
1493 dbgfs_dir->d_parent->d_name.name);
1494 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1495 goto err;
1496
1497 return 0;
1498 err:
1499 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1500 return -ENOMEM;
1501 }
This page took 0.066456 seconds and 5 git commands to generate.