Loading...
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 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * USA
26 *
27 * The full GNU General Public License is included in this distribution
28 * in the file called COPYING.
29 *
30 * Contact Information:
31 * Intel Linux Wireless <linuxwifi@intel.com>
32 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 *
34 * BSD LICENSE
35 *
36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * Copyright(c) 2018 Intel Corporation
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 *
46 * * Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * * Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in
50 * the documentation and/or other materials provided with the
51 * distribution.
52 * * Neither the name Intel Corporation nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 *****************************************************************************/
69#include <linux/vmalloc.h>
70#include <linux/ieee80211.h>
71#include <linux/netdevice.h>
72
73#include "mvm.h"
74#include "sta.h"
75#include "iwl-io.h"
76#include "debugfs.h"
77#include "fw/error-dump.h"
78
79static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
80 char __user *user_buf,
81 size_t count, loff_t *ppos)
82{
83 struct iwl_mvm *mvm = file->private_data;
84 char buf[16];
85 int pos, budget;
86
87 if (!iwl_mvm_is_ctdp_supported(mvm))
88 return -EOPNOTSUPP;
89
90 if (!iwl_mvm_firmware_running(mvm) ||
91 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
92 return -EIO;
93
94 mutex_lock(&mvm->mutex);
95 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
96 mutex_unlock(&mvm->mutex);
97
98 if (budget < 0)
99 return budget;
100
101 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
102
103 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
104}
105
106static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
107 size_t count, loff_t *ppos)
108{
109 int ret;
110
111 if (!iwl_mvm_is_ctdp_supported(mvm))
112 return -EOPNOTSUPP;
113
114 if (!iwl_mvm_firmware_running(mvm) ||
115 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
116 return -EIO;
117
118 mutex_lock(&mvm->mutex);
119 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
120 mutex_unlock(&mvm->mutex);
121
122 return ret ?: count;
123}
124
125static ssize_t iwl_dbgfs_force_ctkill_write(struct iwl_mvm *mvm, char *buf,
126 size_t count, loff_t *ppos)
127{
128 if (!iwl_mvm_firmware_running(mvm) ||
129 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
130 return -EIO;
131
132 iwl_mvm_enter_ctkill(mvm);
133
134 return count;
135}
136
137static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
138 size_t count, loff_t *ppos)
139{
140 int ret;
141 u32 flush_arg;
142
143 if (!iwl_mvm_firmware_running(mvm) ||
144 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
145 return -EIO;
146
147 if (kstrtou32(buf, 0, &flush_arg))
148 return -EINVAL;
149
150 if (iwl_mvm_has_new_tx_api(mvm)) {
151 IWL_DEBUG_TX_QUEUES(mvm,
152 "FLUSHING all tids queues on sta_id = %d\n",
153 flush_arg);
154 mutex_lock(&mvm->mutex);
155 ret = iwl_mvm_flush_sta_tids(mvm, flush_arg, 0xFF, 0) ? : count;
156 mutex_unlock(&mvm->mutex);
157 return ret;
158 }
159
160 IWL_DEBUG_TX_QUEUES(mvm, "FLUSHING queues mask to flush = 0x%x\n",
161 flush_arg);
162
163 mutex_lock(&mvm->mutex);
164 ret = iwl_mvm_flush_tx_path(mvm, flush_arg, 0) ? : count;
165 mutex_unlock(&mvm->mutex);
166
167 return ret;
168}
169
170static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
171 size_t count, loff_t *ppos)
172{
173 struct iwl_mvm_sta *mvmsta;
174 int sta_id, drain, ret;
175
176 if (!iwl_mvm_firmware_running(mvm) ||
177 mvm->fwrt.cur_fw_img != IWL_UCODE_REGULAR)
178 return -EIO;
179
180 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
181 return -EINVAL;
182 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
183 return -EINVAL;
184 if (drain < 0 || drain > 1)
185 return -EINVAL;
186
187 mutex_lock(&mvm->mutex);
188
189 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
190
191 if (!mvmsta)
192 ret = -ENOENT;
193 else
194 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
195
196 mutex_unlock(&mvm->mutex);
197
198 return ret;
199}
200
201static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
202 size_t count, loff_t *ppos)
203{
204 struct iwl_mvm *mvm = file->private_data;
205 const struct fw_img *img;
206 unsigned int ofs, len;
207 size_t ret;
208 u8 *ptr;
209
210 if (!iwl_mvm_firmware_running(mvm))
211 return -EINVAL;
212
213 /* default is to dump the entire data segment */
214 img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
215 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
216 len = img->sec[IWL_UCODE_SECTION_DATA].len;
217
218 if (mvm->dbgfs_sram_len) {
219 ofs = mvm->dbgfs_sram_offset;
220 len = mvm->dbgfs_sram_len;
221 }
222
223 ptr = kzalloc(len, GFP_KERNEL);
224 if (!ptr)
225 return -ENOMEM;
226
227 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
228
229 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
230
231 kfree(ptr);
232
233 return ret;
234}
235
236static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
237 size_t count, loff_t *ppos)
238{
239 const struct fw_img *img;
240 u32 offset, len;
241 u32 img_offset, img_len;
242
243 if (!iwl_mvm_firmware_running(mvm))
244 return -EINVAL;
245
246 img = &mvm->fw->img[mvm->fwrt.cur_fw_img];
247 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
248 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
249
250 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
251 if ((offset & 0x3) || (len & 0x3))
252 return -EINVAL;
253
254 if (offset + len > img_offset + img_len)
255 return -EINVAL;
256
257 mvm->dbgfs_sram_offset = offset;
258 mvm->dbgfs_sram_len = len;
259 } else {
260 mvm->dbgfs_sram_offset = 0;
261 mvm->dbgfs_sram_len = 0;
262 }
263
264 return count;
265}
266
267static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
268 char __user *user_buf,
269 size_t count, loff_t *ppos)
270{
271 struct iwl_mvm *mvm = file->private_data;
272 char buf[16];
273 int pos;
274
275 if (!mvm->temperature_test)
276 pos = scnprintf(buf , sizeof(buf), "disabled\n");
277 else
278 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
279
280 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
281}
282
283/*
284 * Set NIC Temperature
285 * Cause the driver to ignore the actual NIC temperature reported by the FW
286 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
287 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
288 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
289 */
290static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
291 char *buf, size_t count,
292 loff_t *ppos)
293{
294 int temperature;
295
296 if (!iwl_mvm_firmware_running(mvm) && !mvm->temperature_test)
297 return -EIO;
298
299 if (kstrtoint(buf, 10, &temperature))
300 return -EINVAL;
301 /* not a legal temperature */
302 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
303 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
304 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
305 return -EINVAL;
306
307 mutex_lock(&mvm->mutex);
308 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
309 if (!mvm->temperature_test)
310 goto out;
311
312 mvm->temperature_test = false;
313 /* Since we can't read the temp while awake, just set
314 * it to zero until we get the next RX stats from the
315 * firmware.
316 */
317 mvm->temperature = 0;
318 } else {
319 mvm->temperature_test = true;
320 mvm->temperature = temperature;
321 }
322 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
323 mvm->temperature_test ? "En" : "Dis" ,
324 mvm->temperature);
325 /* handle the temperature change */
326 iwl_mvm_tt_handler(mvm);
327
328out:
329 mutex_unlock(&mvm->mutex);
330
331 return count;
332}
333
334static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
335 char __user *user_buf,
336 size_t count, loff_t *ppos)
337{
338 struct iwl_mvm *mvm = file->private_data;
339 char buf[16];
340 int pos, ret;
341 s32 temp;
342
343 if (!iwl_mvm_firmware_running(mvm))
344 return -EIO;
345
346 mutex_lock(&mvm->mutex);
347 ret = iwl_mvm_get_temp(mvm, &temp);
348 mutex_unlock(&mvm->mutex);
349
350 if (ret)
351 return -EIO;
352
353 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
354
355 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
356}
357
358#ifdef CONFIG_ACPI
359static ssize_t iwl_dbgfs_sar_geo_profile_read(struct file *file,
360 char __user *user_buf,
361 size_t count, loff_t *ppos)
362{
363 struct iwl_mvm *mvm = file->private_data;
364 char buf[256];
365 int pos = 0;
366 int bufsz = sizeof(buf);
367 int tbl_idx;
368 u8 *value;
369
370 if (!iwl_mvm_firmware_running(mvm))
371 return -EIO;
372
373 mutex_lock(&mvm->mutex);
374 tbl_idx = iwl_mvm_get_sar_geo_profile(mvm);
375 if (tbl_idx < 0) {
376 mutex_unlock(&mvm->mutex);
377 return tbl_idx;
378 }
379
380 if (!tbl_idx) {
381 pos = scnprintf(buf, bufsz,
382 "SAR geographic profile disabled\n");
383 } else {
384 value = &mvm->geo_profiles[tbl_idx - 1].values[0];
385
386 pos += scnprintf(buf + pos, bufsz - pos,
387 "Use geographic profile %d\n", tbl_idx);
388 pos += scnprintf(buf + pos, bufsz - pos,
389 "2.4GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
390 value[1], value[2], value[0]);
391 pos += scnprintf(buf + pos, bufsz - pos,
392 "5.2GHz:\n\tChain A offset: %hhd dBm\n\tChain B offset: %hhd dBm\n\tmax tx power: %hhd dBm\n",
393 value[4], value[5], value[3]);
394 }
395 mutex_unlock(&mvm->mutex);
396
397 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
398}
399#endif
400
401static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
402 size_t count, loff_t *ppos)
403{
404 struct iwl_mvm *mvm = file->private_data;
405 struct ieee80211_sta *sta;
406 char buf[400];
407 int i, pos = 0, bufsz = sizeof(buf);
408
409 mutex_lock(&mvm->mutex);
410
411 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
412 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
413 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
414 lockdep_is_held(&mvm->mutex));
415 if (!sta)
416 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
417 else if (IS_ERR(sta))
418 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
419 PTR_ERR(sta));
420 else
421 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
422 sta->addr);
423 }
424
425 mutex_unlock(&mvm->mutex);
426
427 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
428}
429
430static ssize_t iwl_dbgfs_rs_data_read(struct file *file, char __user *user_buf,
431 size_t count, loff_t *ppos)
432{
433 struct ieee80211_sta *sta = file->private_data;
434 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
435 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
436 struct iwl_mvm *mvm = lq_sta->pers.drv;
437 static const size_t bufsz = 2048;
438 char *buff;
439 int desc = 0;
440 ssize_t ret;
441
442 buff = kmalloc(bufsz, GFP_KERNEL);
443 if (!buff)
444 return -ENOMEM;
445
446 mutex_lock(&mvm->mutex);
447
448 desc += scnprintf(buff + desc, bufsz - desc, "sta_id %d\n",
449 lq_sta->pers.sta_id);
450 desc += scnprintf(buff + desc, bufsz - desc,
451 "fixed rate 0x%X\n",
452 lq_sta->pers.dbg_fixed_rate);
453 desc += scnprintf(buff + desc, bufsz - desc,
454 "A-MPDU size limit %d\n",
455 lq_sta->pers.dbg_agg_frame_count_lim);
456 desc += scnprintf(buff + desc, bufsz - desc,
457 "valid_tx_ant %s%s%s\n",
458 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_A) ? "ANT_A," : "",
459 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_B) ? "ANT_B," : "",
460 (iwl_mvm_get_valid_tx_ant(mvm) & ANT_C) ? "ANT_C" : "");
461 desc += scnprintf(buff + desc, bufsz - desc,
462 "last tx rate=0x%X ",
463 lq_sta->last_rate_n_flags);
464
465 desc += rs_pretty_print_rate(buff + desc, bufsz - desc,
466 lq_sta->last_rate_n_flags);
467 mutex_unlock(&mvm->mutex);
468
469 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
470 kfree(buff);
471 return ret;
472}
473
474static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
475 char __user *user_buf,
476 size_t count, loff_t *ppos)
477{
478 struct iwl_mvm *mvm = file->private_data;
479 char buf[64];
480 int bufsz = sizeof(buf);
481 int pos = 0;
482
483 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
484 mvm->disable_power_off);
485 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
486 mvm->disable_power_off_d3);
487
488 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
489}
490
491static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
492 size_t count, loff_t *ppos)
493{
494 int ret, val;
495
496 if (!iwl_mvm_firmware_running(mvm))
497 return -EIO;
498
499 if (!strncmp("disable_power_off_d0=", buf, 21)) {
500 if (sscanf(buf + 21, "%d", &val) != 1)
501 return -EINVAL;
502 mvm->disable_power_off = val;
503 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
504 if (sscanf(buf + 21, "%d", &val) != 1)
505 return -EINVAL;
506 mvm->disable_power_off_d3 = val;
507 } else {
508 return -EINVAL;
509 }
510
511 mutex_lock(&mvm->mutex);
512 ret = iwl_mvm_power_update_device(mvm);
513 mutex_unlock(&mvm->mutex);
514
515 return ret ?: count;
516}
517
518static
519int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
520 int pos, int bufsz)
521{
522 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
523
524 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
525 BT_MBOX_PRINT(0, LE_PROF1, false);
526 BT_MBOX_PRINT(0, LE_PROF2, false);
527 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
528 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
529 BT_MBOX_PRINT(0, INBAND_S, false);
530 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
531 BT_MBOX_PRINT(0, LE_SCAN, false);
532 BT_MBOX_PRINT(0, LE_ADV, false);
533 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
534 BT_MBOX_PRINT(0, OPEN_CON_1, true);
535
536 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
537
538 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
539 BT_MBOX_PRINT(1, IP_SR, false);
540 BT_MBOX_PRINT(1, LE_MSTR, false);
541 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
542 BT_MBOX_PRINT(1, MSG_TYPE, false);
543 BT_MBOX_PRINT(1, SSN, true);
544
545 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
546
547 BT_MBOX_PRINT(2, SNIFF_ACT, false);
548 BT_MBOX_PRINT(2, PAG, false);
549 BT_MBOX_PRINT(2, INQUIRY, false);
550 BT_MBOX_PRINT(2, CONN, false);
551 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
552 BT_MBOX_PRINT(2, DISC, false);
553 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
554 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
555 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
556 BT_MBOX_PRINT(2, SCO_DURATION, true);
557
558 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
559
560 BT_MBOX_PRINT(3, SCO_STATE, false);
561 BT_MBOX_PRINT(3, SNIFF_STATE, false);
562 BT_MBOX_PRINT(3, A2DP_STATE, false);
563 BT_MBOX_PRINT(3, A2DP_SRC, false);
564 BT_MBOX_PRINT(3, ACL_STATE, false);
565 BT_MBOX_PRINT(3, MSTR_STATE, false);
566 BT_MBOX_PRINT(3, OBX_STATE, false);
567 BT_MBOX_PRINT(3, OPEN_CON_2, false);
568 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
569 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
570 BT_MBOX_PRINT(3, INBAND_P, false);
571 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
572 BT_MBOX_PRINT(3, SSN_2, false);
573 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
574
575 return pos;
576}
577
578static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
579 size_t count, loff_t *ppos)
580{
581 struct iwl_mvm *mvm = file->private_data;
582 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
583 char *buf;
584 int ret, pos = 0, bufsz = sizeof(char) * 1024;
585
586 buf = kmalloc(bufsz, GFP_KERNEL);
587 if (!buf)
588 return -ENOMEM;
589
590 mutex_lock(&mvm->mutex);
591
592 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
593
594 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
595 notif->bt_ci_compliance);
596 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
597 le32_to_cpu(notif->primary_ch_lut));
598 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
599 le32_to_cpu(notif->secondary_ch_lut));
600 pos += scnprintf(buf + pos,
601 bufsz - pos, "bt_activity_grading = %d\n",
602 le32_to_cpu(notif->bt_activity_grading));
603 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
604 notif->rrc_status & 0xF);
605 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
606 notif->ttc_status & 0xF);
607
608 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
609 IWL_MVM_BT_COEX_SYNC2SCO);
610 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
611 IWL_MVM_BT_COEX_MPLUT);
612
613 mutex_unlock(&mvm->mutex);
614
615 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
616 kfree(buf);
617
618 return ret;
619}
620#undef BT_MBOX_PRINT
621
622static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
623 size_t count, loff_t *ppos)
624{
625 struct iwl_mvm *mvm = file->private_data;
626 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
627 char buf[256];
628 int bufsz = sizeof(buf);
629 int pos = 0;
630
631 mutex_lock(&mvm->mutex);
632
633 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
634 pos += scnprintf(buf + pos, bufsz - pos,
635 "\tPrimary Channel Bitmap 0x%016llx\n",
636 le64_to_cpu(cmd->bt_primary_ci));
637 pos += scnprintf(buf + pos, bufsz - pos,
638 "\tSecondary Channel Bitmap 0x%016llx\n",
639 le64_to_cpu(cmd->bt_secondary_ci));
640
641 mutex_unlock(&mvm->mutex);
642
643 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
644}
645
646static ssize_t
647iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
648 size_t count, loff_t *ppos)
649{
650 u32 bt_tx_prio;
651
652 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
653 return -EINVAL;
654 if (bt_tx_prio > 4)
655 return -EINVAL;
656
657 mvm->bt_tx_prio = bt_tx_prio;
658
659 return count;
660}
661
662static ssize_t
663iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
664 size_t count, loff_t *ppos)
665{
666 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
667 [BT_FORCE_ANT_DIS] = "dis",
668 [BT_FORCE_ANT_AUTO] = "auto",
669 [BT_FORCE_ANT_BT] = "bt",
670 [BT_FORCE_ANT_WIFI] = "wifi",
671 };
672 int ret, bt_force_ant_mode;
673
674 for (bt_force_ant_mode = 0;
675 bt_force_ant_mode < ARRAY_SIZE(modes_str);
676 bt_force_ant_mode++) {
677 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
678 break;
679 }
680
681 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
682 return -EINVAL;
683
684 ret = 0;
685 mutex_lock(&mvm->mutex);
686 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
687 goto out;
688
689 mvm->bt_force_ant_mode = bt_force_ant_mode;
690 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
691 modes_str[mvm->bt_force_ant_mode]);
692
693 if (iwl_mvm_firmware_running(mvm))
694 ret = iwl_mvm_send_bt_init_conf(mvm);
695 else
696 ret = 0;
697
698out:
699 mutex_unlock(&mvm->mutex);
700 return ret ?: count;
701}
702
703static ssize_t iwl_dbgfs_fw_ver_read(struct file *file, char __user *user_buf,
704 size_t count, loff_t *ppos)
705{
706 struct iwl_mvm *mvm = file->private_data;
707 char *buff, *pos, *endpos;
708 static const size_t bufsz = 1024;
709 int ret;
710
711 buff = kmalloc(bufsz, GFP_KERNEL);
712 if (!buff)
713 return -ENOMEM;
714
715 pos = buff;
716 endpos = pos + bufsz;
717
718 pos += scnprintf(pos, endpos - pos, "FW prefix: %s\n",
719 mvm->trans->cfg->fw_name_pre);
720 pos += scnprintf(pos, endpos - pos, "FW: %s\n",
721 mvm->fwrt.fw->human_readable);
722 pos += scnprintf(pos, endpos - pos, "Device: %s\n",
723 mvm->fwrt.trans->cfg->name);
724 pos += scnprintf(pos, endpos - pos, "Bus: %s\n",
725 mvm->fwrt.dev->bus->name);
726
727 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
728 kfree(buff);
729
730 return ret;
731}
732
733#define PRINT_STATS_LE32(_struct, _memb) \
734 pos += scnprintf(buf + pos, bufsz - pos, \
735 fmt_table, #_memb, \
736 le32_to_cpu(_struct->_memb))
737
738static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
739 char __user *user_buf, size_t count,
740 loff_t *ppos)
741{
742 struct iwl_mvm *mvm = file->private_data;
743 static const char *fmt_table = "\t%-30s %10u\n";
744 static const char *fmt_header = "%-32s\n";
745 int pos = 0;
746 char *buf;
747 int ret;
748 size_t bufsz;
749
750 if (iwl_mvm_has_new_rx_stats_api(mvm))
751 bufsz = ((sizeof(struct mvm_statistics_rx) /
752 sizeof(__le32)) * 43) + (4 * 33) + 1;
753 else
754 /* 43 = size of each data line; 33 = size of each header */
755 bufsz = ((sizeof(struct mvm_statistics_rx_v3) /
756 sizeof(__le32)) * 43) + (4 * 33) + 1;
757
758 buf = kzalloc(bufsz, GFP_KERNEL);
759 if (!buf)
760 return -ENOMEM;
761
762 mutex_lock(&mvm->mutex);
763
764 if (iwl_mvm_firmware_running(mvm))
765 iwl_mvm_request_statistics(mvm, false);
766
767 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
768 "Statistics_Rx - OFDM");
769 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
770 struct mvm_statistics_rx_phy_v2 *ofdm = &mvm->rx_stats_v3.ofdm;
771
772 PRINT_STATS_LE32(ofdm, ina_cnt);
773 PRINT_STATS_LE32(ofdm, fina_cnt);
774 PRINT_STATS_LE32(ofdm, plcp_err);
775 PRINT_STATS_LE32(ofdm, crc32_err);
776 PRINT_STATS_LE32(ofdm, overrun_err);
777 PRINT_STATS_LE32(ofdm, early_overrun_err);
778 PRINT_STATS_LE32(ofdm, crc32_good);
779 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
780 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
781 PRINT_STATS_LE32(ofdm, sfd_timeout);
782 PRINT_STATS_LE32(ofdm, fina_timeout);
783 PRINT_STATS_LE32(ofdm, unresponded_rts);
784 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
785 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
786 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
787 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
788 PRINT_STATS_LE32(ofdm, dsp_self_kill);
789 PRINT_STATS_LE32(ofdm, mh_format_err);
790 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
791 PRINT_STATS_LE32(ofdm, reserved);
792 } else {
793 struct mvm_statistics_rx_phy *ofdm = &mvm->rx_stats.ofdm;
794
795 PRINT_STATS_LE32(ofdm, unresponded_rts);
796 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
797 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
798 PRINT_STATS_LE32(ofdm, dsp_self_kill);
799 PRINT_STATS_LE32(ofdm, reserved);
800 }
801
802 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
803 "Statistics_Rx - CCK");
804 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
805 struct mvm_statistics_rx_phy_v2 *cck = &mvm->rx_stats_v3.cck;
806
807 PRINT_STATS_LE32(cck, ina_cnt);
808 PRINT_STATS_LE32(cck, fina_cnt);
809 PRINT_STATS_LE32(cck, plcp_err);
810 PRINT_STATS_LE32(cck, crc32_err);
811 PRINT_STATS_LE32(cck, overrun_err);
812 PRINT_STATS_LE32(cck, early_overrun_err);
813 PRINT_STATS_LE32(cck, crc32_good);
814 PRINT_STATS_LE32(cck, false_alarm_cnt);
815 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
816 PRINT_STATS_LE32(cck, sfd_timeout);
817 PRINT_STATS_LE32(cck, fina_timeout);
818 PRINT_STATS_LE32(cck, unresponded_rts);
819 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
820 PRINT_STATS_LE32(cck, sent_ack_cnt);
821 PRINT_STATS_LE32(cck, sent_cts_cnt);
822 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
823 PRINT_STATS_LE32(cck, dsp_self_kill);
824 PRINT_STATS_LE32(cck, mh_format_err);
825 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
826 PRINT_STATS_LE32(cck, reserved);
827 } else {
828 struct mvm_statistics_rx_phy *cck = &mvm->rx_stats.cck;
829
830 PRINT_STATS_LE32(cck, unresponded_rts);
831 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
832 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
833 PRINT_STATS_LE32(cck, dsp_self_kill);
834 PRINT_STATS_LE32(cck, reserved);
835 }
836
837 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
838 "Statistics_Rx - GENERAL");
839 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
840 struct mvm_statistics_rx_non_phy_v3 *general =
841 &mvm->rx_stats_v3.general;
842
843 PRINT_STATS_LE32(general, bogus_cts);
844 PRINT_STATS_LE32(general, bogus_ack);
845 PRINT_STATS_LE32(general, non_bssid_frames);
846 PRINT_STATS_LE32(general, filtered_frames);
847 PRINT_STATS_LE32(general, non_channel_beacons);
848 PRINT_STATS_LE32(general, channel_beacons);
849 PRINT_STATS_LE32(general, num_missed_bcon);
850 PRINT_STATS_LE32(general, adc_rx_saturation_time);
851 PRINT_STATS_LE32(general, ina_detection_search_time);
852 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
853 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
854 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
855 PRINT_STATS_LE32(general, interference_data_flag);
856 PRINT_STATS_LE32(general, channel_load);
857 PRINT_STATS_LE32(general, dsp_false_alarms);
858 PRINT_STATS_LE32(general, beacon_rssi_a);
859 PRINT_STATS_LE32(general, beacon_rssi_b);
860 PRINT_STATS_LE32(general, beacon_rssi_c);
861 PRINT_STATS_LE32(general, beacon_energy_a);
862 PRINT_STATS_LE32(general, beacon_energy_b);
863 PRINT_STATS_LE32(general, beacon_energy_c);
864 PRINT_STATS_LE32(general, num_bt_kills);
865 PRINT_STATS_LE32(general, mac_id);
866 PRINT_STATS_LE32(general, directed_data_mpdu);
867 } else {
868 struct mvm_statistics_rx_non_phy *general =
869 &mvm->rx_stats.general;
870
871 PRINT_STATS_LE32(general, bogus_cts);
872 PRINT_STATS_LE32(general, bogus_ack);
873 PRINT_STATS_LE32(general, non_channel_beacons);
874 PRINT_STATS_LE32(general, channel_beacons);
875 PRINT_STATS_LE32(general, num_missed_bcon);
876 PRINT_STATS_LE32(general, adc_rx_saturation_time);
877 PRINT_STATS_LE32(general, ina_detection_search_time);
878 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
879 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
880 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
881 PRINT_STATS_LE32(general, interference_data_flag);
882 PRINT_STATS_LE32(general, channel_load);
883 PRINT_STATS_LE32(general, beacon_rssi_a);
884 PRINT_STATS_LE32(general, beacon_rssi_b);
885 PRINT_STATS_LE32(general, beacon_rssi_c);
886 PRINT_STATS_LE32(general, beacon_energy_a);
887 PRINT_STATS_LE32(general, beacon_energy_b);
888 PRINT_STATS_LE32(general, beacon_energy_c);
889 PRINT_STATS_LE32(general, num_bt_kills);
890 PRINT_STATS_LE32(general, mac_id);
891 }
892
893 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
894 "Statistics_Rx - HT");
895 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
896 struct mvm_statistics_rx_ht_phy_v1 *ht =
897 &mvm->rx_stats_v3.ofdm_ht;
898
899 PRINT_STATS_LE32(ht, plcp_err);
900 PRINT_STATS_LE32(ht, overrun_err);
901 PRINT_STATS_LE32(ht, early_overrun_err);
902 PRINT_STATS_LE32(ht, crc32_good);
903 PRINT_STATS_LE32(ht, crc32_err);
904 PRINT_STATS_LE32(ht, mh_format_err);
905 PRINT_STATS_LE32(ht, agg_crc32_good);
906 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
907 PRINT_STATS_LE32(ht, agg_cnt);
908 PRINT_STATS_LE32(ht, unsupport_mcs);
909 } else {
910 struct mvm_statistics_rx_ht_phy *ht =
911 &mvm->rx_stats.ofdm_ht;
912
913 PRINT_STATS_LE32(ht, mh_format_err);
914 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
915 PRINT_STATS_LE32(ht, agg_cnt);
916 PRINT_STATS_LE32(ht, unsupport_mcs);
917 }
918
919 mutex_unlock(&mvm->mutex);
920
921 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
922 kfree(buf);
923
924 return ret;
925}
926#undef PRINT_STAT_LE32
927
928static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
929 char __user *user_buf, size_t count,
930 loff_t *ppos,
931 struct iwl_mvm_frame_stats *stats)
932{
933 char *buff, *pos, *endpos;
934 int idx, i;
935 int ret;
936 static const size_t bufsz = 1024;
937
938 buff = kmalloc(bufsz, GFP_KERNEL);
939 if (!buff)
940 return -ENOMEM;
941
942 spin_lock_bh(&mvm->drv_stats_lock);
943
944 pos = buff;
945 endpos = pos + bufsz;
946
947 pos += scnprintf(pos, endpos - pos,
948 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
949 stats->legacy_frames,
950 stats->ht_frames,
951 stats->vht_frames);
952 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
953 stats->bw_20_frames,
954 stats->bw_40_frames,
955 stats->bw_80_frames);
956 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
957 stats->ngi_frames,
958 stats->sgi_frames);
959 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
960 stats->siso_frames,
961 stats->mimo2_frames);
962 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
963 stats->fail_frames,
964 stats->success_frames);
965 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
966 stats->agg_frames);
967 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
968 stats->ampdu_count);
969 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
970 stats->ampdu_count > 0 ?
971 (stats->agg_frames / stats->ampdu_count) : 0);
972
973 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
974
975 idx = stats->last_frame_idx - 1;
976 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
977 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
978 if (stats->last_rates[idx] == 0)
979 continue;
980 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
981 (int)(ARRAY_SIZE(stats->last_rates) - i));
982 pos += rs_pretty_print_rate(pos, endpos - pos,
983 stats->last_rates[idx]);
984 }
985 spin_unlock_bh(&mvm->drv_stats_lock);
986
987 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
988 kfree(buff);
989
990 return ret;
991}
992
993static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
994 char __user *user_buf, size_t count,
995 loff_t *ppos)
996{
997 struct iwl_mvm *mvm = file->private_data;
998
999 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
1000 &mvm->drv_rx_stats);
1001}
1002
1003static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
1004 size_t count, loff_t *ppos)
1005{
1006 int __maybe_unused ret;
1007
1008 if (!iwl_mvm_firmware_running(mvm))
1009 return -EIO;
1010
1011 mutex_lock(&mvm->mutex);
1012
1013 /* allow one more restart that we're provoking here */
1014 if (mvm->fw_restart >= 0)
1015 mvm->fw_restart++;
1016
1017 /* take the return value to make compiler happy - it will fail anyway */
1018 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
1019
1020 mutex_unlock(&mvm->mutex);
1021
1022 return count;
1023}
1024
1025static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
1026 size_t count, loff_t *ppos)
1027{
1028 int ret;
1029
1030 if (!iwl_mvm_firmware_running(mvm))
1031 return -EIO;
1032
1033 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
1034 if (ret)
1035 return ret;
1036
1037 iwl_force_nmi(mvm->trans);
1038
1039 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
1040
1041 return count;
1042}
1043
1044static ssize_t
1045iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
1046 char __user *user_buf,
1047 size_t count, loff_t *ppos)
1048{
1049 struct iwl_mvm *mvm = file->private_data;
1050 int pos = 0;
1051 char buf[32];
1052 const size_t bufsz = sizeof(buf);
1053
1054 /* print which antennas were set for the scan command by the user */
1055 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
1056 if (mvm->scan_rx_ant & ANT_A)
1057 pos += scnprintf(buf + pos, bufsz - pos, "A");
1058 if (mvm->scan_rx_ant & ANT_B)
1059 pos += scnprintf(buf + pos, bufsz - pos, "B");
1060 if (mvm->scan_rx_ant & ANT_C)
1061 pos += scnprintf(buf + pos, bufsz - pos, "C");
1062 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
1063
1064 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1065}
1066
1067static ssize_t
1068iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
1069 size_t count, loff_t *ppos)
1070{
1071 u8 scan_rx_ant;
1072
1073 if (!iwl_mvm_firmware_running(mvm))
1074 return -EIO;
1075
1076 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
1077 return -EINVAL;
1078 if (scan_rx_ant > ANT_ABC)
1079 return -EINVAL;
1080 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
1081 return -EINVAL;
1082
1083 if (mvm->scan_rx_ant != scan_rx_ant) {
1084 mvm->scan_rx_ant = scan_rx_ant;
1085 if (fw_has_capa(&mvm->fw->ucode_capa,
1086 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1087 iwl_mvm_config_scan(mvm);
1088 }
1089
1090 return count;
1091}
1092
1093static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
1094 char *buf, size_t count,
1095 loff_t *ppos)
1096{
1097 struct iwl_rss_config_cmd cmd = {
1098 .flags = cpu_to_le32(IWL_RSS_ENABLE),
1099 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
1100 IWL_RSS_HASH_TYPE_IPV4_UDP |
1101 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
1102 IWL_RSS_HASH_TYPE_IPV6_TCP |
1103 IWL_RSS_HASH_TYPE_IPV6_UDP |
1104 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
1105 };
1106 int ret, i, num_repeats, nbytes = count / 2;
1107
1108 ret = hex2bin(cmd.indirection_table, buf, nbytes);
1109 if (ret)
1110 return ret;
1111
1112 /*
1113 * The input is the redirection table, partial or full.
1114 * Repeat the pattern if needed.
1115 * For example, input of 01020F will be repeated 42 times,
1116 * indirecting RSS hash results to queues 1, 2, 15 (skipping
1117 * queues 3 - 14).
1118 */
1119 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
1120 for (i = 1; i < num_repeats; i++)
1121 memcpy(&cmd.indirection_table[i * nbytes],
1122 cmd.indirection_table, nbytes);
1123 /* handle cut in the middle pattern for the last places */
1124 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
1125 ARRAY_SIZE(cmd.indirection_table) % nbytes);
1126
1127 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
1128
1129 mutex_lock(&mvm->mutex);
1130 if (iwl_mvm_firmware_running(mvm))
1131 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0,
1132 sizeof(cmd), &cmd);
1133 else
1134 ret = 0;
1135 mutex_unlock(&mvm->mutex);
1136
1137 return ret ?: count;
1138}
1139
1140static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
1141 char *buf, size_t count,
1142 loff_t *ppos)
1143{
1144 struct iwl_rx_cmd_buffer rxb = {
1145 ._rx_page_order = 0,
1146 .truesize = 0, /* not used */
1147 ._offset = 0,
1148 };
1149 struct iwl_rx_packet *pkt;
1150 struct iwl_rx_mpdu_desc *desc;
1151 int bin_len = count / 2;
1152 int ret = -EINVAL;
1153
1154 if (!iwl_mvm_firmware_running(mvm))
1155 return -EIO;
1156
1157 /* supporting only 9000 descriptor */
1158 if (!mvm->trans->cfg->mq_rx_supported)
1159 return -ENOTSUPP;
1160
1161 rxb._page = alloc_pages(GFP_ATOMIC, 0);
1162 if (!rxb._page)
1163 return -ENOMEM;
1164 pkt = rxb_addr(&rxb);
1165
1166 ret = hex2bin(page_address(rxb._page), buf, bin_len);
1167 if (ret)
1168 goto out;
1169
1170 /* avoid invalid memory access */
1171 if (bin_len < sizeof(*pkt) + sizeof(*desc))
1172 goto out;
1173
1174 /* check this is RX packet */
1175 if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
1176 WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
1177 goto out;
1178
1179 /* check the length in metadata matches actual received length */
1180 desc = (void *)pkt->data;
1181 if (le16_to_cpu(desc->mpdu_len) !=
1182 (bin_len - sizeof(*desc) - sizeof(*pkt)))
1183 goto out;
1184
1185 local_bh_disable();
1186 iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
1187 local_bh_enable();
1188 ret = 0;
1189
1190out:
1191 iwl_free_rxb(&rxb);
1192
1193 return ret ?: count;
1194}
1195
1196static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
1197 char __user *user_buf,
1198 size_t count, loff_t *ppos)
1199{
1200 struct iwl_mvm *mvm = file->private_data;
1201 int conf;
1202 char buf[8];
1203 const size_t bufsz = sizeof(buf);
1204 int pos = 0;
1205
1206 mutex_lock(&mvm->mutex);
1207 conf = mvm->fwrt.dump.conf;
1208 mutex_unlock(&mvm->mutex);
1209
1210 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
1211
1212 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1213}
1214
1215/*
1216 * Enable / Disable continuous recording.
1217 * Cause the FW to start continuous recording, by sending the relevant hcmd.
1218 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
1219 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
1220 */
1221static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
1222 char *buf, size_t count,
1223 loff_t *ppos)
1224{
1225 struct iwl_trans *trans = mvm->trans;
1226 const struct iwl_fw_dbg_dest_tlv_v1 *dest = trans->dbg_dest_tlv;
1227 struct iwl_continuous_record_cmd cont_rec = {};
1228 int ret, rec_mode;
1229
1230 if (!iwl_mvm_firmware_running(mvm))
1231 return -EIO;
1232
1233 if (!dest)
1234 return -EOPNOTSUPP;
1235
1236 if (dest->monitor_mode != SMEM_MODE ||
1237 trans->cfg->device_family < IWL_DEVICE_FAMILY_8000)
1238 return -EOPNOTSUPP;
1239
1240 ret = kstrtoint(buf, 0, &rec_mode);
1241 if (ret)
1242 return ret;
1243
1244 cont_rec.record_mode.enable_recording = rec_mode ?
1245 cpu_to_le16(ENABLE_CONT_RECORDING) :
1246 cpu_to_le16(DISABLE_CONT_RECORDING);
1247
1248 mutex_lock(&mvm->mutex);
1249 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1250 sizeof(cont_rec), &cont_rec);
1251 mutex_unlock(&mvm->mutex);
1252
1253 return ret ?: count;
1254}
1255
1256static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1257 char *buf, size_t count,
1258 loff_t *ppos)
1259{
1260 unsigned int conf_id;
1261 int ret;
1262
1263 if (!iwl_mvm_firmware_running(mvm))
1264 return -EIO;
1265
1266 ret = kstrtouint(buf, 0, &conf_id);
1267 if (ret)
1268 return ret;
1269
1270 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1271 return -EINVAL;
1272
1273 mutex_lock(&mvm->mutex);
1274 ret = iwl_fw_start_dbg_conf(&mvm->fwrt, conf_id);
1275 mutex_unlock(&mvm->mutex);
1276
1277 return ret ?: count;
1278}
1279
1280static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1281 char *buf, size_t count,
1282 loff_t *ppos)
1283{
1284 int ret;
1285
1286 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1287 if (ret)
1288 return ret;
1289 if (count == 0)
1290 return 0;
1291
1292 iwl_fw_dbg_collect(&mvm->fwrt, FW_DBG_TRIGGER_USER, buf,
1293 (count - 1), NULL);
1294
1295 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1296
1297 return count;
1298}
1299
1300static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1301 char *buf, size_t count,
1302 loff_t *ppos)
1303{
1304 unsigned int max_amsdu_len;
1305 int ret;
1306
1307 ret = kstrtouint(buf, 0, &max_amsdu_len);
1308 if (ret)
1309 return ret;
1310
1311 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1312 return -EINVAL;
1313 mvm->max_amsdu_len = max_amsdu_len;
1314
1315 return count;
1316}
1317
1318#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1319#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1320static ssize_t iwl_dbgfs_bcast_filters_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 struct iwl_bcast_filter_cmd cmd;
1326 const struct iwl_fw_bcast_filter *filter;
1327 char *buf;
1328 int bufsz = 1024;
1329 int i, j, pos = 0;
1330 ssize_t ret;
1331
1332 buf = kzalloc(bufsz, GFP_KERNEL);
1333 if (!buf)
1334 return -ENOMEM;
1335
1336 mutex_lock(&mvm->mutex);
1337 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1338 ADD_TEXT("None\n");
1339 mutex_unlock(&mvm->mutex);
1340 goto out;
1341 }
1342 mutex_unlock(&mvm->mutex);
1343
1344 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1345 filter = &cmd.filters[i];
1346
1347 ADD_TEXT("Filter [%d]:\n", i);
1348 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1349 ADD_TEXT("\tFrame Type: %s\n",
1350 filter->frame_type ? "IPv4" : "Generic");
1351
1352 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1353 const struct iwl_fw_bcast_filter_attr *attr;
1354
1355 attr = &filter->attrs[j];
1356 if (!attr->mask)
1357 break;
1358
1359 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1360 j, attr->offset,
1361 attr->offset_type ? "IP End" :
1362 "Payload Start",
1363 be32_to_cpu(attr->mask),
1364 be32_to_cpu(attr->val),
1365 le16_to_cpu(attr->reserved1));
1366 }
1367 }
1368out:
1369 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1370 kfree(buf);
1371 return ret;
1372}
1373
1374static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1375 size_t count, loff_t *ppos)
1376{
1377 int pos, next_pos;
1378 struct iwl_fw_bcast_filter filter = {};
1379 struct iwl_bcast_filter_cmd cmd;
1380 u32 filter_id, attr_id, mask, value;
1381 int err = 0;
1382
1383 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1384 &filter.frame_type, &pos) != 3)
1385 return -EINVAL;
1386
1387 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1388 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1389 return -EINVAL;
1390
1391 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1392 attr_id++) {
1393 struct iwl_fw_bcast_filter_attr *attr =
1394 &filter.attrs[attr_id];
1395
1396 if (pos >= count)
1397 break;
1398
1399 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1400 &attr->offset, &attr->offset_type,
1401 &mask, &value, &next_pos) != 4)
1402 return -EINVAL;
1403
1404 attr->mask = cpu_to_be32(mask);
1405 attr->val = cpu_to_be32(value);
1406 if (mask)
1407 filter.num_attrs++;
1408
1409 pos += next_pos;
1410 }
1411
1412 mutex_lock(&mvm->mutex);
1413 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1414 &filter, sizeof(filter));
1415
1416 /* send updated bcast filtering configuration */
1417 if (iwl_mvm_firmware_running(mvm) &&
1418 mvm->dbgfs_bcast_filtering.override &&
1419 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1420 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1421 sizeof(cmd), &cmd);
1422 mutex_unlock(&mvm->mutex);
1423
1424 return err ?: count;
1425}
1426
1427static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1428 char __user *user_buf,
1429 size_t count, loff_t *ppos)
1430{
1431 struct iwl_mvm *mvm = file->private_data;
1432 struct iwl_bcast_filter_cmd cmd;
1433 char *buf;
1434 int bufsz = 1024;
1435 int i, pos = 0;
1436 ssize_t ret;
1437
1438 buf = kzalloc(bufsz, GFP_KERNEL);
1439 if (!buf)
1440 return -ENOMEM;
1441
1442 mutex_lock(&mvm->mutex);
1443 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1444 ADD_TEXT("None\n");
1445 mutex_unlock(&mvm->mutex);
1446 goto out;
1447 }
1448 mutex_unlock(&mvm->mutex);
1449
1450 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1451 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1452
1453 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1454 i, mac->default_discard, mac->attached_filters);
1455 }
1456out:
1457 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1458 kfree(buf);
1459 return ret;
1460}
1461
1462static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1463 char *buf, size_t count,
1464 loff_t *ppos)
1465{
1466 struct iwl_bcast_filter_cmd cmd;
1467 struct iwl_fw_bcast_mac mac = {};
1468 u32 mac_id, attached_filters;
1469 int err = 0;
1470
1471 if (!mvm->bcast_filters)
1472 return -ENOENT;
1473
1474 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1475 &attached_filters) != 3)
1476 return -EINVAL;
1477
1478 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1479 mac.default_discard > 1 ||
1480 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1481 return -EINVAL;
1482
1483 mac.attached_filters = cpu_to_le16(attached_filters);
1484
1485 mutex_lock(&mvm->mutex);
1486 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1487 &mac, sizeof(mac));
1488
1489 /* send updated bcast filtering configuration */
1490 if (iwl_mvm_firmware_running(mvm) &&
1491 mvm->dbgfs_bcast_filtering.override &&
1492 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1493 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1494 sizeof(cmd), &cmd);
1495 mutex_unlock(&mvm->mutex);
1496
1497 return err ?: count;
1498}
1499#endif
1500
1501#ifdef CONFIG_PM_SLEEP
1502static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
1503 size_t count, loff_t *ppos)
1504{
1505 int store;
1506
1507 if (sscanf(buf, "%d", &store) != 1)
1508 return -EINVAL;
1509
1510 mvm->store_d3_resume_sram = store;
1511
1512 return count;
1513}
1514
1515static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1516 size_t count, loff_t *ppos)
1517{
1518 struct iwl_mvm *mvm = file->private_data;
1519 const struct fw_img *img;
1520 int ofs, len, pos = 0;
1521 size_t bufsz, ret;
1522 char *buf;
1523 u8 *ptr = mvm->d3_resume_sram;
1524
1525 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1526 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1527
1528 bufsz = len * 4 + 256;
1529 buf = kzalloc(bufsz, GFP_KERNEL);
1530 if (!buf)
1531 return -ENOMEM;
1532
1533 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1534 mvm->store_d3_resume_sram ? "en" : "dis");
1535
1536 if (ptr) {
1537 for (ofs = 0; ofs < len; ofs += 16) {
1538 pos += scnprintf(buf + pos, bufsz - pos,
1539 "0x%.4x %16ph\n", ofs, ptr + ofs);
1540 }
1541 } else {
1542 pos += scnprintf(buf + pos, bufsz - pos,
1543 "(no data captured)\n");
1544 }
1545
1546 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1547
1548 kfree(buf);
1549
1550 return ret;
1551}
1552#endif
1553
1554#define PRINT_MVM_REF(ref) do { \
1555 if (mvm->refs[ref]) \
1556 pos += scnprintf(buf + pos, bufsz - pos, \
1557 "\t(0x%lx): %d %s\n", \
1558 BIT(ref), mvm->refs[ref], #ref); \
1559} while (0)
1560
1561static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1562 char __user *user_buf,
1563 size_t count, loff_t *ppos)
1564{
1565 struct iwl_mvm *mvm = file->private_data;
1566 int i, pos = 0;
1567 char buf[256];
1568 const size_t bufsz = sizeof(buf);
1569 u32 refs = 0;
1570
1571 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1572 if (mvm->refs[i])
1573 refs |= BIT(i);
1574
1575 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1576 refs);
1577
1578 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1579 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1580 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1581 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
1582 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1583 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
1584 PRINT_MVM_REF(IWL_MVM_REF_USER);
1585 PRINT_MVM_REF(IWL_MVM_REF_TX);
1586 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1587 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1588 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1589 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1590 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1591 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1592 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1593 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1594 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1595 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1596 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
1597 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
1598 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
1599 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
1600 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
1601 PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
1602 PRINT_MVM_REF(IWL_MVM_REF_RX);
1603
1604 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1605}
1606
1607static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1608 size_t count, loff_t *ppos)
1609{
1610 unsigned long value;
1611 int ret;
1612 bool taken;
1613
1614 ret = kstrtoul(buf, 10, &value);
1615 if (ret < 0)
1616 return ret;
1617
1618 mutex_lock(&mvm->mutex);
1619
1620 taken = mvm->refs[IWL_MVM_REF_USER];
1621 if (value == 1 && !taken)
1622 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1623 else if (value == 0 && taken)
1624 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1625 else
1626 ret = -EINVAL;
1627
1628 mutex_unlock(&mvm->mutex);
1629
1630 if (ret < 0)
1631 return ret;
1632 return count;
1633}
1634
1635#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1636 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1637#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1638 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1639#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1640 if (!debugfs_create_file(alias, mode, parent, mvm, \
1641 &iwl_dbgfs_##name##_ops)) \
1642 goto err; \
1643 } while (0)
1644#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1645 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1646
1647#define MVM_DEBUGFS_WRITE_STA_FILE_OPS(name, bufsz) \
1648 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_sta)
1649#define MVM_DEBUGFS_READ_WRITE_STA_FILE_OPS(name, bufsz) \
1650 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_sta)
1651
1652#define MVM_DEBUGFS_ADD_STA_FILE_ALIAS(alias, name, parent, mode) do { \
1653 if (!debugfs_create_file(alias, mode, parent, sta, \
1654 &iwl_dbgfs_##name##_ops)) \
1655 goto err; \
1656 } while (0)
1657#define MVM_DEBUGFS_ADD_STA_FILE(name, parent, mode) \
1658 MVM_DEBUGFS_ADD_STA_FILE_ALIAS(#name, name, parent, mode)
1659
1660static ssize_t
1661iwl_dbgfs_prph_reg_read(struct file *file,
1662 char __user *user_buf,
1663 size_t count, loff_t *ppos)
1664{
1665 struct iwl_mvm *mvm = file->private_data;
1666 int pos = 0;
1667 char buf[32];
1668 const size_t bufsz = sizeof(buf);
1669 int ret;
1670
1671 if (!mvm->dbgfs_prph_reg_addr)
1672 return -EINVAL;
1673
1674 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1675 if (ret)
1676 return ret;
1677
1678 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1679 mvm->dbgfs_prph_reg_addr,
1680 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1681
1682 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1683
1684 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1685}
1686
1687static ssize_t
1688iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1689 size_t count, loff_t *ppos)
1690{
1691 u8 args;
1692 u32 value;
1693 int ret;
1694
1695 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1696 /* if we only want to set the reg address - nothing more to do */
1697 if (args == 1)
1698 goto out;
1699
1700 /* otherwise, make sure we have both address and value */
1701 if (args != 2)
1702 return -EINVAL;
1703
1704 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1705 if (ret)
1706 return ret;
1707
1708 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1709
1710 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1711out:
1712 return count;
1713}
1714
1715static ssize_t
1716iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1717 size_t count, loff_t *ppos)
1718{
1719 int ret;
1720
1721 if (!iwl_mvm_firmware_running(mvm))
1722 return -EIO;
1723
1724 mutex_lock(&mvm->mutex);
1725 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1726 mutex_unlock(&mvm->mutex);
1727
1728 return ret ?: count;
1729}
1730
1731MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1732
1733/* Device wide debugfs entries */
1734MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1735MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
1736MVM_DEBUGFS_WRITE_FILE_OPS(force_ctkill, 8);
1737MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1738MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1739MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
1740MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1741MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
1742MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
1743MVM_DEBUGFS_READ_FILE_OPS(stations);
1744MVM_DEBUGFS_READ_FILE_OPS(rs_data);
1745MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1746MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1747MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1748MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1749MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1750MVM_DEBUGFS_READ_FILE_OPS(fw_ver);
1751MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1752MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1753MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1754MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1755MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1756MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1757MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
1758MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
1759MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
1760MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
1761MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1762 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
1763MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
1764
1765#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1766MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1767MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1768#endif
1769
1770#ifdef CONFIG_PM_SLEEP
1771MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1772#endif
1773#ifdef CONFIG_ACPI
1774MVM_DEBUGFS_READ_FILE_OPS(sar_geo_profile);
1775#endif
1776
1777static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1778 size_t count, loff_t *ppos)
1779{
1780 struct iwl_mvm *mvm = file->private_data;
1781 struct iwl_dbg_mem_access_cmd cmd = {};
1782 struct iwl_dbg_mem_access_rsp *rsp;
1783 struct iwl_host_cmd hcmd = {
1784 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1785 .data = { &cmd, },
1786 .len = { sizeof(cmd) },
1787 };
1788 size_t delta;
1789 ssize_t ret, len;
1790
1791 if (!iwl_mvm_firmware_running(mvm))
1792 return -EIO;
1793
1794 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1795 DEBUG_GROUP, 0);
1796 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1797
1798 /* Take care of alignment of both the position and the length */
1799 delta = *ppos & 0x3;
1800 cmd.addr = cpu_to_le32(*ppos - delta);
1801 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1802 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1803
1804 mutex_lock(&mvm->mutex);
1805 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1806 mutex_unlock(&mvm->mutex);
1807
1808 if (ret < 0)
1809 return ret;
1810
1811 rsp = (void *)hcmd.resp_pkt->data;
1812 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1813 ret = -ENXIO;
1814 goto out;
1815 }
1816
1817 len = min((size_t)le32_to_cpu(rsp->len) << 2,
1818 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1819 len = min(len - delta, count);
1820 if (len < 0) {
1821 ret = -EFAULT;
1822 goto out;
1823 }
1824
1825 ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1826 *ppos += ret;
1827
1828out:
1829 iwl_free_resp(&hcmd);
1830 return ret;
1831}
1832
1833static ssize_t iwl_dbgfs_mem_write(struct file *file,
1834 const char __user *user_buf, size_t count,
1835 loff_t *ppos)
1836{
1837 struct iwl_mvm *mvm = file->private_data;
1838 struct iwl_dbg_mem_access_cmd *cmd;
1839 struct iwl_dbg_mem_access_rsp *rsp;
1840 struct iwl_host_cmd hcmd = {};
1841 size_t cmd_size;
1842 size_t data_size;
1843 u32 op, len;
1844 ssize_t ret;
1845
1846 if (!iwl_mvm_firmware_running(mvm))
1847 return -EIO;
1848
1849 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1850 DEBUG_GROUP, 0);
1851
1852 if (*ppos & 0x3 || count < 4) {
1853 op = DEBUG_MEM_OP_WRITE_BYTES;
1854 len = min(count, (size_t)(4 - (*ppos & 0x3)));
1855 data_size = len;
1856 } else {
1857 op = DEBUG_MEM_OP_WRITE;
1858 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1859 data_size = len << 2;
1860 }
1861
1862 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1863 cmd = kzalloc(cmd_size, GFP_KERNEL);
1864 if (!cmd)
1865 return -ENOMEM;
1866
1867 cmd->op = cpu_to_le32(op);
1868 cmd->len = cpu_to_le32(len);
1869 cmd->addr = cpu_to_le32(*ppos);
1870 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1871 kfree(cmd);
1872 return -EFAULT;
1873 }
1874
1875 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1876 hcmd.data[0] = (void *)cmd;
1877 hcmd.len[0] = cmd_size;
1878
1879 mutex_lock(&mvm->mutex);
1880 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1881 mutex_unlock(&mvm->mutex);
1882
1883 kfree(cmd);
1884
1885 if (ret < 0)
1886 return ret;
1887
1888 rsp = (void *)hcmd.resp_pkt->data;
1889 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1890 ret = -ENXIO;
1891 goto out;
1892 }
1893
1894 ret = data_size;
1895 *ppos += ret;
1896
1897out:
1898 iwl_free_resp(&hcmd);
1899 return ret;
1900}
1901
1902static const struct file_operations iwl_dbgfs_mem_ops = {
1903 .read = iwl_dbgfs_mem_read,
1904 .write = iwl_dbgfs_mem_write,
1905 .open = simple_open,
1906 .llseek = default_llseek,
1907};
1908
1909void iwl_mvm_sta_add_debugfs(struct ieee80211_hw *hw,
1910 struct ieee80211_vif *vif,
1911 struct ieee80211_sta *sta,
1912 struct dentry *dir)
1913{
1914 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1915
1916 if (iwl_mvm_has_tlc_offload(mvm))
1917 MVM_DEBUGFS_ADD_STA_FILE(rs_data, dir, 0400);
1918
1919 return;
1920err:
1921 IWL_ERR(mvm, "Can't create the mvm station debugfs entry\n");
1922}
1923
1924int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1925{
1926 struct dentry *bcast_dir __maybe_unused;
1927 char buf[100];
1928
1929 spin_lock_init(&mvm->drv_stats_lock);
1930
1931 mvm->debugfs_dir = dbgfs_dir;
1932
1933 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, 0200);
1934 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, 0200);
1935 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, 0600);
1936 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir, 0600);
1937 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, 0400);
1938 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, 0400);
1939 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, 0200);
1940 MVM_DEBUGFS_ADD_FILE(force_ctkill, dbgfs_dir, 0200);
1941 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, 0400);
1942 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, 0400);
1943 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, 0400);
1944 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir, 0600);
1945 MVM_DEBUGFS_ADD_FILE(fw_ver, mvm->debugfs_dir, 0400);
1946 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, 0400);
1947 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, 0400);
1948 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, 0200);
1949 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, 0200);
1950 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, 0200);
1951 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, 0200);
1952 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir, 0600);
1953 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, 0600);
1954 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, 0600);
1955 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, 0600);
1956 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, 0200);
1957 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, 0200);
1958 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, 0200);
1959 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, 0200);
1960 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, 0200);
1961 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, 0200);
1962#ifdef CONFIG_ACPI
1963 MVM_DEBUGFS_ADD_FILE(sar_geo_profile, dbgfs_dir, 0400);
1964#endif
1965
1966 if (!debugfs_create_bool("enable_scan_iteration_notif",
1967 0600,
1968 mvm->debugfs_dir,
1969 &mvm->scan_iter_notif_enabled))
1970 goto err;
1971 if (!debugfs_create_bool("drop_bcn_ap_mode", 0600,
1972 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1973 goto err;
1974
1975#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1976 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1977 bcast_dir = debugfs_create_dir("bcast_filtering",
1978 mvm->debugfs_dir);
1979 if (!bcast_dir)
1980 goto err;
1981
1982 if (!debugfs_create_bool("override", 0600,
1983 bcast_dir,
1984 &mvm->dbgfs_bcast_filtering.override))
1985 goto err;
1986
1987 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1988 bcast_dir, 0600);
1989 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1990 bcast_dir, 0600);
1991 }
1992#endif
1993
1994#ifdef CONFIG_PM_SLEEP
1995 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, 0600);
1996 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, 0400);
1997 if (!debugfs_create_bool("d3_wake_sysassert", 0600,
1998 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1999 goto err;
2000 if (!debugfs_create_u32("last_netdetect_scans", 0400,
2001 mvm->debugfs_dir, &mvm->last_netdetect_scans))
2002 goto err;
2003#endif
2004
2005 if (!debugfs_create_u8("ps_disabled", 0400,
2006 mvm->debugfs_dir, &mvm->ps_disabled))
2007 goto err;
2008 if (!debugfs_create_blob("nvm_hw", 0400,
2009 mvm->debugfs_dir, &mvm->nvm_hw_blob))
2010 goto err;
2011 if (!debugfs_create_blob("nvm_sw", 0400,
2012 mvm->debugfs_dir, &mvm->nvm_sw_blob))
2013 goto err;
2014 if (!debugfs_create_blob("nvm_calib", 0400,
2015 mvm->debugfs_dir, &mvm->nvm_calib_blob))
2016 goto err;
2017 if (!debugfs_create_blob("nvm_prod", 0400,
2018 mvm->debugfs_dir, &mvm->nvm_prod_blob))
2019 goto err;
2020 if (!debugfs_create_blob("nvm_phy_sku", 0400,
2021 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
2022 goto err;
2023
2024 debugfs_create_file("mem", 0600, dbgfs_dir, mvm, &iwl_dbgfs_mem_ops);
2025
2026 /*
2027 * Create a symlink with mac80211. It will be removed when mac80211
2028 * exists (before the opmode exists which removes the target.)
2029 */
2030 snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
2031 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
2032 goto err;
2033
2034 return 0;
2035err:
2036 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
2037 return -ENOMEM;
2038}
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 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
28 *
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 *
43 * * Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * * Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in
47 * the documentation and/or other materials provided with the
48 * distribution.
49 * * Neither the name Intel Corporation nor the names of its
50 * contributors may be used to endorse or promote products derived
51 * from this software without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *
65 *****************************************************************************/
66#include <linux/vmalloc.h>
67#include <linux/ieee80211.h>
68#include <linux/netdevice.h>
69
70#include "mvm.h"
71#include "fw-dbg.h"
72#include "sta.h"
73#include "iwl-io.h"
74#include "debugfs.h"
75#include "iwl-fw-error-dump.h"
76
77static ssize_t iwl_dbgfs_ctdp_budget_read(struct file *file,
78 char __user *user_buf,
79 size_t count, loff_t *ppos)
80{
81 struct iwl_mvm *mvm = file->private_data;
82 char buf[16];
83 int pos, budget;
84
85 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
86 return -EIO;
87
88 mutex_lock(&mvm->mutex);
89 budget = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_REPORT, 0);
90 mutex_unlock(&mvm->mutex);
91
92 if (budget < 0)
93 return budget;
94
95 pos = scnprintf(buf, sizeof(buf), "%d\n", budget);
96
97 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
98}
99
100static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mvm *mvm, char *buf,
101 size_t count, loff_t *ppos)
102{
103 int ret;
104
105 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
106 return -EIO;
107
108 mutex_lock(&mvm->mutex);
109 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_STOP, 0);
110 mutex_unlock(&mvm->mutex);
111
112 return ret ?: count;
113}
114
115static ssize_t iwl_dbgfs_tx_flush_write(struct iwl_mvm *mvm, char *buf,
116 size_t count, loff_t *ppos)
117{
118 int ret;
119 u32 scd_q_msk;
120
121 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
122 return -EIO;
123
124 if (sscanf(buf, "%x", &scd_q_msk) != 1)
125 return -EINVAL;
126
127 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
128
129 mutex_lock(&mvm->mutex);
130 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, 0) ? : count;
131 mutex_unlock(&mvm->mutex);
132
133 return ret;
134}
135
136static ssize_t iwl_dbgfs_sta_drain_write(struct iwl_mvm *mvm, char *buf,
137 size_t count, loff_t *ppos)
138{
139 struct iwl_mvm_sta *mvmsta;
140 int sta_id, drain, ret;
141
142 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
143 return -EIO;
144
145 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
146 return -EINVAL;
147 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
148 return -EINVAL;
149 if (drain < 0 || drain > 1)
150 return -EINVAL;
151
152 mutex_lock(&mvm->mutex);
153
154 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
155
156 if (!mvmsta)
157 ret = -ENOENT;
158 else
159 ret = iwl_mvm_drain_sta(mvm, mvmsta, drain) ? : count;
160
161 mutex_unlock(&mvm->mutex);
162
163 return ret;
164}
165
166static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
167 size_t count, loff_t *ppos)
168{
169 struct iwl_mvm *mvm = file->private_data;
170 const struct fw_img *img;
171 unsigned int ofs, len;
172 size_t ret;
173 u8 *ptr;
174
175 if (!mvm->ucode_loaded)
176 return -EINVAL;
177
178 /* default is to dump the entire data segment */
179 img = &mvm->fw->img[mvm->cur_ucode];
180 ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
181 len = img->sec[IWL_UCODE_SECTION_DATA].len;
182
183 if (mvm->dbgfs_sram_len) {
184 ofs = mvm->dbgfs_sram_offset;
185 len = mvm->dbgfs_sram_len;
186 }
187
188 ptr = kzalloc(len, GFP_KERNEL);
189 if (!ptr)
190 return -ENOMEM;
191
192 iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len);
193
194 ret = simple_read_from_buffer(user_buf, count, ppos, ptr, len);
195
196 kfree(ptr);
197
198 return ret;
199}
200
201static ssize_t iwl_dbgfs_sram_write(struct iwl_mvm *mvm, char *buf,
202 size_t count, loff_t *ppos)
203{
204 const struct fw_img *img;
205 u32 offset, len;
206 u32 img_offset, img_len;
207
208 if (!mvm->ucode_loaded)
209 return -EINVAL;
210
211 img = &mvm->fw->img[mvm->cur_ucode];
212 img_offset = img->sec[IWL_UCODE_SECTION_DATA].offset;
213 img_len = img->sec[IWL_UCODE_SECTION_DATA].len;
214
215 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
216 if ((offset & 0x3) || (len & 0x3))
217 return -EINVAL;
218
219 if (offset + len > img_offset + img_len)
220 return -EINVAL;
221
222 mvm->dbgfs_sram_offset = offset;
223 mvm->dbgfs_sram_len = len;
224 } else {
225 mvm->dbgfs_sram_offset = 0;
226 mvm->dbgfs_sram_len = 0;
227 }
228
229 return count;
230}
231
232static ssize_t iwl_dbgfs_set_nic_temperature_read(struct file *file,
233 char __user *user_buf,
234 size_t count, loff_t *ppos)
235{
236 struct iwl_mvm *mvm = file->private_data;
237 char buf[16];
238 int pos;
239
240 if (!mvm->temperature_test)
241 pos = scnprintf(buf , sizeof(buf), "disabled\n");
242 else
243 pos = scnprintf(buf , sizeof(buf), "%d\n", mvm->temperature);
244
245 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
246}
247
248/*
249 * Set NIC Temperature
250 * Cause the driver to ignore the actual NIC temperature reported by the FW
251 * Enable: any value between IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -
252 * IWL_MVM_DEBUG_SET_TEMPERATURE_MAX
253 * Disable: IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE
254 */
255static ssize_t iwl_dbgfs_set_nic_temperature_write(struct iwl_mvm *mvm,
256 char *buf, size_t count,
257 loff_t *ppos)
258{
259 int temperature;
260
261 if (!mvm->ucode_loaded && !mvm->temperature_test)
262 return -EIO;
263
264 if (kstrtoint(buf, 10, &temperature))
265 return -EINVAL;
266 /* not a legal temperature */
267 if ((temperature > IWL_MVM_DEBUG_SET_TEMPERATURE_MAX &&
268 temperature != IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) ||
269 temperature < IWL_MVM_DEBUG_SET_TEMPERATURE_MIN)
270 return -EINVAL;
271
272 mutex_lock(&mvm->mutex);
273 if (temperature == IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE) {
274 if (!mvm->temperature_test)
275 goto out;
276
277 mvm->temperature_test = false;
278 /* Since we can't read the temp while awake, just set
279 * it to zero until we get the next RX stats from the
280 * firmware.
281 */
282 mvm->temperature = 0;
283 } else {
284 mvm->temperature_test = true;
285 mvm->temperature = temperature;
286 }
287 IWL_DEBUG_TEMP(mvm, "%sabling debug set temperature (temp = %d)\n",
288 mvm->temperature_test ? "En" : "Dis" ,
289 mvm->temperature);
290 /* handle the temperature change */
291 iwl_mvm_tt_handler(mvm);
292
293out:
294 mutex_unlock(&mvm->mutex);
295
296 return count;
297}
298
299static ssize_t iwl_dbgfs_nic_temp_read(struct file *file,
300 char __user *user_buf,
301 size_t count, loff_t *ppos)
302{
303 struct iwl_mvm *mvm = file->private_data;
304 char buf[16];
305 int pos, ret;
306 s32 temp;
307
308 if (!mvm->ucode_loaded)
309 return -EIO;
310
311 mutex_lock(&mvm->mutex);
312 ret = iwl_mvm_get_temp(mvm, &temp);
313 mutex_unlock(&mvm->mutex);
314
315 if (ret)
316 return -EIO;
317
318 pos = scnprintf(buf , sizeof(buf), "%d\n", temp);
319
320 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
321}
322
323static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
324 size_t count, loff_t *ppos)
325{
326 struct iwl_mvm *mvm = file->private_data;
327 struct ieee80211_sta *sta;
328 char buf[400];
329 int i, pos = 0, bufsz = sizeof(buf);
330
331 mutex_lock(&mvm->mutex);
332
333 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
334 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
335 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
336 lockdep_is_held(&mvm->mutex));
337 if (!sta)
338 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
339 else if (IS_ERR(sta))
340 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
341 PTR_ERR(sta));
342 else
343 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
344 sta->addr);
345 }
346
347 mutex_unlock(&mvm->mutex);
348
349 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
350}
351
352static ssize_t iwl_dbgfs_disable_power_off_read(struct file *file,
353 char __user *user_buf,
354 size_t count, loff_t *ppos)
355{
356 struct iwl_mvm *mvm = file->private_data;
357 char buf[64];
358 int bufsz = sizeof(buf);
359 int pos = 0;
360
361 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d0=%d\n",
362 mvm->disable_power_off);
363 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off_d3=%d\n",
364 mvm->disable_power_off_d3);
365
366 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
367}
368
369static ssize_t iwl_dbgfs_disable_power_off_write(struct iwl_mvm *mvm, char *buf,
370 size_t count, loff_t *ppos)
371{
372 int ret, val;
373
374 if (!mvm->ucode_loaded)
375 return -EIO;
376
377 if (!strncmp("disable_power_off_d0=", buf, 21)) {
378 if (sscanf(buf + 21, "%d", &val) != 1)
379 return -EINVAL;
380 mvm->disable_power_off = val;
381 } else if (!strncmp("disable_power_off_d3=", buf, 21)) {
382 if (sscanf(buf + 21, "%d", &val) != 1)
383 return -EINVAL;
384 mvm->disable_power_off_d3 = val;
385 } else {
386 return -EINVAL;
387 }
388
389 mutex_lock(&mvm->mutex);
390 ret = iwl_mvm_power_update_device(mvm);
391 mutex_unlock(&mvm->mutex);
392
393 return ret ?: count;
394}
395
396#define BT_MBOX_MSG(_notif, _num, _field) \
397 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
398 >> BT_MBOX##_num##_##_field##_POS)
399
400
401#define BT_MBOX_PRINT(_num, _field, _end) \
402 pos += scnprintf(buf + pos, bufsz - pos, \
403 "\t%s: %d%s", \
404 #_field, \
405 BT_MBOX_MSG(notif, _num, _field), \
406 true ? "\n" : ", ");
407
408static
409int iwl_mvm_coex_dump_mbox(struct iwl_bt_coex_profile_notif *notif, char *buf,
410 int pos, int bufsz)
411{
412 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
413
414 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
415 BT_MBOX_PRINT(0, LE_PROF1, false);
416 BT_MBOX_PRINT(0, LE_PROF2, false);
417 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
418 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
419 BT_MBOX_PRINT(0, INBAND_S, false);
420 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
421 BT_MBOX_PRINT(0, LE_SCAN, false);
422 BT_MBOX_PRINT(0, LE_ADV, false);
423 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
424 BT_MBOX_PRINT(0, OPEN_CON_1, true);
425
426 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
427
428 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
429 BT_MBOX_PRINT(1, IP_SR, false);
430 BT_MBOX_PRINT(1, LE_MSTR, false);
431 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
432 BT_MBOX_PRINT(1, MSG_TYPE, false);
433 BT_MBOX_PRINT(1, SSN, true);
434
435 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
436
437 BT_MBOX_PRINT(2, SNIFF_ACT, false);
438 BT_MBOX_PRINT(2, PAG, false);
439 BT_MBOX_PRINT(2, INQUIRY, false);
440 BT_MBOX_PRINT(2, CONN, false);
441 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
442 BT_MBOX_PRINT(2, DISC, false);
443 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
444 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
445 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
446 BT_MBOX_PRINT(2, SCO_DURATION, true);
447
448 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
449
450 BT_MBOX_PRINT(3, SCO_STATE, false);
451 BT_MBOX_PRINT(3, SNIFF_STATE, false);
452 BT_MBOX_PRINT(3, A2DP_STATE, false);
453 BT_MBOX_PRINT(3, ACL_STATE, false);
454 BT_MBOX_PRINT(3, MSTR_STATE, false);
455 BT_MBOX_PRINT(3, OBX_STATE, false);
456 BT_MBOX_PRINT(3, OPEN_CON_2, false);
457 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
458 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
459 BT_MBOX_PRINT(3, INBAND_P, false);
460 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
461 BT_MBOX_PRINT(3, SSN_2, false);
462 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
463
464 return pos;
465}
466
467static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
468 size_t count, loff_t *ppos)
469{
470 struct iwl_mvm *mvm = file->private_data;
471 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
472 char *buf;
473 int ret, pos = 0, bufsz = sizeof(char) * 1024;
474
475 buf = kmalloc(bufsz, GFP_KERNEL);
476 if (!buf)
477 return -ENOMEM;
478
479 mutex_lock(&mvm->mutex);
480
481 pos += iwl_mvm_coex_dump_mbox(notif, buf, pos, bufsz);
482
483 pos += scnprintf(buf + pos, bufsz - pos, "bt_ci_compliance = %d\n",
484 notif->bt_ci_compliance);
485 pos += scnprintf(buf + pos, bufsz - pos, "primary_ch_lut = %d\n",
486 le32_to_cpu(notif->primary_ch_lut));
487 pos += scnprintf(buf + pos, bufsz - pos, "secondary_ch_lut = %d\n",
488 le32_to_cpu(notif->secondary_ch_lut));
489 pos += scnprintf(buf + pos,
490 bufsz - pos, "bt_activity_grading = %d\n",
491 le32_to_cpu(notif->bt_activity_grading));
492 pos += scnprintf(buf + pos, bufsz - pos,
493 "antenna isolation = %d CORUN LUT index = %d\n",
494 mvm->last_ant_isol, mvm->last_corun_lut);
495 pos += scnprintf(buf + pos, bufsz - pos, "bt_rrc = %d\n",
496 (notif->ttc_rrc_status >> 4) & 0xF);
497 pos += scnprintf(buf + pos, bufsz - pos, "bt_ttc = %d\n",
498 notif->ttc_rrc_status & 0xF);
499
500 pos += scnprintf(buf + pos, bufsz - pos, "sync_sco = %d\n",
501 IWL_MVM_BT_COEX_SYNC2SCO);
502 pos += scnprintf(buf + pos, bufsz - pos, "mplut = %d\n",
503 IWL_MVM_BT_COEX_MPLUT);
504 pos += scnprintf(buf + pos, bufsz - pos, "corunning = %d\n",
505 IWL_MVM_BT_COEX_CORUNNING);
506
507 mutex_unlock(&mvm->mutex);
508
509 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
510 kfree(buf);
511
512 return ret;
513}
514#undef BT_MBOX_PRINT
515
516static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
517 size_t count, loff_t *ppos)
518{
519 struct iwl_mvm *mvm = file->private_data;
520 struct iwl_bt_coex_ci_cmd *cmd = &mvm->last_bt_ci_cmd;
521 char buf[256];
522 int bufsz = sizeof(buf);
523 int pos = 0;
524
525 mutex_lock(&mvm->mutex);
526
527 pos += scnprintf(buf + pos, bufsz - pos, "Channel inhibition CMD\n");
528 pos += scnprintf(buf + pos, bufsz - pos,
529 "\tPrimary Channel Bitmap 0x%016llx\n",
530 le64_to_cpu(cmd->bt_primary_ci));
531 pos += scnprintf(buf + pos, bufsz - pos,
532 "\tSecondary Channel Bitmap 0x%016llx\n",
533 le64_to_cpu(cmd->bt_secondary_ci));
534
535 mutex_unlock(&mvm->mutex);
536
537 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
538}
539
540static ssize_t
541iwl_dbgfs_bt_tx_prio_write(struct iwl_mvm *mvm, char *buf,
542 size_t count, loff_t *ppos)
543{
544 u32 bt_tx_prio;
545
546 if (sscanf(buf, "%u", &bt_tx_prio) != 1)
547 return -EINVAL;
548 if (bt_tx_prio > 4)
549 return -EINVAL;
550
551 mvm->bt_tx_prio = bt_tx_prio;
552
553 return count;
554}
555
556static ssize_t
557iwl_dbgfs_bt_force_ant_write(struct iwl_mvm *mvm, char *buf,
558 size_t count, loff_t *ppos)
559{
560 static const char * const modes_str[BT_FORCE_ANT_MAX] = {
561 [BT_FORCE_ANT_DIS] = "dis",
562 [BT_FORCE_ANT_AUTO] = "auto",
563 [BT_FORCE_ANT_BT] = "bt",
564 [BT_FORCE_ANT_WIFI] = "wifi",
565 };
566 int ret, bt_force_ant_mode;
567
568 for (bt_force_ant_mode = 0;
569 bt_force_ant_mode < ARRAY_SIZE(modes_str);
570 bt_force_ant_mode++) {
571 if (!strcmp(buf, modes_str[bt_force_ant_mode]))
572 break;
573 }
574
575 if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
576 return -EINVAL;
577
578 ret = 0;
579 mutex_lock(&mvm->mutex);
580 if (mvm->bt_force_ant_mode == bt_force_ant_mode)
581 goto out;
582
583 mvm->bt_force_ant_mode = bt_force_ant_mode;
584 IWL_DEBUG_COEX(mvm, "Force mode: %s\n",
585 modes_str[mvm->bt_force_ant_mode]);
586 ret = iwl_send_bt_init_conf(mvm);
587
588out:
589 mutex_unlock(&mvm->mutex);
590 return ret ?: count;
591}
592
593#define PRINT_STATS_LE32(_struct, _memb) \
594 pos += scnprintf(buf + pos, bufsz - pos, \
595 fmt_table, #_memb, \
596 le32_to_cpu(_struct->_memb))
597
598static ssize_t iwl_dbgfs_fw_rx_stats_read(struct file *file,
599 char __user *user_buf, size_t count,
600 loff_t *ppos)
601{
602 struct iwl_mvm *mvm = file->private_data;
603 static const char *fmt_table = "\t%-30s %10u\n";
604 static const char *fmt_header = "%-32s\n";
605 int pos = 0;
606 char *buf;
607 int ret;
608 /* 43 is the size of each data line, 33 is the size of each header */
609 size_t bufsz =
610 ((sizeof(struct mvm_statistics_rx) / sizeof(__le32)) * 43) +
611 (4 * 33) + 1;
612
613 struct mvm_statistics_rx_phy *ofdm;
614 struct mvm_statistics_rx_phy *cck;
615 struct mvm_statistics_rx_non_phy *general;
616 struct mvm_statistics_rx_ht_phy *ht;
617
618 buf = kzalloc(bufsz, GFP_KERNEL);
619 if (!buf)
620 return -ENOMEM;
621
622 mutex_lock(&mvm->mutex);
623
624 ofdm = &mvm->rx_stats.ofdm;
625 cck = &mvm->rx_stats.cck;
626 general = &mvm->rx_stats.general;
627 ht = &mvm->rx_stats.ofdm_ht;
628
629 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
630 "Statistics_Rx - OFDM");
631 PRINT_STATS_LE32(ofdm, ina_cnt);
632 PRINT_STATS_LE32(ofdm, fina_cnt);
633 PRINT_STATS_LE32(ofdm, plcp_err);
634 PRINT_STATS_LE32(ofdm, crc32_err);
635 PRINT_STATS_LE32(ofdm, overrun_err);
636 PRINT_STATS_LE32(ofdm, early_overrun_err);
637 PRINT_STATS_LE32(ofdm, crc32_good);
638 PRINT_STATS_LE32(ofdm, false_alarm_cnt);
639 PRINT_STATS_LE32(ofdm, fina_sync_err_cnt);
640 PRINT_STATS_LE32(ofdm, sfd_timeout);
641 PRINT_STATS_LE32(ofdm, fina_timeout);
642 PRINT_STATS_LE32(ofdm, unresponded_rts);
643 PRINT_STATS_LE32(ofdm, rxe_frame_lmt_overrun);
644 PRINT_STATS_LE32(ofdm, sent_ack_cnt);
645 PRINT_STATS_LE32(ofdm, sent_cts_cnt);
646 PRINT_STATS_LE32(ofdm, sent_ba_rsp_cnt);
647 PRINT_STATS_LE32(ofdm, dsp_self_kill);
648 PRINT_STATS_LE32(ofdm, mh_format_err);
649 PRINT_STATS_LE32(ofdm, re_acq_main_rssi_sum);
650 PRINT_STATS_LE32(ofdm, reserved);
651
652 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
653 "Statistics_Rx - CCK");
654 PRINT_STATS_LE32(cck, ina_cnt);
655 PRINT_STATS_LE32(cck, fina_cnt);
656 PRINT_STATS_LE32(cck, plcp_err);
657 PRINT_STATS_LE32(cck, crc32_err);
658 PRINT_STATS_LE32(cck, overrun_err);
659 PRINT_STATS_LE32(cck, early_overrun_err);
660 PRINT_STATS_LE32(cck, crc32_good);
661 PRINT_STATS_LE32(cck, false_alarm_cnt);
662 PRINT_STATS_LE32(cck, fina_sync_err_cnt);
663 PRINT_STATS_LE32(cck, sfd_timeout);
664 PRINT_STATS_LE32(cck, fina_timeout);
665 PRINT_STATS_LE32(cck, unresponded_rts);
666 PRINT_STATS_LE32(cck, rxe_frame_lmt_overrun);
667 PRINT_STATS_LE32(cck, sent_ack_cnt);
668 PRINT_STATS_LE32(cck, sent_cts_cnt);
669 PRINT_STATS_LE32(cck, sent_ba_rsp_cnt);
670 PRINT_STATS_LE32(cck, dsp_self_kill);
671 PRINT_STATS_LE32(cck, mh_format_err);
672 PRINT_STATS_LE32(cck, re_acq_main_rssi_sum);
673 PRINT_STATS_LE32(cck, reserved);
674
675 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
676 "Statistics_Rx - GENERAL");
677 PRINT_STATS_LE32(general, bogus_cts);
678 PRINT_STATS_LE32(general, bogus_ack);
679 PRINT_STATS_LE32(general, non_bssid_frames);
680 PRINT_STATS_LE32(general, filtered_frames);
681 PRINT_STATS_LE32(general, non_channel_beacons);
682 PRINT_STATS_LE32(general, channel_beacons);
683 PRINT_STATS_LE32(general, num_missed_bcon);
684 PRINT_STATS_LE32(general, adc_rx_saturation_time);
685 PRINT_STATS_LE32(general, ina_detection_search_time);
686 PRINT_STATS_LE32(general, beacon_silence_rssi_a);
687 PRINT_STATS_LE32(general, beacon_silence_rssi_b);
688 PRINT_STATS_LE32(general, beacon_silence_rssi_c);
689 PRINT_STATS_LE32(general, interference_data_flag);
690 PRINT_STATS_LE32(general, channel_load);
691 PRINT_STATS_LE32(general, dsp_false_alarms);
692 PRINT_STATS_LE32(general, beacon_rssi_a);
693 PRINT_STATS_LE32(general, beacon_rssi_b);
694 PRINT_STATS_LE32(general, beacon_rssi_c);
695 PRINT_STATS_LE32(general, beacon_energy_a);
696 PRINT_STATS_LE32(general, beacon_energy_b);
697 PRINT_STATS_LE32(general, beacon_energy_c);
698 PRINT_STATS_LE32(general, num_bt_kills);
699 PRINT_STATS_LE32(general, mac_id);
700 PRINT_STATS_LE32(general, directed_data_mpdu);
701
702 pos += scnprintf(buf + pos, bufsz - pos, fmt_header,
703 "Statistics_Rx - HT");
704 PRINT_STATS_LE32(ht, plcp_err);
705 PRINT_STATS_LE32(ht, overrun_err);
706 PRINT_STATS_LE32(ht, early_overrun_err);
707 PRINT_STATS_LE32(ht, crc32_good);
708 PRINT_STATS_LE32(ht, crc32_err);
709 PRINT_STATS_LE32(ht, mh_format_err);
710 PRINT_STATS_LE32(ht, agg_crc32_good);
711 PRINT_STATS_LE32(ht, agg_mpdu_cnt);
712 PRINT_STATS_LE32(ht, agg_cnt);
713 PRINT_STATS_LE32(ht, unsupport_mcs);
714
715 mutex_unlock(&mvm->mutex);
716
717 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
718 kfree(buf);
719
720 return ret;
721}
722#undef PRINT_STAT_LE32
723
724static ssize_t iwl_dbgfs_frame_stats_read(struct iwl_mvm *mvm,
725 char __user *user_buf, size_t count,
726 loff_t *ppos,
727 struct iwl_mvm_frame_stats *stats)
728{
729 char *buff, *pos, *endpos;
730 int idx, i;
731 int ret;
732 static const size_t bufsz = 1024;
733
734 buff = kmalloc(bufsz, GFP_KERNEL);
735 if (!buff)
736 return -ENOMEM;
737
738 spin_lock_bh(&mvm->drv_stats_lock);
739
740 pos = buff;
741 endpos = pos + bufsz;
742
743 pos += scnprintf(pos, endpos - pos,
744 "Legacy/HT/VHT\t:\t%d/%d/%d\n",
745 stats->legacy_frames,
746 stats->ht_frames,
747 stats->vht_frames);
748 pos += scnprintf(pos, endpos - pos, "20/40/80\t:\t%d/%d/%d\n",
749 stats->bw_20_frames,
750 stats->bw_40_frames,
751 stats->bw_80_frames);
752 pos += scnprintf(pos, endpos - pos, "NGI/SGI\t\t:\t%d/%d\n",
753 stats->ngi_frames,
754 stats->sgi_frames);
755 pos += scnprintf(pos, endpos - pos, "SISO/MIMO2\t:\t%d/%d\n",
756 stats->siso_frames,
757 stats->mimo2_frames);
758 pos += scnprintf(pos, endpos - pos, "FAIL/SCSS\t:\t%d/%d\n",
759 stats->fail_frames,
760 stats->success_frames);
761 pos += scnprintf(pos, endpos - pos, "MPDUs agg\t:\t%d\n",
762 stats->agg_frames);
763 pos += scnprintf(pos, endpos - pos, "A-MPDUs\t\t:\t%d\n",
764 stats->ampdu_count);
765 pos += scnprintf(pos, endpos - pos, "Avg MPDUs/A-MPDU:\t%d\n",
766 stats->ampdu_count > 0 ?
767 (stats->agg_frames / stats->ampdu_count) : 0);
768
769 pos += scnprintf(pos, endpos - pos, "Last Rates\n");
770
771 idx = stats->last_frame_idx - 1;
772 for (i = 0; i < ARRAY_SIZE(stats->last_rates); i++) {
773 idx = (idx + 1) % ARRAY_SIZE(stats->last_rates);
774 if (stats->last_rates[idx] == 0)
775 continue;
776 pos += scnprintf(pos, endpos - pos, "Rate[%d]: ",
777 (int)(ARRAY_SIZE(stats->last_rates) - i));
778 pos += rs_pretty_print_rate(pos, stats->last_rates[idx]);
779 }
780 spin_unlock_bh(&mvm->drv_stats_lock);
781
782 ret = simple_read_from_buffer(user_buf, count, ppos, buff, pos - buff);
783 kfree(buff);
784
785 return ret;
786}
787
788static ssize_t iwl_dbgfs_drv_rx_stats_read(struct file *file,
789 char __user *user_buf, size_t count,
790 loff_t *ppos)
791{
792 struct iwl_mvm *mvm = file->private_data;
793
794 return iwl_dbgfs_frame_stats_read(mvm, user_buf, count, ppos,
795 &mvm->drv_rx_stats);
796}
797
798static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mvm *mvm, char *buf,
799 size_t count, loff_t *ppos)
800{
801 int ret;
802
803 mutex_lock(&mvm->mutex);
804
805 /* allow one more restart that we're provoking here */
806 if (mvm->restart_fw >= 0)
807 mvm->restart_fw++;
808
809 /* take the return value to make compiler happy - it will fail anyway */
810 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, 0, 0, NULL);
811
812 mutex_unlock(&mvm->mutex);
813
814 return count;
815}
816
817static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mvm *mvm, char *buf,
818 size_t count, loff_t *ppos)
819{
820 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_NMI);
821 if (ret)
822 return ret;
823
824 iwl_force_nmi(mvm->trans);
825
826 iwl_mvm_unref(mvm, IWL_MVM_REF_NMI);
827
828 return count;
829}
830
831static ssize_t
832iwl_dbgfs_scan_ant_rxchain_read(struct file *file,
833 char __user *user_buf,
834 size_t count, loff_t *ppos)
835{
836 struct iwl_mvm *mvm = file->private_data;
837 int pos = 0;
838 char buf[32];
839 const size_t bufsz = sizeof(buf);
840
841 /* print which antennas were set for the scan command by the user */
842 pos += scnprintf(buf + pos, bufsz - pos, "Antennas for scan: ");
843 if (mvm->scan_rx_ant & ANT_A)
844 pos += scnprintf(buf + pos, bufsz - pos, "A");
845 if (mvm->scan_rx_ant & ANT_B)
846 pos += scnprintf(buf + pos, bufsz - pos, "B");
847 if (mvm->scan_rx_ant & ANT_C)
848 pos += scnprintf(buf + pos, bufsz - pos, "C");
849 pos += scnprintf(buf + pos, bufsz - pos, " (%hhx)\n", mvm->scan_rx_ant);
850
851 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
852}
853
854static ssize_t
855iwl_dbgfs_scan_ant_rxchain_write(struct iwl_mvm *mvm, char *buf,
856 size_t count, loff_t *ppos)
857{
858 u8 scan_rx_ant;
859
860 if (sscanf(buf, "%hhx", &scan_rx_ant) != 1)
861 return -EINVAL;
862 if (scan_rx_ant > ANT_ABC)
863 return -EINVAL;
864 if (scan_rx_ant & ~(iwl_mvm_get_valid_rx_ant(mvm)))
865 return -EINVAL;
866
867 if (mvm->scan_rx_ant != scan_rx_ant) {
868 mvm->scan_rx_ant = scan_rx_ant;
869 if (fw_has_capa(&mvm->fw->ucode_capa,
870 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
871 iwl_mvm_config_scan(mvm);
872 }
873
874 return count;
875}
876
877static ssize_t iwl_dbgfs_indirection_tbl_write(struct iwl_mvm *mvm,
878 char *buf, size_t count,
879 loff_t *ppos)
880{
881 struct iwl_rss_config_cmd cmd = {
882 .flags = cpu_to_le32(IWL_RSS_ENABLE),
883 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
884 IWL_RSS_HASH_TYPE_IPV4_UDP |
885 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
886 IWL_RSS_HASH_TYPE_IPV6_TCP |
887 IWL_RSS_HASH_TYPE_IPV6_UDP |
888 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
889 };
890 int ret, i, num_repeats, nbytes = count / 2;
891
892 ret = hex2bin(cmd.indirection_table, buf, nbytes);
893 if (ret)
894 return ret;
895
896 /*
897 * The input is the redirection table, partial or full.
898 * Repeat the pattern if needed.
899 * For example, input of 01020F will be repeated 42 times,
900 * indirecting RSS hash results to queues 1, 2, 15 (skipping
901 * queues 3 - 14).
902 */
903 num_repeats = ARRAY_SIZE(cmd.indirection_table) / nbytes;
904 for (i = 1; i < num_repeats; i++)
905 memcpy(&cmd.indirection_table[i * nbytes],
906 cmd.indirection_table, nbytes);
907 /* handle cut in the middle pattern for the last places */
908 memcpy(&cmd.indirection_table[i * nbytes], cmd.indirection_table,
909 ARRAY_SIZE(cmd.indirection_table) % nbytes);
910
911 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
912
913 mutex_lock(&mvm->mutex);
914 ret = iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
915 mutex_unlock(&mvm->mutex);
916
917 return ret ?: count;
918}
919
920static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mvm *mvm,
921 char *buf, size_t count,
922 loff_t *ppos)
923{
924 struct iwl_rx_cmd_buffer rxb = {
925 ._rx_page_order = 0,
926 .truesize = 0, /* not used */
927 ._offset = 0,
928 };
929 struct iwl_rx_packet *pkt;
930 struct iwl_rx_mpdu_desc *desc;
931 int bin_len = count / 2;
932 int ret = -EINVAL;
933
934 /* supporting only 9000 descriptor */
935 if (!mvm->trans->cfg->mq_rx_supported)
936 return -ENOTSUPP;
937
938 rxb._page = alloc_pages(GFP_ATOMIC, 0);
939 if (!rxb._page)
940 return -ENOMEM;
941 pkt = rxb_addr(&rxb);
942
943 ret = hex2bin(page_address(rxb._page), buf, bin_len);
944 if (ret)
945 goto out;
946
947 /* avoid invalid memory access */
948 if (bin_len < sizeof(*pkt) + sizeof(*desc))
949 goto out;
950
951 /* check this is RX packet */
952 if (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd) !=
953 WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD))
954 goto out;
955
956 /* check the length in metadata matches actual received length */
957 desc = (void *)pkt->data;
958 if (le16_to_cpu(desc->mpdu_len) !=
959 (bin_len - sizeof(*desc) - sizeof(*pkt)))
960 goto out;
961
962 local_bh_disable();
963 iwl_mvm_rx_mpdu_mq(mvm, NULL, &rxb, 0);
964 local_bh_enable();
965 ret = 0;
966
967out:
968 iwl_free_rxb(&rxb);
969
970 return ret ?: count;
971}
972
973static ssize_t iwl_dbgfs_fw_dbg_conf_read(struct file *file,
974 char __user *user_buf,
975 size_t count, loff_t *ppos)
976{
977 struct iwl_mvm *mvm = file->private_data;
978 int conf;
979 char buf[8];
980 const size_t bufsz = sizeof(buf);
981 int pos = 0;
982
983 mutex_lock(&mvm->mutex);
984 conf = mvm->fw_dbg_conf;
985 mutex_unlock(&mvm->mutex);
986
987 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", conf);
988
989 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
990}
991
992/*
993 * Enable / Disable continuous recording.
994 * Cause the FW to start continuous recording, by sending the relevant hcmd.
995 * Enable: input of every integer larger than 0, ENABLE_CONT_RECORDING.
996 * Disable: for 0 as input, DISABLE_CONT_RECORDING.
997 */
998static ssize_t iwl_dbgfs_cont_recording_write(struct iwl_mvm *mvm,
999 char *buf, size_t count,
1000 loff_t *ppos)
1001{
1002 struct iwl_trans *trans = mvm->trans;
1003 const struct iwl_fw_dbg_dest_tlv *dest = trans->dbg_dest_tlv;
1004 struct iwl_continuous_record_cmd cont_rec = {};
1005 int ret, rec_mode;
1006
1007 if (!dest)
1008 return -EOPNOTSUPP;
1009
1010 if (dest->monitor_mode != SMEM_MODE ||
1011 trans->cfg->device_family != IWL_DEVICE_FAMILY_8000)
1012 return -EOPNOTSUPP;
1013
1014 ret = kstrtoint(buf, 0, &rec_mode);
1015 if (ret)
1016 return ret;
1017
1018 cont_rec.record_mode.enable_recording = rec_mode ?
1019 cpu_to_le16(ENABLE_CONT_RECORDING) :
1020 cpu_to_le16(DISABLE_CONT_RECORDING);
1021
1022 mutex_lock(&mvm->mutex);
1023 ret = iwl_mvm_send_cmd_pdu(mvm, LDBG_CONFIG_CMD, 0,
1024 sizeof(cont_rec), &cont_rec);
1025 mutex_unlock(&mvm->mutex);
1026
1027 return ret ?: count;
1028}
1029
1030static ssize_t iwl_dbgfs_fw_dbg_conf_write(struct iwl_mvm *mvm,
1031 char *buf, size_t count,
1032 loff_t *ppos)
1033{
1034 unsigned int conf_id;
1035 int ret;
1036
1037 ret = kstrtouint(buf, 0, &conf_id);
1038 if (ret)
1039 return ret;
1040
1041 if (WARN_ON(conf_id >= FW_DBG_CONF_MAX))
1042 return -EINVAL;
1043
1044 mutex_lock(&mvm->mutex);
1045 ret = iwl_mvm_start_fw_dbg_conf(mvm, conf_id);
1046 mutex_unlock(&mvm->mutex);
1047
1048 return ret ?: count;
1049}
1050
1051static ssize_t iwl_dbgfs_fw_dbg_collect_write(struct iwl_mvm *mvm,
1052 char *buf, size_t count,
1053 loff_t *ppos)
1054{
1055 int ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1056
1057 if (ret)
1058 return ret;
1059
1060 iwl_mvm_fw_dbg_collect(mvm, FW_DBG_TRIGGER_USER, buf,
1061 (count - 1), NULL);
1062
1063 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1064
1065 return count;
1066}
1067
1068static ssize_t iwl_dbgfs_max_amsdu_len_write(struct iwl_mvm *mvm,
1069 char *buf, size_t count,
1070 loff_t *ppos)
1071{
1072 unsigned int max_amsdu_len;
1073 int ret;
1074
1075 ret = kstrtouint(buf, 0, &max_amsdu_len);
1076 if (ret)
1077 return ret;
1078
1079 if (max_amsdu_len > IEEE80211_MAX_MPDU_LEN_VHT_11454)
1080 return -EINVAL;
1081 mvm->max_amsdu_len = max_amsdu_len;
1082
1083 return count;
1084}
1085
1086#define ADD_TEXT(...) pos += scnprintf(buf + pos, bufsz - pos, __VA_ARGS__)
1087#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1088static ssize_t iwl_dbgfs_bcast_filters_read(struct file *file,
1089 char __user *user_buf,
1090 size_t count, loff_t *ppos)
1091{
1092 struct iwl_mvm *mvm = file->private_data;
1093 struct iwl_bcast_filter_cmd cmd;
1094 const struct iwl_fw_bcast_filter *filter;
1095 char *buf;
1096 int bufsz = 1024;
1097 int i, j, pos = 0;
1098 ssize_t ret;
1099
1100 buf = kzalloc(bufsz, GFP_KERNEL);
1101 if (!buf)
1102 return -ENOMEM;
1103
1104 mutex_lock(&mvm->mutex);
1105 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1106 ADD_TEXT("None\n");
1107 mutex_unlock(&mvm->mutex);
1108 goto out;
1109 }
1110 mutex_unlock(&mvm->mutex);
1111
1112 for (i = 0; cmd.filters[i].attrs[0].mask; i++) {
1113 filter = &cmd.filters[i];
1114
1115 ADD_TEXT("Filter [%d]:\n", i);
1116 ADD_TEXT("\tDiscard=%d\n", filter->discard);
1117 ADD_TEXT("\tFrame Type: %s\n",
1118 filter->frame_type ? "IPv4" : "Generic");
1119
1120 for (j = 0; j < ARRAY_SIZE(filter->attrs); j++) {
1121 const struct iwl_fw_bcast_filter_attr *attr;
1122
1123 attr = &filter->attrs[j];
1124 if (!attr->mask)
1125 break;
1126
1127 ADD_TEXT("\tAttr [%d]: offset=%d (from %s), mask=0x%x, value=0x%x reserved=0x%x\n",
1128 j, attr->offset,
1129 attr->offset_type ? "IP End" :
1130 "Payload Start",
1131 be32_to_cpu(attr->mask),
1132 be32_to_cpu(attr->val),
1133 le16_to_cpu(attr->reserved1));
1134 }
1135 }
1136out:
1137 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1138 kfree(buf);
1139 return ret;
1140}
1141
1142static ssize_t iwl_dbgfs_bcast_filters_write(struct iwl_mvm *mvm, char *buf,
1143 size_t count, loff_t *ppos)
1144{
1145 int pos, next_pos;
1146 struct iwl_fw_bcast_filter filter = {};
1147 struct iwl_bcast_filter_cmd cmd;
1148 u32 filter_id, attr_id, mask, value;
1149 int err = 0;
1150
1151 if (sscanf(buf, "%d %hhi %hhi %n", &filter_id, &filter.discard,
1152 &filter.frame_type, &pos) != 3)
1153 return -EINVAL;
1154
1155 if (filter_id >= ARRAY_SIZE(mvm->dbgfs_bcast_filtering.cmd.filters) ||
1156 filter.frame_type > BCAST_FILTER_FRAME_TYPE_IPV4)
1157 return -EINVAL;
1158
1159 for (attr_id = 0; attr_id < ARRAY_SIZE(filter.attrs);
1160 attr_id++) {
1161 struct iwl_fw_bcast_filter_attr *attr =
1162 &filter.attrs[attr_id];
1163
1164 if (pos >= count)
1165 break;
1166
1167 if (sscanf(&buf[pos], "%hhi %hhi %i %i %n",
1168 &attr->offset, &attr->offset_type,
1169 &mask, &value, &next_pos) != 4)
1170 return -EINVAL;
1171
1172 attr->mask = cpu_to_be32(mask);
1173 attr->val = cpu_to_be32(value);
1174 if (mask)
1175 filter.num_attrs++;
1176
1177 pos += next_pos;
1178 }
1179
1180 mutex_lock(&mvm->mutex);
1181 memcpy(&mvm->dbgfs_bcast_filtering.cmd.filters[filter_id],
1182 &filter, sizeof(filter));
1183
1184 /* send updated bcast filtering configuration */
1185 if (mvm->dbgfs_bcast_filtering.override &&
1186 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1187 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1188 sizeof(cmd), &cmd);
1189 mutex_unlock(&mvm->mutex);
1190
1191 return err ?: count;
1192}
1193
1194static ssize_t iwl_dbgfs_bcast_filters_macs_read(struct file *file,
1195 char __user *user_buf,
1196 size_t count, loff_t *ppos)
1197{
1198 struct iwl_mvm *mvm = file->private_data;
1199 struct iwl_bcast_filter_cmd cmd;
1200 char *buf;
1201 int bufsz = 1024;
1202 int i, pos = 0;
1203 ssize_t ret;
1204
1205 buf = kzalloc(bufsz, GFP_KERNEL);
1206 if (!buf)
1207 return -ENOMEM;
1208
1209 mutex_lock(&mvm->mutex);
1210 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) {
1211 ADD_TEXT("None\n");
1212 mutex_unlock(&mvm->mutex);
1213 goto out;
1214 }
1215 mutex_unlock(&mvm->mutex);
1216
1217 for (i = 0; i < ARRAY_SIZE(cmd.macs); i++) {
1218 const struct iwl_fw_bcast_mac *mac = &cmd.macs[i];
1219
1220 ADD_TEXT("Mac [%d]: discard=%d attached_filters=0x%x\n",
1221 i, mac->default_discard, mac->attached_filters);
1222 }
1223out:
1224 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1225 kfree(buf);
1226 return ret;
1227}
1228
1229static ssize_t iwl_dbgfs_bcast_filters_macs_write(struct iwl_mvm *mvm,
1230 char *buf, size_t count,
1231 loff_t *ppos)
1232{
1233 struct iwl_bcast_filter_cmd cmd;
1234 struct iwl_fw_bcast_mac mac = {};
1235 u32 mac_id, attached_filters;
1236 int err = 0;
1237
1238 if (!mvm->bcast_filters)
1239 return -ENOENT;
1240
1241 if (sscanf(buf, "%d %hhi %i", &mac_id, &mac.default_discard,
1242 &attached_filters) != 3)
1243 return -EINVAL;
1244
1245 if (mac_id >= ARRAY_SIZE(cmd.macs) ||
1246 mac.default_discard > 1 ||
1247 attached_filters >= BIT(ARRAY_SIZE(cmd.filters)))
1248 return -EINVAL;
1249
1250 mac.attached_filters = cpu_to_le16(attached_filters);
1251
1252 mutex_lock(&mvm->mutex);
1253 memcpy(&mvm->dbgfs_bcast_filtering.cmd.macs[mac_id],
1254 &mac, sizeof(mac));
1255
1256 /* send updated bcast filtering configuration */
1257 if (mvm->dbgfs_bcast_filtering.override &&
1258 iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1259 err = iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1260 sizeof(cmd), &cmd);
1261 mutex_unlock(&mvm->mutex);
1262
1263 return err ?: count;
1264}
1265#endif
1266
1267#ifdef CONFIG_PM_SLEEP
1268static ssize_t iwl_dbgfs_d3_sram_write(struct iwl_mvm *mvm, char *buf,
1269 size_t count, loff_t *ppos)
1270{
1271 int store;
1272
1273 if (sscanf(buf, "%d", &store) != 1)
1274 return -EINVAL;
1275
1276 mvm->store_d3_resume_sram = store;
1277
1278 return count;
1279}
1280
1281static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf,
1282 size_t count, loff_t *ppos)
1283{
1284 struct iwl_mvm *mvm = file->private_data;
1285 const struct fw_img *img;
1286 int ofs, len, pos = 0;
1287 size_t bufsz, ret;
1288 char *buf;
1289 u8 *ptr = mvm->d3_resume_sram;
1290
1291 img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1292 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1293
1294 bufsz = len * 4 + 256;
1295 buf = kzalloc(bufsz, GFP_KERNEL);
1296 if (!buf)
1297 return -ENOMEM;
1298
1299 pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n",
1300 mvm->store_d3_resume_sram ? "en" : "dis");
1301
1302 if (ptr) {
1303 for (ofs = 0; ofs < len; ofs += 16) {
1304 pos += scnprintf(buf + pos, bufsz - pos,
1305 "0x%.4x %16ph\n", ofs, ptr + ofs);
1306 }
1307 } else {
1308 pos += scnprintf(buf + pos, bufsz - pos,
1309 "(no data captured)\n");
1310 }
1311
1312 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1313
1314 kfree(buf);
1315
1316 return ret;
1317}
1318#endif
1319
1320#define PRINT_MVM_REF(ref) do { \
1321 if (mvm->refs[ref]) \
1322 pos += scnprintf(buf + pos, bufsz - pos, \
1323 "\t(0x%lx): %d %s\n", \
1324 BIT(ref), mvm->refs[ref], #ref); \
1325} while (0)
1326
1327static ssize_t iwl_dbgfs_d0i3_refs_read(struct file *file,
1328 char __user *user_buf,
1329 size_t count, loff_t *ppos)
1330{
1331 struct iwl_mvm *mvm = file->private_data;
1332 int i, pos = 0;
1333 char buf[256];
1334 const size_t bufsz = sizeof(buf);
1335 u32 refs = 0;
1336
1337 for (i = 0; i < IWL_MVM_REF_COUNT; i++)
1338 if (mvm->refs[i])
1339 refs |= BIT(i);
1340
1341 pos += scnprintf(buf + pos, bufsz - pos, "taken mvm refs: 0x%x\n",
1342 refs);
1343
1344 PRINT_MVM_REF(IWL_MVM_REF_UCODE_DOWN);
1345 PRINT_MVM_REF(IWL_MVM_REF_SCAN);
1346 PRINT_MVM_REF(IWL_MVM_REF_ROC);
1347 PRINT_MVM_REF(IWL_MVM_REF_ROC_AUX);
1348 PRINT_MVM_REF(IWL_MVM_REF_P2P_CLIENT);
1349 PRINT_MVM_REF(IWL_MVM_REF_AP_IBSS);
1350 PRINT_MVM_REF(IWL_MVM_REF_USER);
1351 PRINT_MVM_REF(IWL_MVM_REF_TX);
1352 PRINT_MVM_REF(IWL_MVM_REF_TX_AGG);
1353 PRINT_MVM_REF(IWL_MVM_REF_ADD_IF);
1354 PRINT_MVM_REF(IWL_MVM_REF_START_AP);
1355 PRINT_MVM_REF(IWL_MVM_REF_BSS_CHANGED);
1356 PRINT_MVM_REF(IWL_MVM_REF_PREPARE_TX);
1357 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_TDLS);
1358 PRINT_MVM_REF(IWL_MVM_REF_CHECK_CTKILL);
1359 PRINT_MVM_REF(IWL_MVM_REF_PRPH_READ);
1360 PRINT_MVM_REF(IWL_MVM_REF_PRPH_WRITE);
1361 PRINT_MVM_REF(IWL_MVM_REF_NMI);
1362 PRINT_MVM_REF(IWL_MVM_REF_TM_CMD);
1363 PRINT_MVM_REF(IWL_MVM_REF_EXIT_WORK);
1364 PRINT_MVM_REF(IWL_MVM_REF_PROTECT_CSA);
1365 PRINT_MVM_REF(IWL_MVM_REF_FW_DBG_COLLECT);
1366 PRINT_MVM_REF(IWL_MVM_REF_INIT_UCODE);
1367 PRINT_MVM_REF(IWL_MVM_REF_SENDING_CMD);
1368 PRINT_MVM_REF(IWL_MVM_REF_RX);
1369
1370 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1371}
1372
1373static ssize_t iwl_dbgfs_d0i3_refs_write(struct iwl_mvm *mvm, char *buf,
1374 size_t count, loff_t *ppos)
1375{
1376 unsigned long value;
1377 int ret;
1378 bool taken;
1379
1380 ret = kstrtoul(buf, 10, &value);
1381 if (ret < 0)
1382 return ret;
1383
1384 mutex_lock(&mvm->mutex);
1385
1386 taken = mvm->refs[IWL_MVM_REF_USER];
1387 if (value == 1 && !taken)
1388 iwl_mvm_ref(mvm, IWL_MVM_REF_USER);
1389 else if (value == 0 && taken)
1390 iwl_mvm_unref(mvm, IWL_MVM_REF_USER);
1391 else
1392 ret = -EINVAL;
1393
1394 mutex_unlock(&mvm->mutex);
1395
1396 if (ret < 0)
1397 return ret;
1398 return count;
1399}
1400
1401#define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
1402 _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1403#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
1404 _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_mvm)
1405#define MVM_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode) do { \
1406 if (!debugfs_create_file(alias, mode, parent, mvm, \
1407 &iwl_dbgfs_##name##_ops)) \
1408 goto err; \
1409 } while (0)
1410#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) \
1411 MVM_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1412
1413static ssize_t
1414iwl_dbgfs_prph_reg_read(struct file *file,
1415 char __user *user_buf,
1416 size_t count, loff_t *ppos)
1417{
1418 struct iwl_mvm *mvm = file->private_data;
1419 int pos = 0;
1420 char buf[32];
1421 const size_t bufsz = sizeof(buf);
1422 int ret;
1423
1424 if (!mvm->dbgfs_prph_reg_addr)
1425 return -EINVAL;
1426
1427 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_READ);
1428 if (ret)
1429 return ret;
1430
1431 pos += scnprintf(buf + pos, bufsz - pos, "Reg 0x%x: (0x%x)\n",
1432 mvm->dbgfs_prph_reg_addr,
1433 iwl_read_prph(mvm->trans, mvm->dbgfs_prph_reg_addr));
1434
1435 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_READ);
1436
1437 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1438}
1439
1440static ssize_t
1441iwl_dbgfs_prph_reg_write(struct iwl_mvm *mvm, char *buf,
1442 size_t count, loff_t *ppos)
1443{
1444 u8 args;
1445 u32 value;
1446 int ret;
1447
1448 args = sscanf(buf, "%i %i", &mvm->dbgfs_prph_reg_addr, &value);
1449 /* if we only want to set the reg address - nothing more to do */
1450 if (args == 1)
1451 goto out;
1452
1453 /* otherwise, make sure we have both address and value */
1454 if (args != 2)
1455 return -EINVAL;
1456
1457 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PRPH_WRITE);
1458 if (ret)
1459 return ret;
1460
1461 iwl_write_prph(mvm->trans, mvm->dbgfs_prph_reg_addr, value);
1462
1463 iwl_mvm_unref(mvm, IWL_MVM_REF_PRPH_WRITE);
1464out:
1465 return count;
1466}
1467
1468static ssize_t
1469iwl_dbgfs_send_echo_cmd_write(struct iwl_mvm *mvm, char *buf,
1470 size_t count, loff_t *ppos)
1471{
1472 int ret;
1473
1474 mutex_lock(&mvm->mutex);
1475 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1476 mutex_unlock(&mvm->mutex);
1477
1478 return ret ?: count;
1479}
1480
1481MVM_DEBUGFS_READ_WRITE_FILE_OPS(prph_reg, 64);
1482
1483/* Device wide debugfs entries */
1484MVM_DEBUGFS_READ_FILE_OPS(ctdp_budget);
1485MVM_DEBUGFS_WRITE_FILE_OPS(stop_ctdp, 8);
1486MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush, 16);
1487MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain, 8);
1488MVM_DEBUGFS_WRITE_FILE_OPS(send_echo_cmd, 8);
1489MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram, 64);
1490MVM_DEBUGFS_READ_WRITE_FILE_OPS(set_nic_temperature, 64);
1491MVM_DEBUGFS_READ_FILE_OPS(nic_temp);
1492MVM_DEBUGFS_READ_FILE_OPS(stations);
1493MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
1494MVM_DEBUGFS_READ_FILE_OPS(bt_cmd);
1495MVM_DEBUGFS_READ_WRITE_FILE_OPS(disable_power_off, 64);
1496MVM_DEBUGFS_READ_FILE_OPS(fw_rx_stats);
1497MVM_DEBUGFS_READ_FILE_OPS(drv_rx_stats);
1498MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart, 10);
1499MVM_DEBUGFS_WRITE_FILE_OPS(fw_nmi, 10);
1500MVM_DEBUGFS_WRITE_FILE_OPS(bt_tx_prio, 10);
1501MVM_DEBUGFS_WRITE_FILE_OPS(bt_force_ant, 10);
1502MVM_DEBUGFS_READ_WRITE_FILE_OPS(scan_ant_rxchain, 8);
1503MVM_DEBUGFS_READ_WRITE_FILE_OPS(d0i3_refs, 8);
1504MVM_DEBUGFS_READ_WRITE_FILE_OPS(fw_dbg_conf, 8);
1505MVM_DEBUGFS_WRITE_FILE_OPS(fw_dbg_collect, 64);
1506MVM_DEBUGFS_WRITE_FILE_OPS(cont_recording, 8);
1507MVM_DEBUGFS_WRITE_FILE_OPS(max_amsdu_len, 8);
1508MVM_DEBUGFS_WRITE_FILE_OPS(indirection_tbl,
1509 (IWL_RSS_INDIRECTION_TABLE_SIZE * 2));
1510MVM_DEBUGFS_WRITE_FILE_OPS(inject_packet, 512);
1511
1512#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1513MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters, 256);
1514MVM_DEBUGFS_READ_WRITE_FILE_OPS(bcast_filters_macs, 256);
1515#endif
1516
1517#ifdef CONFIG_PM_SLEEP
1518MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram, 8);
1519#endif
1520
1521static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1522 size_t count, loff_t *ppos)
1523{
1524 struct iwl_mvm *mvm = file->private_data;
1525 struct iwl_dbg_mem_access_cmd cmd = {};
1526 struct iwl_dbg_mem_access_rsp *rsp;
1527 struct iwl_host_cmd hcmd = {
1528 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1529 .data = { &cmd, },
1530 .len = { sizeof(cmd) },
1531 };
1532 size_t delta;
1533 ssize_t ret, len;
1534
1535 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1536 DEBUG_GROUP, 0);
1537 cmd.op = cpu_to_le32(DEBUG_MEM_OP_READ);
1538
1539 /* Take care of alignment of both the position and the length */
1540 delta = *ppos & 0x3;
1541 cmd.addr = cpu_to_le32(*ppos - delta);
1542 cmd.len = cpu_to_le32(min(ALIGN(count + delta, 4) / 4,
1543 (size_t)DEBUG_MEM_MAX_SIZE_DWORDS));
1544
1545 mutex_lock(&mvm->mutex);
1546 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1547 mutex_unlock(&mvm->mutex);
1548
1549 if (ret < 0)
1550 return ret;
1551
1552 rsp = (void *)hcmd.resp_pkt->data;
1553 if (le32_to_cpu(rsp->status) != DEBUG_MEM_STATUS_SUCCESS) {
1554 ret = -ENXIO;
1555 goto out;
1556 }
1557
1558 len = min((size_t)le32_to_cpu(rsp->len) << 2,
1559 iwl_rx_packet_payload_len(hcmd.resp_pkt) - sizeof(*rsp));
1560 len = min(len - delta, count);
1561 if (len < 0) {
1562 ret = -EFAULT;
1563 goto out;
1564 }
1565
1566 ret = len - copy_to_user(user_buf, (void *)rsp->data + delta, len);
1567 *ppos += ret;
1568
1569out:
1570 iwl_free_resp(&hcmd);
1571 return ret;
1572}
1573
1574static ssize_t iwl_dbgfs_mem_write(struct file *file,
1575 const char __user *user_buf, size_t count,
1576 loff_t *ppos)
1577{
1578 struct iwl_mvm *mvm = file->private_data;
1579 struct iwl_dbg_mem_access_cmd *cmd;
1580 struct iwl_dbg_mem_access_rsp *rsp;
1581 struct iwl_host_cmd hcmd = {};
1582 size_t cmd_size;
1583 size_t data_size;
1584 u32 op, len;
1585 ssize_t ret;
1586
1587 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1588 DEBUG_GROUP, 0);
1589
1590 if (*ppos & 0x3 || count < 4) {
1591 op = DEBUG_MEM_OP_WRITE_BYTES;
1592 len = min(count, (size_t)(4 - (*ppos & 0x3)));
1593 data_size = len;
1594 } else {
1595 op = DEBUG_MEM_OP_WRITE;
1596 len = min(count >> 2, (size_t)DEBUG_MEM_MAX_SIZE_DWORDS);
1597 data_size = len << 2;
1598 }
1599
1600 cmd_size = sizeof(*cmd) + ALIGN(data_size, 4);
1601 cmd = kzalloc(cmd_size, GFP_KERNEL);
1602 if (!cmd)
1603 return -ENOMEM;
1604
1605 cmd->op = cpu_to_le32(op);
1606 cmd->len = cpu_to_le32(len);
1607 cmd->addr = cpu_to_le32(*ppos);
1608 if (copy_from_user((void *)cmd->data, user_buf, data_size)) {
1609 kfree(cmd);
1610 return -EFAULT;
1611 }
1612
1613 hcmd.flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
1614 hcmd.data[0] = (void *)cmd;
1615 hcmd.len[0] = cmd_size;
1616
1617 mutex_lock(&mvm->mutex);
1618 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1619 mutex_unlock(&mvm->mutex);
1620
1621 kfree(cmd);
1622
1623 if (ret < 0)
1624 return ret;
1625
1626 rsp = (void *)hcmd.resp_pkt->data;
1627 if (rsp->status != DEBUG_MEM_STATUS_SUCCESS) {
1628 ret = -ENXIO;
1629 goto out;
1630 }
1631
1632 ret = data_size;
1633 *ppos += ret;
1634
1635out:
1636 iwl_free_resp(&hcmd);
1637 return ret;
1638}
1639
1640static const struct file_operations iwl_dbgfs_mem_ops = {
1641 .read = iwl_dbgfs_mem_read,
1642 .write = iwl_dbgfs_mem_write,
1643 .open = simple_open,
1644 .llseek = default_llseek,
1645};
1646
1647int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
1648{
1649 struct dentry *bcast_dir __maybe_unused;
1650 char buf[100];
1651
1652 spin_lock_init(&mvm->drv_stats_lock);
1653
1654 mvm->debugfs_dir = dbgfs_dir;
1655
1656 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
1657 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
1658 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1659 MVM_DEBUGFS_ADD_FILE(set_nic_temperature, mvm->debugfs_dir,
1660 S_IWUSR | S_IRUSR);
1661 MVM_DEBUGFS_ADD_FILE(nic_temp, dbgfs_dir, S_IRUSR);
1662 MVM_DEBUGFS_ADD_FILE(ctdp_budget, dbgfs_dir, S_IRUSR);
1663 MVM_DEBUGFS_ADD_FILE(stop_ctdp, dbgfs_dir, S_IWUSR);
1664 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
1665 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
1666 MVM_DEBUGFS_ADD_FILE(bt_cmd, dbgfs_dir, S_IRUSR);
1667 MVM_DEBUGFS_ADD_FILE(disable_power_off, mvm->debugfs_dir,
1668 S_IRUSR | S_IWUSR);
1669 MVM_DEBUGFS_ADD_FILE(fw_rx_stats, mvm->debugfs_dir, S_IRUSR);
1670 MVM_DEBUGFS_ADD_FILE(drv_rx_stats, mvm->debugfs_dir, S_IRUSR);
1671 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
1672 MVM_DEBUGFS_ADD_FILE(fw_nmi, mvm->debugfs_dir, S_IWUSR);
1673 MVM_DEBUGFS_ADD_FILE(bt_tx_prio, mvm->debugfs_dir, S_IWUSR);
1674 MVM_DEBUGFS_ADD_FILE(bt_force_ant, mvm->debugfs_dir, S_IWUSR);
1675 MVM_DEBUGFS_ADD_FILE(scan_ant_rxchain, mvm->debugfs_dir,
1676 S_IWUSR | S_IRUSR);
1677 MVM_DEBUGFS_ADD_FILE(prph_reg, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
1678 MVM_DEBUGFS_ADD_FILE(d0i3_refs, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1679 MVM_DEBUGFS_ADD_FILE(fw_dbg_conf, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1680 MVM_DEBUGFS_ADD_FILE(fw_dbg_collect, mvm->debugfs_dir, S_IWUSR);
1681 MVM_DEBUGFS_ADD_FILE(max_amsdu_len, mvm->debugfs_dir, S_IWUSR);
1682 MVM_DEBUGFS_ADD_FILE(send_echo_cmd, mvm->debugfs_dir, S_IWUSR);
1683 MVM_DEBUGFS_ADD_FILE(cont_recording, mvm->debugfs_dir, S_IWUSR);
1684 MVM_DEBUGFS_ADD_FILE(indirection_tbl, mvm->debugfs_dir, S_IWUSR);
1685 MVM_DEBUGFS_ADD_FILE(inject_packet, mvm->debugfs_dir, S_IWUSR);
1686 if (!debugfs_create_bool("enable_scan_iteration_notif",
1687 S_IRUSR | S_IWUSR,
1688 mvm->debugfs_dir,
1689 &mvm->scan_iter_notif_enabled))
1690 goto err;
1691 if (!debugfs_create_bool("drop_bcn_ap_mode", S_IRUSR | S_IWUSR,
1692 mvm->debugfs_dir, &mvm->drop_bcn_ap_mode))
1693 goto err;
1694
1695#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1696 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING) {
1697 bcast_dir = debugfs_create_dir("bcast_filtering",
1698 mvm->debugfs_dir);
1699 if (!bcast_dir)
1700 goto err;
1701
1702 if (!debugfs_create_bool("override", S_IRUSR | S_IWUSR,
1703 bcast_dir,
1704 &mvm->dbgfs_bcast_filtering.override))
1705 goto err;
1706
1707 MVM_DEBUGFS_ADD_FILE_ALIAS("filters", bcast_filters,
1708 bcast_dir, S_IWUSR | S_IRUSR);
1709 MVM_DEBUGFS_ADD_FILE_ALIAS("macs", bcast_filters_macs,
1710 bcast_dir, S_IWUSR | S_IRUSR);
1711 }
1712#endif
1713
1714#ifdef CONFIG_PM_SLEEP
1715 MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR);
1716 MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR);
1717 if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR,
1718 mvm->debugfs_dir, &mvm->d3_wake_sysassert))
1719 goto err;
1720 if (!debugfs_create_u32("last_netdetect_scans", S_IRUSR,
1721 mvm->debugfs_dir, &mvm->last_netdetect_scans))
1722 goto err;
1723#endif
1724
1725 if (!debugfs_create_u8("ps_disabled", S_IRUSR,
1726 mvm->debugfs_dir, &mvm->ps_disabled))
1727 goto err;
1728 if (!debugfs_create_blob("nvm_hw", S_IRUSR,
1729 mvm->debugfs_dir, &mvm->nvm_hw_blob))
1730 goto err;
1731 if (!debugfs_create_blob("nvm_sw", S_IRUSR,
1732 mvm->debugfs_dir, &mvm->nvm_sw_blob))
1733 goto err;
1734 if (!debugfs_create_blob("nvm_calib", S_IRUSR,
1735 mvm->debugfs_dir, &mvm->nvm_calib_blob))
1736 goto err;
1737 if (!debugfs_create_blob("nvm_prod", S_IRUSR,
1738 mvm->debugfs_dir, &mvm->nvm_prod_blob))
1739 goto err;
1740 if (!debugfs_create_blob("nvm_phy_sku", S_IRUSR,
1741 mvm->debugfs_dir, &mvm->nvm_phy_sku_blob))
1742 goto err;
1743
1744 debugfs_create_file("mem", S_IRUSR | S_IWUSR, dbgfs_dir, mvm,
1745 &iwl_dbgfs_mem_ops);
1746
1747 /*
1748 * Create a symlink with mac80211. It will be removed when mac80211
1749 * exists (before the opmode exists which removes the target.)
1750 */
1751 snprintf(buf, 100, "../../%pd2", dbgfs_dir->d_parent);
1752 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
1753 goto err;
1754
1755 return 0;
1756err:
1757 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
1758 return -ENOMEM;
1759}