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 | * | |
8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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 | * | |
33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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 | *****************************************************************************/ | |
63 | #include "mvm.h" | |
64 | #include "sta.h" | |
65 | #include "iwl-io.h" | |
66 | ||
67 | struct iwl_dbgfs_mvm_ctx { | |
68 | struct iwl_mvm *mvm; | |
69 | struct ieee80211_vif *vif; | |
70 | }; | |
71 | ||
8ca151b5 JB |
72 | static ssize_t iwl_dbgfs_tx_flush_write(struct file *file, |
73 | const char __user *user_buf, | |
74 | size_t count, loff_t *ppos) | |
75 | { | |
76 | struct iwl_mvm *mvm = file->private_data; | |
77 | ||
78 | char buf[16]; | |
79 | int buf_size, ret; | |
80 | u32 scd_q_msk; | |
81 | ||
82 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) | |
83 | return -EIO; | |
84 | ||
85 | memset(buf, 0, sizeof(buf)); | |
86 | buf_size = min(count, sizeof(buf) - 1); | |
87 | if (copy_from_user(buf, user_buf, buf_size)) | |
88 | return -EFAULT; | |
89 | ||
90 | if (sscanf(buf, "%x", &scd_q_msk) != 1) | |
91 | return -EINVAL; | |
92 | ||
93 | IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk); | |
94 | ||
95 | mutex_lock(&mvm->mutex); | |
96 | ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count; | |
97 | mutex_unlock(&mvm->mutex); | |
98 | ||
99 | return ret; | |
100 | } | |
101 | ||
102 | static ssize_t iwl_dbgfs_sta_drain_write(struct file *file, | |
103 | const char __user *user_buf, | |
104 | size_t count, loff_t *ppos) | |
105 | { | |
106 | struct iwl_mvm *mvm = file->private_data; | |
107 | struct ieee80211_sta *sta; | |
108 | ||
109 | char buf[8]; | |
110 | int buf_size, sta_id, drain, ret; | |
111 | ||
112 | if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR) | |
113 | return -EIO; | |
114 | ||
115 | memset(buf, 0, sizeof(buf)); | |
116 | buf_size = min(count, sizeof(buf) - 1); | |
117 | if (copy_from_user(buf, user_buf, buf_size)) | |
118 | return -EFAULT; | |
119 | ||
120 | if (sscanf(buf, "%d %d", &sta_id, &drain) != 2) | |
121 | return -EINVAL; | |
122 | ||
123 | mutex_lock(&mvm->mutex); | |
124 | ||
125 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
126 | lockdep_is_held(&mvm->mutex)); | |
127 | if (IS_ERR_OR_NULL(sta)) | |
128 | ret = -ENOENT; | |
129 | else | |
130 | ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? : | |
131 | count; | |
132 | ||
133 | mutex_unlock(&mvm->mutex); | |
134 | ||
135 | return ret; | |
136 | } | |
137 | ||
138 | static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf, | |
139 | size_t count, loff_t *ppos) | |
140 | { | |
141 | struct iwl_mvm *mvm = file->private_data; | |
142 | const struct fw_img *img; | |
143 | int ofs, len, pos = 0; | |
144 | size_t bufsz, ret; | |
145 | char *buf; | |
146 | u8 *ptr; | |
147 | ||
60191d99 JB |
148 | if (!mvm->ucode_loaded) |
149 | return -EINVAL; | |
150 | ||
8ca151b5 JB |
151 | /* default is to dump the entire data segment */ |
152 | if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) { | |
8ca151b5 | 153 | img = &mvm->fw->img[mvm->cur_ucode]; |
60191d99 JB |
154 | ofs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
155 | len = img->sec[IWL_UCODE_SECTION_DATA].len; | |
156 | } else { | |
157 | ofs = mvm->dbgfs_sram_offset; | |
158 | len = mvm->dbgfs_sram_len; | |
8ca151b5 | 159 | } |
8ca151b5 JB |
160 | |
161 | bufsz = len * 4 + 256; | |
162 | buf = kzalloc(bufsz, GFP_KERNEL); | |
163 | if (!buf) | |
164 | return -ENOMEM; | |
165 | ||
166 | ptr = kzalloc(len, GFP_KERNEL); | |
167 | if (!ptr) { | |
168 | kfree(buf); | |
169 | return -ENOMEM; | |
170 | } | |
171 | ||
172 | pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len); | |
60191d99 | 173 | pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", ofs); |
8ca151b5 | 174 | |
60191d99 | 175 | iwl_trans_read_mem_bytes(mvm->trans, ofs, ptr, len); |
8ca151b5 JB |
176 | for (ofs = 0; ofs < len; ofs += 16) { |
177 | pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs); | |
178 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, | |
179 | bufsz - pos, false); | |
180 | pos += strlen(buf + pos); | |
181 | if (bufsz - pos > 0) | |
182 | buf[pos++] = '\n'; | |
183 | } | |
184 | ||
185 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
186 | ||
187 | kfree(buf); | |
188 | kfree(ptr); | |
189 | ||
190 | return ret; | |
191 | } | |
192 | ||
193 | static ssize_t iwl_dbgfs_sram_write(struct file *file, | |
194 | const char __user *user_buf, size_t count, | |
195 | loff_t *ppos) | |
196 | { | |
197 | struct iwl_mvm *mvm = file->private_data; | |
198 | char buf[64]; | |
199 | int buf_size; | |
200 | u32 offset, len; | |
201 | ||
202 | memset(buf, 0, sizeof(buf)); | |
203 | buf_size = min(count, sizeof(buf) - 1); | |
204 | if (copy_from_user(buf, user_buf, buf_size)) | |
205 | return -EFAULT; | |
206 | ||
207 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { | |
208 | if ((offset & 0x3) || (len & 0x3)) | |
209 | return -EINVAL; | |
210 | mvm->dbgfs_sram_offset = offset; | |
211 | mvm->dbgfs_sram_len = len; | |
212 | } else { | |
213 | mvm->dbgfs_sram_offset = 0; | |
214 | mvm->dbgfs_sram_len = 0; | |
215 | } | |
216 | ||
217 | return count; | |
218 | } | |
219 | ||
220 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, | |
221 | size_t count, loff_t *ppos) | |
222 | { | |
223 | struct iwl_mvm *mvm = file->private_data; | |
224 | struct ieee80211_sta *sta; | |
225 | char buf[400]; | |
226 | int i, pos = 0, bufsz = sizeof(buf); | |
227 | ||
228 | mutex_lock(&mvm->mutex); | |
229 | ||
230 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { | |
231 | pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); | |
232 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], | |
233 | lockdep_is_held(&mvm->mutex)); | |
234 | if (!sta) | |
235 | pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); | |
236 | else if (IS_ERR(sta)) | |
237 | pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", | |
238 | PTR_ERR(sta)); | |
239 | else | |
240 | pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", | |
241 | sta->addr); | |
242 | } | |
243 | ||
244 | mutex_unlock(&mvm->mutex); | |
245 | ||
246 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
247 | } | |
248 | ||
249 | static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file, | |
250 | const char __user *user_buf, | |
251 | size_t count, loff_t *ppos) | |
252 | { | |
253 | struct iwl_mvm *mvm = file->private_data; | |
254 | char buf[8] = {}; | |
255 | int allow; | |
256 | ||
257 | if (!mvm->ucode_loaded) | |
258 | return -EIO; | |
259 | ||
260 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
261 | return -EFAULT; | |
262 | ||
263 | if (sscanf(buf, "%d", &allow) != 1) | |
264 | return -EINVAL; | |
265 | ||
266 | IWL_DEBUG_POWER(mvm, "%s device power down\n", | |
267 | allow ? "allow" : "prevent"); | |
268 | ||
269 | /* | |
270 | * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it | |
271 | */ | |
272 | ||
273 | return count; | |
274 | } | |
275 | ||
276 | static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file, | |
277 | const char __user *user_buf, | |
278 | size_t count, loff_t *ppos) | |
279 | { | |
280 | struct iwl_mvm *mvm = file->private_data; | |
281 | char buf[8] = {}; | |
282 | int allow; | |
283 | ||
284 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
285 | return -EFAULT; | |
286 | ||
287 | if (sscanf(buf, "%d", &allow) != 1) | |
288 | return -EINVAL; | |
289 | ||
290 | IWL_DEBUG_POWER(mvm, "%s device power down in d3\n", | |
291 | allow ? "allow" : "prevent"); | |
292 | ||
293 | /* | |
294 | * TODO: When WoWLAN FW alive notification happens, driver will send | |
295 | * REPLY_DEBUG_CMD setting power_down_allow flag according to | |
296 | * mvm->prevent_power_down_d3 | |
297 | */ | |
298 | mvm->prevent_power_down_d3 = !allow; | |
299 | ||
300 | return count; | |
301 | } | |
302 | ||
b571a697 AB |
303 | static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm, |
304 | struct ieee80211_vif *vif, | |
305 | enum iwl_dbgfs_pm_mask param, int val) | |
306 | { | |
307 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
308 | struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm; | |
309 | ||
310 | dbgfs_pm->mask |= param; | |
311 | ||
312 | switch (param) { | |
313 | case MVM_DEBUGFS_PM_KEEP_ALIVE: { | |
314 | struct ieee80211_hw *hw = mvm->hw; | |
315 | int dtimper = hw->conf.ps_dtim_period ?: 1; | |
316 | int dtimper_msec = dtimper * vif->bss_conf.beacon_int; | |
317 | ||
318 | IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val); | |
319 | if (val * MSEC_PER_SEC < 3 * dtimper_msec) { | |
320 | IWL_WARN(mvm, | |
321 | "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n", | |
322 | val * MSEC_PER_SEC, 3 * dtimper_msec); | |
323 | } | |
324 | dbgfs_pm->keep_alive_seconds = val; | |
325 | break; | |
326 | } | |
327 | case MVM_DEBUGFS_PM_SKIP_OVER_DTIM: | |
328 | IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n", | |
329 | val ? "enabled" : "disabled"); | |
330 | dbgfs_pm->skip_over_dtim = val; | |
331 | break; | |
332 | case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS: | |
333 | IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val); | |
334 | dbgfs_pm->skip_dtim_periods = val; | |
335 | break; | |
336 | case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT: | |
337 | IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val); | |
338 | dbgfs_pm->rx_data_timeout = val; | |
339 | break; | |
340 | case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT: | |
341 | IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val); | |
342 | dbgfs_pm->tx_data_timeout = val; | |
343 | break; | |
344 | case MVM_DEBUGFS_PM_DISABLE_POWER_OFF: | |
345 | IWL_DEBUG_POWER(mvm, "disable_power_off=%d\n", val); | |
346 | dbgfs_pm->disable_power_off = val; | |
bd4ace2a AB |
347 | case MVM_DEBUGFS_PM_LPRX_ENA: |
348 | IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled"); | |
349 | dbgfs_pm->lprx_ena = val; | |
350 | break; | |
351 | case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD: | |
352 | IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val); | |
353 | dbgfs_pm->lprx_rssi_threshold = val; | |
b571a697 AB |
354 | break; |
355 | } | |
356 | } | |
357 | ||
358 | static ssize_t iwl_dbgfs_pm_params_write(struct file *file, | |
359 | const char __user *user_buf, | |
360 | size_t count, loff_t *ppos) | |
361 | { | |
362 | struct ieee80211_vif *vif = file->private_data; | |
363 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
364 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; | |
365 | enum iwl_dbgfs_pm_mask param; | |
366 | char buf[32] = {}; | |
367 | int val; | |
368 | int ret; | |
369 | ||
370 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
371 | return -EFAULT; | |
372 | ||
373 | if (!strncmp("keep_alive=", buf, 11)) { | |
374 | if (sscanf(buf + 11, "%d", &val) != 1) | |
375 | return -EINVAL; | |
376 | param = MVM_DEBUGFS_PM_KEEP_ALIVE; | |
377 | } else if (!strncmp("skip_over_dtim=", buf, 15)) { | |
378 | if (sscanf(buf + 15, "%d", &val) != 1) | |
379 | return -EINVAL; | |
380 | param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM; | |
381 | } else if (!strncmp("skip_dtim_periods=", buf, 18)) { | |
382 | if (sscanf(buf + 18, "%d", &val) != 1) | |
383 | return -EINVAL; | |
384 | param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS; | |
385 | } else if (!strncmp("rx_data_timeout=", buf, 16)) { | |
386 | if (sscanf(buf + 16, "%d", &val) != 1) | |
387 | return -EINVAL; | |
388 | param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT; | |
389 | } else if (!strncmp("tx_data_timeout=", buf, 16)) { | |
390 | if (sscanf(buf + 16, "%d", &val) != 1) | |
391 | return -EINVAL; | |
392 | param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT; | |
393 | } else if (!strncmp("disable_power_off=", buf, 18)) { | |
394 | if (sscanf(buf + 18, "%d", &val) != 1) | |
395 | return -EINVAL; | |
396 | param = MVM_DEBUGFS_PM_DISABLE_POWER_OFF; | |
bd4ace2a AB |
397 | } else if (!strncmp("lprx=", buf, 5)) { |
398 | if (sscanf(buf + 5, "%d", &val) != 1) | |
399 | return -EINVAL; | |
400 | param = MVM_DEBUGFS_PM_LPRX_ENA; | |
401 | } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) { | |
402 | if (sscanf(buf + 20, "%d", &val) != 1) | |
403 | return -EINVAL; | |
404 | if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val < | |
405 | POWER_LPRX_RSSI_THRESHOLD_MIN) | |
406 | return -EINVAL; | |
407 | param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD; | |
b571a697 AB |
408 | } else { |
409 | return -EINVAL; | |
410 | } | |
411 | ||
412 | mutex_lock(&mvm->mutex); | |
413 | iwl_dbgfs_update_pm(mvm, vif, param, val); | |
414 | ret = iwl_mvm_power_update_mode(mvm, vif); | |
415 | mutex_unlock(&mvm->mutex); | |
416 | ||
417 | return ret ?: count; | |
418 | } | |
419 | ||
420 | static ssize_t iwl_dbgfs_pm_params_read(struct file *file, | |
421 | char __user *user_buf, | |
422 | size_t count, loff_t *ppos) | |
423 | { | |
424 | struct ieee80211_vif *vif = file->private_data; | |
425 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
426 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; | |
b571a697 AB |
427 | char buf[256]; |
428 | int bufsz = sizeof(buf); | |
e811ada7 | 429 | int pos; |
b571a697 | 430 | |
e811ada7 | 431 | pos = iwl_mvm_power_dbgfs_read(mvm, vif, buf, bufsz); |
b571a697 AB |
432 | |
433 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
434 | } | |
435 | ||
63494374 JB |
436 | static ssize_t iwl_dbgfs_mac_params_read(struct file *file, |
437 | char __user *user_buf, | |
438 | size_t count, loff_t *ppos) | |
439 | { | |
440 | struct ieee80211_vif *vif = file->private_data; | |
441 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
442 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; | |
443 | u8 ap_sta_id; | |
444 | struct ieee80211_chanctx_conf *chanctx_conf; | |
445 | char buf[512]; | |
446 | int bufsz = sizeof(buf); | |
447 | int pos = 0; | |
448 | int i; | |
449 | ||
450 | mutex_lock(&mvm->mutex); | |
451 | ||
452 | ap_sta_id = mvmvif->ap_sta_id; | |
453 | ||
454 | pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n", | |
455 | mvmvif->id, mvmvif->color); | |
456 | pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n", | |
457 | vif->bss_conf.bssid); | |
458 | pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n"); | |
459 | for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) { | |
460 | pos += scnprintf(buf+pos, bufsz-pos, | |
461 | "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n", | |
462 | i, mvmvif->queue_params[i].txop, | |
463 | mvmvif->queue_params[i].cw_min, | |
464 | mvmvif->queue_params[i].cw_max, | |
465 | mvmvif->queue_params[i].aifs, | |
466 | mvmvif->queue_params[i].uapsd); | |
467 | } | |
468 | ||
2b76ef13 EG |
469 | if (vif->type == NL80211_IFTYPE_STATION && |
470 | ap_sta_id != IWL_MVM_STATION_COUNT) { | |
471 | struct ieee80211_sta *sta; | |
472 | struct iwl_mvm_sta *mvm_sta; | |
473 | ||
474 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id], | |
475 | lockdep_is_held(&mvm->mutex)); | |
476 | mvm_sta = (void *)sta->drv_priv; | |
477 | pos += scnprintf(buf+pos, bufsz-pos, | |
478 | "ap_sta_id %d - reduced Tx power %d\n", | |
479 | ap_sta_id, mvm_sta->bt_reduced_txpower); | |
480 | } | |
63494374 JB |
481 | |
482 | rcu_read_lock(); | |
483 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
484 | if (chanctx_conf) { | |
485 | pos += scnprintf(buf+pos, bufsz-pos, | |
486 | "idle rx chains %d, active rx chains: %d\n", | |
487 | chanctx_conf->rx_chains_static, | |
488 | chanctx_conf->rx_chains_dynamic); | |
489 | } | |
490 | rcu_read_unlock(); | |
491 | ||
492 | mutex_unlock(&mvm->mutex); | |
493 | ||
494 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
495 | } | |
496 | ||
10942342 EG |
497 | #define BT_MBOX_MSG(_notif, _num, _field) \ |
498 | ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\ | |
499 | >> BT_MBOX##_num##_##_field##_POS) | |
500 | ||
501 | ||
502 | #define BT_MBOX_PRINT(_num, _field, _end) \ | |
503 | pos += scnprintf(buf + pos, bufsz - pos, \ | |
504 | "\t%s: %d%s", \ | |
505 | #_field, \ | |
506 | BT_MBOX_MSG(notif, _num, _field), \ | |
507 | true ? "\n" : ", "); | |
508 | ||
509 | static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, | |
510 | size_t count, loff_t *ppos) | |
511 | { | |
512 | struct iwl_mvm *mvm = file->private_data; | |
513 | struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; | |
514 | char *buf; | |
515 | int ret, pos = 0, bufsz = sizeof(char) * 1024; | |
516 | ||
517 | buf = kmalloc(bufsz, GFP_KERNEL); | |
518 | if (!buf) | |
519 | return -ENOMEM; | |
520 | ||
521 | mutex_lock(&mvm->mutex); | |
522 | ||
523 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); | |
524 | ||
525 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); | |
526 | BT_MBOX_PRINT(0, LE_PROF1, false); | |
527 | BT_MBOX_PRINT(0, LE_PROF2, false); | |
528 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); | |
529 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); | |
530 | BT_MBOX_PRINT(0, INBAND_S, false); | |
531 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); | |
532 | BT_MBOX_PRINT(0, LE_SCAN, false); | |
533 | BT_MBOX_PRINT(0, LE_ADV, false); | |
534 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); | |
535 | BT_MBOX_PRINT(0, OPEN_CON_1, true); | |
536 | ||
537 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); | |
538 | ||
539 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); | |
540 | BT_MBOX_PRINT(1, IP_SR, false); | |
541 | BT_MBOX_PRINT(1, LE_MSTR, false); | |
542 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); | |
543 | BT_MBOX_PRINT(1, MSG_TYPE, false); | |
544 | BT_MBOX_PRINT(1, SSN, true); | |
545 | ||
546 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); | |
547 | ||
548 | BT_MBOX_PRINT(2, SNIFF_ACT, false); | |
549 | BT_MBOX_PRINT(2, PAG, false); | |
550 | BT_MBOX_PRINT(2, INQUIRY, false); | |
551 | BT_MBOX_PRINT(2, CONN, false); | |
552 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); | |
553 | BT_MBOX_PRINT(2, DISC, false); | |
554 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); | |
555 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); | |
556 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); | |
557 | BT_MBOX_PRINT(2, SCO_DURATION, true); | |
558 | ||
559 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); | |
560 | ||
561 | BT_MBOX_PRINT(3, SCO_STATE, false); | |
562 | BT_MBOX_PRINT(3, SNIFF_STATE, false); | |
563 | BT_MBOX_PRINT(3, A2DP_STATE, false); | |
564 | BT_MBOX_PRINT(3, ACL_STATE, false); | |
565 | BT_MBOX_PRINT(3, MSTR_STATE, false); | |
566 | BT_MBOX_PRINT(3, OBX_STATE, false); | |
567 | BT_MBOX_PRINT(3, OPEN_CON_2, false); | |
568 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); | |
569 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); | |
570 | BT_MBOX_PRINT(3, INBAND_P, false); | |
571 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); | |
572 | BT_MBOX_PRINT(3, SSN_2, false); | |
573 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); | |
574 | ||
575 | pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n", | |
576 | notif->bt_status); | |
577 | pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n", | |
578 | notif->bt_open_conn); | |
579 | pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n", | |
580 | notif->bt_traffic_load); | |
581 | pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n", | |
582 | notif->bt_agg_traffic_load); | |
583 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", | |
584 | notif->bt_ci_compliance); | |
585 | ||
586 | mutex_unlock(&mvm->mutex); | |
587 | ||
588 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
589 | kfree(buf); | |
590 | ||
591 | return ret; | |
592 | } | |
593 | #undef BT_MBOX_PRINT | |
594 | ||
490953ac EG |
595 | static ssize_t iwl_dbgfs_fw_restart_write(struct file *file, |
596 | const char __user *user_buf, | |
597 | size_t count, loff_t *ppos) | |
598 | { | |
599 | struct iwl_mvm *mvm = file->private_data; | |
490953ac EG |
600 | int ret; |
601 | ||
490953ac EG |
602 | mutex_lock(&mvm->mutex); |
603 | ||
291aa7c4 EH |
604 | /* allow one more restart that we're provoking here */ |
605 | if (mvm->restart_fw >= 0) | |
606 | mvm->restart_fw++; | |
607 | ||
490953ac EG |
608 | /* take the return value to make compiler happy - it will fail anyway */ |
609 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL); | |
610 | ||
611 | mutex_unlock(&mvm->mutex); | |
612 | ||
490953ac EG |
613 | return count; |
614 | } | |
615 | ||
b571a697 AB |
616 | static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif, |
617 | enum iwl_dbgfs_bf_mask param, int value) | |
618 | { | |
619 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
620 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; | |
621 | ||
622 | dbgfs_bf->mask |= param; | |
623 | ||
624 | switch (param) { | |
625 | case MVM_DEBUGFS_BF_ENERGY_DELTA: | |
626 | dbgfs_bf->bf_energy_delta = value; | |
627 | break; | |
628 | case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA: | |
629 | dbgfs_bf->bf_roaming_energy_delta = value; | |
630 | break; | |
631 | case MVM_DEBUGFS_BF_ROAMING_STATE: | |
632 | dbgfs_bf->bf_roaming_state = value; | |
633 | break; | |
5dca7c24 HG |
634 | case MVM_DEBUGFS_BF_TEMP_THRESHOLD: |
635 | dbgfs_bf->bf_temp_threshold = value; | |
636 | break; | |
637 | case MVM_DEBUGFS_BF_TEMP_FAST_FILTER: | |
638 | dbgfs_bf->bf_temp_fast_filter = value; | |
639 | break; | |
640 | case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER: | |
641 | dbgfs_bf->bf_temp_slow_filter = value; | |
b571a697 AB |
642 | break; |
643 | case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER: | |
644 | dbgfs_bf->bf_enable_beacon_filter = value; | |
645 | break; | |
646 | case MVM_DEBUGFS_BF_DEBUG_FLAG: | |
647 | dbgfs_bf->bf_debug_flag = value; | |
648 | break; | |
649 | case MVM_DEBUGFS_BF_ESCAPE_TIMER: | |
650 | dbgfs_bf->bf_escape_timer = value; | |
651 | break; | |
652 | case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT: | |
653 | dbgfs_bf->ba_enable_beacon_abort = value; | |
654 | break; | |
655 | case MVM_DEBUGFS_BA_ESCAPE_TIMER: | |
656 | dbgfs_bf->ba_escape_timer = value; | |
657 | break; | |
658 | } | |
659 | } | |
660 | ||
661 | static ssize_t iwl_dbgfs_bf_params_write(struct file *file, | |
662 | const char __user *user_buf, | |
663 | size_t count, loff_t *ppos) | |
664 | { | |
665 | struct ieee80211_vif *vif = file->private_data; | |
666 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
667 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; | |
668 | enum iwl_dbgfs_bf_mask param; | |
669 | char buf[256]; | |
670 | int buf_size; | |
671 | int value; | |
672 | int ret = 0; | |
673 | ||
674 | memset(buf, 0, sizeof(buf)); | |
675 | buf_size = min(count, sizeof(buf) - 1); | |
676 | if (copy_from_user(buf, user_buf, buf_size)) | |
677 | return -EFAULT; | |
678 | ||
679 | if (!strncmp("bf_energy_delta=", buf, 16)) { | |
680 | if (sscanf(buf+16, "%d", &value) != 1) | |
681 | return -EINVAL; | |
682 | if (value < IWL_BF_ENERGY_DELTA_MIN || | |
683 | value > IWL_BF_ENERGY_DELTA_MAX) | |
684 | return -EINVAL; | |
685 | param = MVM_DEBUGFS_BF_ENERGY_DELTA; | |
686 | } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) { | |
687 | if (sscanf(buf+24, "%d", &value) != 1) | |
688 | return -EINVAL; | |
689 | if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN || | |
690 | value > IWL_BF_ROAMING_ENERGY_DELTA_MAX) | |
691 | return -EINVAL; | |
692 | param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA; | |
693 | } else if (!strncmp("bf_roaming_state=", buf, 17)) { | |
694 | if (sscanf(buf+17, "%d", &value) != 1) | |
695 | return -EINVAL; | |
696 | if (value < IWL_BF_ROAMING_STATE_MIN || | |
697 | value > IWL_BF_ROAMING_STATE_MAX) | |
698 | return -EINVAL; | |
699 | param = MVM_DEBUGFS_BF_ROAMING_STATE; | |
5dca7c24 HG |
700 | } else if (!strncmp("bf_temp_threshold=", buf, 18)) { |
701 | if (sscanf(buf+18, "%d", &value) != 1) | |
702 | return -EINVAL; | |
703 | if (value < IWL_BF_TEMP_THRESHOLD_MIN || | |
704 | value > IWL_BF_TEMP_THRESHOLD_MAX) | |
705 | return -EINVAL; | |
706 | param = MVM_DEBUGFS_BF_TEMP_THRESHOLD; | |
707 | } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) { | |
708 | if (sscanf(buf+20, "%d", &value) != 1) | |
709 | return -EINVAL; | |
710 | if (value < IWL_BF_TEMP_FAST_FILTER_MIN || | |
711 | value > IWL_BF_TEMP_FAST_FILTER_MAX) | |
712 | return -EINVAL; | |
713 | param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER; | |
714 | } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) { | |
715 | if (sscanf(buf+20, "%d", &value) != 1) | |
b571a697 | 716 | return -EINVAL; |
5dca7c24 HG |
717 | if (value < IWL_BF_TEMP_SLOW_FILTER_MIN || |
718 | value > IWL_BF_TEMP_SLOW_FILTER_MAX) | |
b571a697 | 719 | return -EINVAL; |
5dca7c24 | 720 | param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER; |
b571a697 AB |
721 | } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) { |
722 | if (sscanf(buf+24, "%d", &value) != 1) | |
723 | return -EINVAL; | |
724 | if (value < 0 || value > 1) | |
725 | return -EINVAL; | |
726 | param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER; | |
727 | } else if (!strncmp("bf_debug_flag=", buf, 14)) { | |
728 | if (sscanf(buf+14, "%d", &value) != 1) | |
729 | return -EINVAL; | |
730 | if (value < 0 || value > 1) | |
731 | return -EINVAL; | |
732 | param = MVM_DEBUGFS_BF_DEBUG_FLAG; | |
733 | } else if (!strncmp("bf_escape_timer=", buf, 16)) { | |
734 | if (sscanf(buf+16, "%d", &value) != 1) | |
735 | return -EINVAL; | |
736 | if (value < IWL_BF_ESCAPE_TIMER_MIN || | |
737 | value > IWL_BF_ESCAPE_TIMER_MAX) | |
738 | return -EINVAL; | |
739 | param = MVM_DEBUGFS_BF_ESCAPE_TIMER; | |
740 | } else if (!strncmp("ba_escape_timer=", buf, 16)) { | |
741 | if (sscanf(buf+16, "%d", &value) != 1) | |
742 | return -EINVAL; | |
743 | if (value < IWL_BA_ESCAPE_TIMER_MIN || | |
744 | value > IWL_BA_ESCAPE_TIMER_MAX) | |
745 | return -EINVAL; | |
746 | param = MVM_DEBUGFS_BA_ESCAPE_TIMER; | |
747 | } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) { | |
748 | if (sscanf(buf+23, "%d", &value) != 1) | |
749 | return -EINVAL; | |
750 | if (value < 0 || value > 1) | |
751 | return -EINVAL; | |
752 | param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT; | |
753 | } else { | |
754 | return -EINVAL; | |
755 | } | |
756 | ||
757 | mutex_lock(&mvm->mutex); | |
758 | iwl_dbgfs_update_bf(vif, param, value); | |
759 | if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value) { | |
760 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); | |
761 | } else { | |
762 | if (mvmvif->bf_enabled) | |
763 | ret = iwl_mvm_enable_beacon_filter(mvm, vif); | |
764 | else | |
765 | ret = iwl_mvm_disable_beacon_filter(mvm, vif); | |
766 | } | |
767 | mutex_unlock(&mvm->mutex); | |
768 | ||
769 | return ret ?: count; | |
770 | } | |
771 | ||
772 | static ssize_t iwl_dbgfs_bf_params_read(struct file *file, | |
773 | char __user *user_buf, | |
774 | size_t count, loff_t *ppos) | |
775 | { | |
776 | struct ieee80211_vif *vif = file->private_data; | |
777 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
778 | char buf[256]; | |
779 | int pos = 0; | |
780 | const size_t bufsz = sizeof(buf); | |
781 | struct iwl_beacon_filter_cmd cmd = { | |
5dca7c24 HG |
782 | IWL_BF_CMD_CONFIG_DEFAULTS, |
783 | .bf_enable_beacon_filter = | |
784 | cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT), | |
785 | .ba_enable_beacon_abort = | |
786 | cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT), | |
b571a697 AB |
787 | }; |
788 | ||
789 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); | |
790 | if (mvmvif->bf_enabled) | |
5dca7c24 | 791 | cmd.bf_enable_beacon_filter = cpu_to_le32(1); |
b571a697 AB |
792 | else |
793 | cmd.bf_enable_beacon_filter = 0; | |
794 | ||
795 | pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n", | |
5dca7c24 | 796 | le32_to_cpu(cmd.bf_energy_delta)); |
b571a697 | 797 | pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n", |
5dca7c24 | 798 | le32_to_cpu(cmd.bf_roaming_energy_delta)); |
b571a697 | 799 | pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n", |
5dca7c24 HG |
800 | le32_to_cpu(cmd.bf_roaming_state)); |
801 | pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n", | |
802 | le32_to_cpu(cmd.bf_temp_threshold)); | |
803 | pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n", | |
804 | le32_to_cpu(cmd.bf_temp_fast_filter)); | |
805 | pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n", | |
806 | le32_to_cpu(cmd.bf_temp_slow_filter)); | |
b571a697 | 807 | pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n", |
5dca7c24 | 808 | le32_to_cpu(cmd.bf_enable_beacon_filter)); |
b571a697 | 809 | pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n", |
5dca7c24 | 810 | le32_to_cpu(cmd.bf_debug_flag)); |
b571a697 | 811 | pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n", |
5dca7c24 | 812 | le32_to_cpu(cmd.bf_escape_timer)); |
b571a697 | 813 | pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n", |
5dca7c24 | 814 | le32_to_cpu(cmd.ba_escape_timer)); |
b571a697 | 815 | pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n", |
5dca7c24 | 816 | le32_to_cpu(cmd.ba_enable_beacon_abort)); |
b571a697 AB |
817 | |
818 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
819 | } | |
820 | ||
afc66bb7 JB |
821 | #ifdef CONFIG_PM_SLEEP |
822 | static ssize_t iwl_dbgfs_d3_sram_write(struct file *file, | |
823 | const char __user *user_buf, | |
824 | size_t count, loff_t *ppos) | |
825 | { | |
826 | struct iwl_mvm *mvm = file->private_data; | |
827 | char buf[8] = {}; | |
828 | int store; | |
829 | ||
830 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
831 | return -EFAULT; | |
832 | ||
833 | if (sscanf(buf, "%d", &store) != 1) | |
834 | return -EINVAL; | |
835 | ||
836 | mvm->store_d3_resume_sram = store; | |
837 | ||
838 | return count; | |
839 | } | |
840 | ||
841 | static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf, | |
842 | size_t count, loff_t *ppos) | |
843 | { | |
844 | struct iwl_mvm *mvm = file->private_data; | |
845 | const struct fw_img *img; | |
846 | int ofs, len, pos = 0; | |
847 | size_t bufsz, ret; | |
848 | char *buf; | |
849 | u8 *ptr = mvm->d3_resume_sram; | |
850 | ||
851 | img = &mvm->fw->img[IWL_UCODE_WOWLAN]; | |
852 | len = img->sec[IWL_UCODE_SECTION_DATA].len; | |
853 | ||
854 | bufsz = len * 4 + 256; | |
855 | buf = kzalloc(bufsz, GFP_KERNEL); | |
856 | if (!buf) | |
857 | return -ENOMEM; | |
858 | ||
859 | pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n", | |
860 | mvm->store_d3_resume_sram ? "en" : "dis"); | |
861 | ||
862 | if (ptr) { | |
863 | for (ofs = 0; ofs < len; ofs += 16) { | |
864 | pos += scnprintf(buf + pos, bufsz - pos, | |
865 | "0x%.4x ", ofs); | |
866 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, | |
867 | bufsz - pos, false); | |
868 | pos += strlen(buf + pos); | |
869 | if (bufsz - pos > 0) | |
870 | buf[pos++] = '\n'; | |
871 | } | |
872 | } else { | |
873 | pos += scnprintf(buf + pos, bufsz - pos, | |
874 | "(no data captured)\n"); | |
875 | } | |
876 | ||
877 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
878 | ||
879 | kfree(buf); | |
880 | ||
881 | return ret; | |
882 | } | |
883 | #endif | |
884 | ||
8ca151b5 JB |
885 | #define MVM_DEBUGFS_READ_FILE_OPS(name) \ |
886 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
887 | .read = iwl_dbgfs_##name##_read, \ | |
ba5295f8 | 888 | .open = simple_open, \ |
8ca151b5 JB |
889 | .llseek = generic_file_llseek, \ |
890 | } | |
891 | ||
892 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \ | |
893 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
894 | .write = iwl_dbgfs_##name##_write, \ | |
895 | .read = iwl_dbgfs_##name##_read, \ | |
ba5295f8 | 896 | .open = simple_open, \ |
8ca151b5 JB |
897 | .llseek = generic_file_llseek, \ |
898 | }; | |
899 | ||
900 | #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \ | |
901 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
902 | .write = iwl_dbgfs_##name##_write, \ | |
ba5295f8 | 903 | .open = simple_open, \ |
8ca151b5 JB |
904 | .llseek = generic_file_llseek, \ |
905 | }; | |
906 | ||
907 | #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \ | |
908 | if (!debugfs_create_file(#name, mode, parent, mvm, \ | |
909 | &iwl_dbgfs_##name##_ops)) \ | |
910 | goto err; \ | |
911 | } while (0) | |
912 | ||
913 | #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \ | |
914 | if (!debugfs_create_file(#name, mode, parent, vif, \ | |
915 | &iwl_dbgfs_##name##_ops)) \ | |
916 | goto err; \ | |
917 | } while (0) | |
918 | ||
919 | /* Device wide debugfs entries */ | |
920 | MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush); | |
921 | MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain); | |
922 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram); | |
923 | MVM_DEBUGFS_READ_FILE_OPS(stations); | |
10942342 | 924 | MVM_DEBUGFS_READ_FILE_OPS(bt_notif); |
8ca151b5 JB |
925 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow); |
926 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow); | |
490953ac | 927 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart); |
afc66bb7 JB |
928 | #ifdef CONFIG_PM_SLEEP |
929 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram); | |
930 | #endif | |
8ca151b5 | 931 | |
63494374 JB |
932 | /* Interface specific debugfs entries */ |
933 | MVM_DEBUGFS_READ_FILE_OPS(mac_params); | |
b571a697 AB |
934 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params); |
935 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params); | |
63494374 | 936 | |
8ca151b5 JB |
937 | int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) |
938 | { | |
939 | char buf[100]; | |
940 | ||
941 | mvm->debugfs_dir = dbgfs_dir; | |
942 | ||
943 | MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR); | |
944 | MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR); | |
945 | MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR); | |
946 | MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); | |
10942342 | 947 | MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); |
8ca151b5 JB |
948 | MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR); |
949 | MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR); | |
490953ac | 950 | MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR); |
afc66bb7 JB |
951 | #ifdef CONFIG_PM_SLEEP |
952 | MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR); | |
debff618 | 953 | MVM_DEBUGFS_ADD_FILE(d3_test, mvm->debugfs_dir, S_IRUSR); |
b0114714 JB |
954 | if (!debugfs_create_bool("d3_wake_sysassert", S_IRUSR | S_IWUSR, |
955 | mvm->debugfs_dir, &mvm->d3_wake_sysassert)) | |
956 | goto err; | |
afc66bb7 | 957 | #endif |
8ca151b5 JB |
958 | |
959 | /* | |
960 | * Create a symlink with mac80211. It will be removed when mac80211 | |
961 | * exists (before the opmode exists which removes the target.) | |
962 | */ | |
963 | snprintf(buf, 100, "../../%s/%s", | |
964 | dbgfs_dir->d_parent->d_parent->d_name.name, | |
965 | dbgfs_dir->d_parent->d_name.name); | |
966 | if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf)) | |
967 | goto err; | |
968 | ||
969 | return 0; | |
970 | err: | |
971 | IWL_ERR(mvm, "Can't create the mvm debugfs directory\n"); | |
972 | return -ENOMEM; | |
973 | } | |
63494374 JB |
974 | |
975 | void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
976 | { | |
977 | struct dentry *dbgfs_dir = vif->debugfs_dir; | |
978 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
979 | char buf[100]; | |
980 | ||
981 | if (!dbgfs_dir) | |
982 | return; | |
983 | ||
984 | mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir); | |
985 | mvmvif->dbgfs_data = mvm; | |
986 | ||
987 | if (!mvmvif->dbgfs_dir) { | |
988 | IWL_ERR(mvm, "Failed to create debugfs directory under %s\n", | |
989 | dbgfs_dir->d_name.name); | |
990 | return; | |
991 | } | |
992 | ||
b571a697 AB |
993 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM && |
994 | vif->type == NL80211_IFTYPE_STATION && !vif->p2p) | |
995 | MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, S_IWUSR | | |
996 | S_IRUSR); | |
997 | ||
63494374 JB |
998 | MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, |
999 | S_IRUSR); | |
1000 | ||
b571a697 AB |
1001 | if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p && |
1002 | mvmvif == mvm->bf_allowed_vif) | |
1003 | MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, | |
1004 | S_IRUSR | S_IWUSR); | |
1005 | ||
63494374 JB |
1006 | /* |
1007 | * Create symlink for convenience pointing to interface specific | |
1008 | * debugfs entries for the driver. For example, under | |
1009 | * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/ | |
1010 | * find | |
1011 | * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/ | |
1012 | */ | |
1013 | snprintf(buf, 100, "../../../%s/%s/%s/%s", | |
1014 | dbgfs_dir->d_parent->d_parent->d_name.name, | |
1015 | dbgfs_dir->d_parent->d_name.name, | |
1016 | dbgfs_dir->d_name.name, | |
1017 | mvmvif->dbgfs_dir->d_name.name); | |
1018 | ||
1019 | mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name, | |
1020 | mvm->debugfs_dir, buf); | |
1021 | if (!mvmvif->dbgfs_slink) | |
1022 | IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n", | |
1023 | dbgfs_dir->d_name.name); | |
1024 | return; | |
1025 | err: | |
1026 | IWL_ERR(mvm, "Can't create debugfs entity\n"); | |
1027 | } | |
1028 | ||
1029 | void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
1030 | { | |
1031 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1032 | ||
1033 | debugfs_remove(mvmvif->dbgfs_slink); | |
1034 | mvmvif->dbgfs_slink = NULL; | |
1035 | ||
1036 | debugfs_remove_recursive(mvmvif->dbgfs_dir); | |
1037 | mvmvif->dbgfs_dir = NULL; | |
1038 | } |