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