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 | ||
148 | /* default is to dump the entire data segment */ | |
149 | if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) { | |
8ca151b5 JB |
150 | if (!mvm->ucode_loaded) |
151 | return -EINVAL; | |
152 | img = &mvm->fw->img[mvm->cur_ucode]; | |
ce7f9ab3 JB |
153 | mvm->dbgfs_sram_offset = |
154 | img->sec[IWL_UCODE_SECTION_DATA].offset; | |
8ca151b5 JB |
155 | mvm->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len; |
156 | } | |
157 | len = mvm->dbgfs_sram_len; | |
158 | ||
159 | bufsz = len * 4 + 256; | |
160 | buf = kzalloc(bufsz, GFP_KERNEL); | |
161 | if (!buf) | |
162 | return -ENOMEM; | |
163 | ||
164 | ptr = kzalloc(len, GFP_KERNEL); | |
165 | if (!ptr) { | |
166 | kfree(buf); | |
167 | return -ENOMEM; | |
168 | } | |
169 | ||
170 | pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len); | |
171 | pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n", | |
172 | mvm->dbgfs_sram_offset); | |
173 | ||
174 | iwl_trans_read_mem_bytes(mvm->trans, | |
175 | mvm->dbgfs_sram_offset, | |
176 | ptr, len); | |
177 | for (ofs = 0; ofs < len; ofs += 16) { | |
178 | pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs); | |
179 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, | |
180 | bufsz - pos, false); | |
181 | pos += strlen(buf + pos); | |
182 | if (bufsz - pos > 0) | |
183 | buf[pos++] = '\n'; | |
184 | } | |
185 | ||
186 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
187 | ||
188 | kfree(buf); | |
189 | kfree(ptr); | |
190 | ||
191 | return ret; | |
192 | } | |
193 | ||
194 | static ssize_t iwl_dbgfs_sram_write(struct file *file, | |
195 | const char __user *user_buf, size_t count, | |
196 | loff_t *ppos) | |
197 | { | |
198 | struct iwl_mvm *mvm = file->private_data; | |
199 | char buf[64]; | |
200 | int buf_size; | |
201 | u32 offset, len; | |
202 | ||
203 | memset(buf, 0, sizeof(buf)); | |
204 | buf_size = min(count, sizeof(buf) - 1); | |
205 | if (copy_from_user(buf, user_buf, buf_size)) | |
206 | return -EFAULT; | |
207 | ||
208 | if (sscanf(buf, "%x,%x", &offset, &len) == 2) { | |
209 | if ((offset & 0x3) || (len & 0x3)) | |
210 | return -EINVAL; | |
211 | mvm->dbgfs_sram_offset = offset; | |
212 | mvm->dbgfs_sram_len = len; | |
213 | } else { | |
214 | mvm->dbgfs_sram_offset = 0; | |
215 | mvm->dbgfs_sram_len = 0; | |
216 | } | |
217 | ||
218 | return count; | |
219 | } | |
220 | ||
221 | static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf, | |
222 | size_t count, loff_t *ppos) | |
223 | { | |
224 | struct iwl_mvm *mvm = file->private_data; | |
225 | struct ieee80211_sta *sta; | |
226 | char buf[400]; | |
227 | int i, pos = 0, bufsz = sizeof(buf); | |
228 | ||
229 | mutex_lock(&mvm->mutex); | |
230 | ||
231 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { | |
232 | pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i); | |
233 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], | |
234 | lockdep_is_held(&mvm->mutex)); | |
235 | if (!sta) | |
236 | pos += scnprintf(buf + pos, bufsz - pos, "N/A\n"); | |
237 | else if (IS_ERR(sta)) | |
238 | pos += scnprintf(buf + pos, bufsz - pos, "%ld\n", | |
239 | PTR_ERR(sta)); | |
240 | else | |
241 | pos += scnprintf(buf + pos, bufsz - pos, "%pM\n", | |
242 | sta->addr); | |
243 | } | |
244 | ||
245 | mutex_unlock(&mvm->mutex); | |
246 | ||
247 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
248 | } | |
249 | ||
250 | static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file, | |
251 | const char __user *user_buf, | |
252 | size_t count, loff_t *ppos) | |
253 | { | |
254 | struct iwl_mvm *mvm = file->private_data; | |
255 | char buf[8] = {}; | |
256 | int allow; | |
257 | ||
258 | if (!mvm->ucode_loaded) | |
259 | return -EIO; | |
260 | ||
261 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
262 | return -EFAULT; | |
263 | ||
264 | if (sscanf(buf, "%d", &allow) != 1) | |
265 | return -EINVAL; | |
266 | ||
267 | IWL_DEBUG_POWER(mvm, "%s device power down\n", | |
268 | allow ? "allow" : "prevent"); | |
269 | ||
270 | /* | |
271 | * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it | |
272 | */ | |
273 | ||
274 | return count; | |
275 | } | |
276 | ||
277 | static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file, | |
278 | const char __user *user_buf, | |
279 | size_t count, loff_t *ppos) | |
280 | { | |
281 | struct iwl_mvm *mvm = file->private_data; | |
282 | char buf[8] = {}; | |
283 | int allow; | |
284 | ||
285 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
286 | return -EFAULT; | |
287 | ||
288 | if (sscanf(buf, "%d", &allow) != 1) | |
289 | return -EINVAL; | |
290 | ||
291 | IWL_DEBUG_POWER(mvm, "%s device power down in d3\n", | |
292 | allow ? "allow" : "prevent"); | |
293 | ||
294 | /* | |
295 | * TODO: When WoWLAN FW alive notification happens, driver will send | |
296 | * REPLY_DEBUG_CMD setting power_down_allow flag according to | |
297 | * mvm->prevent_power_down_d3 | |
298 | */ | |
299 | mvm->prevent_power_down_d3 = !allow; | |
300 | ||
301 | return count; | |
302 | } | |
303 | ||
63494374 JB |
304 | static ssize_t iwl_dbgfs_mac_params_read(struct file *file, |
305 | char __user *user_buf, | |
306 | size_t count, loff_t *ppos) | |
307 | { | |
308 | struct ieee80211_vif *vif = file->private_data; | |
309 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
310 | struct iwl_mvm *mvm = mvmvif->dbgfs_data; | |
311 | u8 ap_sta_id; | |
312 | struct ieee80211_chanctx_conf *chanctx_conf; | |
313 | char buf[512]; | |
314 | int bufsz = sizeof(buf); | |
315 | int pos = 0; | |
316 | int i; | |
317 | ||
318 | mutex_lock(&mvm->mutex); | |
319 | ||
320 | ap_sta_id = mvmvif->ap_sta_id; | |
321 | ||
322 | pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n", | |
323 | mvmvif->id, mvmvif->color); | |
324 | pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n", | |
325 | vif->bss_conf.bssid); | |
326 | pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n"); | |
327 | for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) { | |
328 | pos += scnprintf(buf+pos, bufsz-pos, | |
329 | "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n", | |
330 | i, mvmvif->queue_params[i].txop, | |
331 | mvmvif->queue_params[i].cw_min, | |
332 | mvmvif->queue_params[i].cw_max, | |
333 | mvmvif->queue_params[i].aifs, | |
334 | mvmvif->queue_params[i].uapsd); | |
335 | } | |
336 | ||
2b76ef13 EG |
337 | if (vif->type == NL80211_IFTYPE_STATION && |
338 | ap_sta_id != IWL_MVM_STATION_COUNT) { | |
339 | struct ieee80211_sta *sta; | |
340 | struct iwl_mvm_sta *mvm_sta; | |
341 | ||
342 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id], | |
343 | lockdep_is_held(&mvm->mutex)); | |
344 | mvm_sta = (void *)sta->drv_priv; | |
345 | pos += scnprintf(buf+pos, bufsz-pos, | |
346 | "ap_sta_id %d - reduced Tx power %d\n", | |
347 | ap_sta_id, mvm_sta->bt_reduced_txpower); | |
348 | } | |
63494374 JB |
349 | |
350 | rcu_read_lock(); | |
351 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
352 | if (chanctx_conf) { | |
353 | pos += scnprintf(buf+pos, bufsz-pos, | |
354 | "idle rx chains %d, active rx chains: %d\n", | |
355 | chanctx_conf->rx_chains_static, | |
356 | chanctx_conf->rx_chains_dynamic); | |
357 | } | |
358 | rcu_read_unlock(); | |
359 | ||
360 | mutex_unlock(&mvm->mutex); | |
361 | ||
362 | return simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
363 | } | |
364 | ||
10942342 EG |
365 | #define BT_MBOX_MSG(_notif, _num, _field) \ |
366 | ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\ | |
367 | >> BT_MBOX##_num##_##_field##_POS) | |
368 | ||
369 | ||
370 | #define BT_MBOX_PRINT(_num, _field, _end) \ | |
371 | pos += scnprintf(buf + pos, bufsz - pos, \ | |
372 | "\t%s: %d%s", \ | |
373 | #_field, \ | |
374 | BT_MBOX_MSG(notif, _num, _field), \ | |
375 | true ? "\n" : ", "); | |
376 | ||
377 | static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf, | |
378 | size_t count, loff_t *ppos) | |
379 | { | |
380 | struct iwl_mvm *mvm = file->private_data; | |
381 | struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif; | |
382 | char *buf; | |
383 | int ret, pos = 0, bufsz = sizeof(char) * 1024; | |
384 | ||
385 | buf = kmalloc(bufsz, GFP_KERNEL); | |
386 | if (!buf) | |
387 | return -ENOMEM; | |
388 | ||
389 | mutex_lock(&mvm->mutex); | |
390 | ||
391 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n"); | |
392 | ||
393 | BT_MBOX_PRINT(0, LE_SLAVE_LAT, false); | |
394 | BT_MBOX_PRINT(0, LE_PROF1, false); | |
395 | BT_MBOX_PRINT(0, LE_PROF2, false); | |
396 | BT_MBOX_PRINT(0, LE_PROF_OTHER, false); | |
397 | BT_MBOX_PRINT(0, CHL_SEQ_N, false); | |
398 | BT_MBOX_PRINT(0, INBAND_S, false); | |
399 | BT_MBOX_PRINT(0, LE_MIN_RSSI, false); | |
400 | BT_MBOX_PRINT(0, LE_SCAN, false); | |
401 | BT_MBOX_PRINT(0, LE_ADV, false); | |
402 | BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false); | |
403 | BT_MBOX_PRINT(0, OPEN_CON_1, true); | |
404 | ||
405 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n"); | |
406 | ||
407 | BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false); | |
408 | BT_MBOX_PRINT(1, IP_SR, false); | |
409 | BT_MBOX_PRINT(1, LE_MSTR, false); | |
410 | BT_MBOX_PRINT(1, AGGR_TRFC_LD, false); | |
411 | BT_MBOX_PRINT(1, MSG_TYPE, false); | |
412 | BT_MBOX_PRINT(1, SSN, true); | |
413 | ||
414 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n"); | |
415 | ||
416 | BT_MBOX_PRINT(2, SNIFF_ACT, false); | |
417 | BT_MBOX_PRINT(2, PAG, false); | |
418 | BT_MBOX_PRINT(2, INQUIRY, false); | |
419 | BT_MBOX_PRINT(2, CONN, false); | |
420 | BT_MBOX_PRINT(2, SNIFF_INTERVAL, false); | |
421 | BT_MBOX_PRINT(2, DISC, false); | |
422 | BT_MBOX_PRINT(2, SCO_TX_ACT, false); | |
423 | BT_MBOX_PRINT(2, SCO_RX_ACT, false); | |
424 | BT_MBOX_PRINT(2, ESCO_RE_TX, false); | |
425 | BT_MBOX_PRINT(2, SCO_DURATION, true); | |
426 | ||
427 | pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n"); | |
428 | ||
429 | BT_MBOX_PRINT(3, SCO_STATE, false); | |
430 | BT_MBOX_PRINT(3, SNIFF_STATE, false); | |
431 | BT_MBOX_PRINT(3, A2DP_STATE, false); | |
432 | BT_MBOX_PRINT(3, ACL_STATE, false); | |
433 | BT_MBOX_PRINT(3, MSTR_STATE, false); | |
434 | BT_MBOX_PRINT(3, OBX_STATE, false); | |
435 | BT_MBOX_PRINT(3, OPEN_CON_2, false); | |
436 | BT_MBOX_PRINT(3, TRAFFIC_LOAD, false); | |
437 | BT_MBOX_PRINT(3, CHL_SEQN_LSB, false); | |
438 | BT_MBOX_PRINT(3, INBAND_P, false); | |
439 | BT_MBOX_PRINT(3, MSG_TYPE_2, false); | |
440 | BT_MBOX_PRINT(3, SSN_2, false); | |
441 | BT_MBOX_PRINT(3, UPDATE_REQUEST, true); | |
442 | ||
443 | pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n", | |
444 | notif->bt_status); | |
445 | pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n", | |
446 | notif->bt_open_conn); | |
447 | pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n", | |
448 | notif->bt_traffic_load); | |
449 | pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n", | |
450 | notif->bt_agg_traffic_load); | |
451 | pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n", | |
452 | notif->bt_ci_compliance); | |
453 | ||
454 | mutex_unlock(&mvm->mutex); | |
455 | ||
456 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
457 | kfree(buf); | |
458 | ||
459 | return ret; | |
460 | } | |
461 | #undef BT_MBOX_PRINT | |
462 | ||
490953ac EG |
463 | static ssize_t iwl_dbgfs_fw_restart_write(struct file *file, |
464 | const char __user *user_buf, | |
465 | size_t count, loff_t *ppos) | |
466 | { | |
467 | struct iwl_mvm *mvm = file->private_data; | |
468 | bool restart_fw = iwlwifi_mod_params.restart_fw; | |
469 | int ret; | |
470 | ||
471 | iwlwifi_mod_params.restart_fw = true; | |
472 | ||
473 | mutex_lock(&mvm->mutex); | |
474 | ||
475 | /* take the return value to make compiler happy - it will fail anyway */ | |
476 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL); | |
477 | ||
478 | mutex_unlock(&mvm->mutex); | |
479 | ||
480 | iwlwifi_mod_params.restart_fw = restart_fw; | |
481 | ||
482 | return count; | |
483 | } | |
484 | ||
afc66bb7 JB |
485 | #ifdef CONFIG_PM_SLEEP |
486 | static ssize_t iwl_dbgfs_d3_sram_write(struct file *file, | |
487 | const char __user *user_buf, | |
488 | size_t count, loff_t *ppos) | |
489 | { | |
490 | struct iwl_mvm *mvm = file->private_data; | |
491 | char buf[8] = {}; | |
492 | int store; | |
493 | ||
494 | if (copy_from_user(buf, user_buf, sizeof(buf))) | |
495 | return -EFAULT; | |
496 | ||
497 | if (sscanf(buf, "%d", &store) != 1) | |
498 | return -EINVAL; | |
499 | ||
500 | mvm->store_d3_resume_sram = store; | |
501 | ||
502 | return count; | |
503 | } | |
504 | ||
505 | static ssize_t iwl_dbgfs_d3_sram_read(struct file *file, char __user *user_buf, | |
506 | size_t count, loff_t *ppos) | |
507 | { | |
508 | struct iwl_mvm *mvm = file->private_data; | |
509 | const struct fw_img *img; | |
510 | int ofs, len, pos = 0; | |
511 | size_t bufsz, ret; | |
512 | char *buf; | |
513 | u8 *ptr = mvm->d3_resume_sram; | |
514 | ||
515 | img = &mvm->fw->img[IWL_UCODE_WOWLAN]; | |
516 | len = img->sec[IWL_UCODE_SECTION_DATA].len; | |
517 | ||
518 | bufsz = len * 4 + 256; | |
519 | buf = kzalloc(bufsz, GFP_KERNEL); | |
520 | if (!buf) | |
521 | return -ENOMEM; | |
522 | ||
523 | pos += scnprintf(buf, bufsz, "D3 SRAM capture: %sabled\n", | |
524 | mvm->store_d3_resume_sram ? "en" : "dis"); | |
525 | ||
526 | if (ptr) { | |
527 | for (ofs = 0; ofs < len; ofs += 16) { | |
528 | pos += scnprintf(buf + pos, bufsz - pos, | |
529 | "0x%.4x ", ofs); | |
530 | hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos, | |
531 | bufsz - pos, false); | |
532 | pos += strlen(buf + pos); | |
533 | if (bufsz - pos > 0) | |
534 | buf[pos++] = '\n'; | |
535 | } | |
536 | } else { | |
537 | pos += scnprintf(buf + pos, bufsz - pos, | |
538 | "(no data captured)\n"); | |
539 | } | |
540 | ||
541 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); | |
542 | ||
543 | kfree(buf); | |
544 | ||
545 | return ret; | |
546 | } | |
547 | #endif | |
548 | ||
8ca151b5 JB |
549 | #define MVM_DEBUGFS_READ_FILE_OPS(name) \ |
550 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
551 | .read = iwl_dbgfs_##name##_read, \ | |
ba5295f8 | 552 | .open = simple_open, \ |
8ca151b5 JB |
553 | .llseek = generic_file_llseek, \ |
554 | } | |
555 | ||
556 | #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \ | |
557 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
558 | .write = iwl_dbgfs_##name##_write, \ | |
559 | .read = iwl_dbgfs_##name##_read, \ | |
ba5295f8 | 560 | .open = simple_open, \ |
8ca151b5 JB |
561 | .llseek = generic_file_llseek, \ |
562 | }; | |
563 | ||
564 | #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \ | |
565 | static const struct file_operations iwl_dbgfs_##name##_ops = { \ | |
566 | .write = iwl_dbgfs_##name##_write, \ | |
ba5295f8 | 567 | .open = simple_open, \ |
8ca151b5 JB |
568 | .llseek = generic_file_llseek, \ |
569 | }; | |
570 | ||
571 | #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \ | |
572 | if (!debugfs_create_file(#name, mode, parent, mvm, \ | |
573 | &iwl_dbgfs_##name##_ops)) \ | |
574 | goto err; \ | |
575 | } while (0) | |
576 | ||
577 | #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \ | |
578 | if (!debugfs_create_file(#name, mode, parent, vif, \ | |
579 | &iwl_dbgfs_##name##_ops)) \ | |
580 | goto err; \ | |
581 | } while (0) | |
582 | ||
583 | /* Device wide debugfs entries */ | |
584 | MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush); | |
585 | MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain); | |
586 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram); | |
587 | MVM_DEBUGFS_READ_FILE_OPS(stations); | |
10942342 | 588 | MVM_DEBUGFS_READ_FILE_OPS(bt_notif); |
8ca151b5 JB |
589 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow); |
590 | MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow); | |
490953ac | 591 | MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart); |
afc66bb7 JB |
592 | #ifdef CONFIG_PM_SLEEP |
593 | MVM_DEBUGFS_READ_WRITE_FILE_OPS(d3_sram); | |
594 | #endif | |
8ca151b5 | 595 | |
63494374 JB |
596 | /* Interface specific debugfs entries */ |
597 | MVM_DEBUGFS_READ_FILE_OPS(mac_params); | |
598 | ||
8ca151b5 JB |
599 | int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir) |
600 | { | |
601 | char buf[100]; | |
602 | ||
603 | mvm->debugfs_dir = dbgfs_dir; | |
604 | ||
605 | MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR); | |
606 | MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR); | |
607 | MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR); | |
608 | MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR); | |
10942342 | 609 | MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR); |
8ca151b5 JB |
610 | MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR); |
611 | MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR); | |
490953ac | 612 | MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR); |
afc66bb7 JB |
613 | #ifdef CONFIG_PM_SLEEP |
614 | MVM_DEBUGFS_ADD_FILE(d3_sram, mvm->debugfs_dir, S_IRUSR | S_IWUSR); | |
615 | #endif | |
8ca151b5 JB |
616 | |
617 | /* | |
618 | * Create a symlink with mac80211. It will be removed when mac80211 | |
619 | * exists (before the opmode exists which removes the target.) | |
620 | */ | |
621 | snprintf(buf, 100, "../../%s/%s", | |
622 | dbgfs_dir->d_parent->d_parent->d_name.name, | |
623 | dbgfs_dir->d_parent->d_name.name); | |
624 | if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf)) | |
625 | goto err; | |
626 | ||
627 | return 0; | |
628 | err: | |
629 | IWL_ERR(mvm, "Can't create the mvm debugfs directory\n"); | |
630 | return -ENOMEM; | |
631 | } | |
63494374 JB |
632 | |
633 | void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
634 | { | |
635 | struct dentry *dbgfs_dir = vif->debugfs_dir; | |
636 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
637 | char buf[100]; | |
638 | ||
639 | if (!dbgfs_dir) | |
640 | return; | |
641 | ||
642 | mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir); | |
643 | mvmvif->dbgfs_data = mvm; | |
644 | ||
645 | if (!mvmvif->dbgfs_dir) { | |
646 | IWL_ERR(mvm, "Failed to create debugfs directory under %s\n", | |
647 | dbgfs_dir->d_name.name); | |
648 | return; | |
649 | } | |
650 | ||
651 | MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, | |
652 | S_IRUSR); | |
653 | ||
654 | /* | |
655 | * Create symlink for convenience pointing to interface specific | |
656 | * debugfs entries for the driver. For example, under | |
657 | * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/ | |
658 | * find | |
659 | * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/ | |
660 | */ | |
661 | snprintf(buf, 100, "../../../%s/%s/%s/%s", | |
662 | dbgfs_dir->d_parent->d_parent->d_name.name, | |
663 | dbgfs_dir->d_parent->d_name.name, | |
664 | dbgfs_dir->d_name.name, | |
665 | mvmvif->dbgfs_dir->d_name.name); | |
666 | ||
667 | mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name, | |
668 | mvm->debugfs_dir, buf); | |
669 | if (!mvmvif->dbgfs_slink) | |
670 | IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n", | |
671 | dbgfs_dir->d_name.name); | |
672 | return; | |
673 | err: | |
674 | IWL_ERR(mvm, "Can't create debugfs entity\n"); | |
675 | } | |
676 | ||
677 | void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
678 | { | |
679 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
680 | ||
681 | debugfs_remove(mvmvif->dbgfs_slink); | |
682 | mvmvif->dbgfs_slink = NULL; | |
683 | ||
684 | debugfs_remove_recursive(mvmvif->dbgfs_dir); | |
685 | mvmvif->dbgfs_dir = NULL; | |
686 | } |