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