blob: 109dc8e437f532b4d91424fa54407beca51a3233 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
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
67struct iwl_dbgfs_mvm_ctx {
68 struct iwl_mvm *mvm;
69 struct ieee80211_vif *vif;
70};
71
Johannes Berg8ca151b2013-01-24 14:25:36 +010072static 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
102static 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;
Johannes Berg555214a2013-10-25 13:06:06 +0200122 if (sta_id < 0 || sta_id >= IWL_MVM_STATION_COUNT)
123 return -EINVAL;
124 if (drain < 0 || drain > 1)
125 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100126
127 mutex_lock(&mvm->mutex);
128
129 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
130 lockdep_is_held(&mvm->mutex));
131 if (IS_ERR_OR_NULL(sta))
132 ret = -ENOENT;
133 else
134 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
135 count;
136
137 mutex_unlock(&mvm->mutex);
138
139 return ret;
140}
141
142static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
143 size_t count, loff_t *ppos)
144{
145 struct iwl_mvm *mvm = file->private_data;
146 const struct fw_img *img;
147 int ofs, len, pos = 0;
148 size_t bufsz, ret;
149 char *buf;
150 u8 *ptr;
151
152 /* default is to dump the entire data segment */
153 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
154 mvm->dbgfs_sram_offset = 0x800000;
155 if (!mvm->ucode_loaded)
156 return -EINVAL;
157 img = &mvm->fw->img[mvm->cur_ucode];
158 mvm->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
159 }
160 len = mvm->dbgfs_sram_len;
161
162 bufsz = len * 4 + 256;
163 buf = kzalloc(bufsz, GFP_KERNEL);
164 if (!buf)
165 return -ENOMEM;
166
167 ptr = kzalloc(len, GFP_KERNEL);
168 if (!ptr) {
169 kfree(buf);
170 return -ENOMEM;
171 }
172
173 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
174 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
175 mvm->dbgfs_sram_offset);
176
177 iwl_trans_read_mem_bytes(mvm->trans,
178 mvm->dbgfs_sram_offset,
179 ptr, len);
180 for (ofs = 0; ofs < len; ofs += 16) {
181 pos += scnprintf(buf + pos, bufsz - pos, "0x%.4x ", ofs);
182 hex_dump_to_buffer(ptr + ofs, 16, 16, 1, buf + pos,
183 bufsz - pos, false);
184 pos += strlen(buf + pos);
185 if (bufsz - pos > 0)
186 buf[pos++] = '\n';
187 }
188
189 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
190
191 kfree(buf);
192 kfree(ptr);
193
194 return ret;
195}
196
197static ssize_t iwl_dbgfs_sram_write(struct file *file,
198 const char __user *user_buf, size_t count,
199 loff_t *ppos)
200{
201 struct iwl_mvm *mvm = file->private_data;
202 char buf[64];
203 int buf_size;
204 u32 offset, len;
205
206 memset(buf, 0, sizeof(buf));
207 buf_size = min(count, sizeof(buf) - 1);
208 if (copy_from_user(buf, user_buf, buf_size))
209 return -EFAULT;
210
211 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
212 if ((offset & 0x3) || (len & 0x3))
213 return -EINVAL;
214 mvm->dbgfs_sram_offset = offset;
215 mvm->dbgfs_sram_len = len;
216 } else {
217 mvm->dbgfs_sram_offset = 0;
218 mvm->dbgfs_sram_len = 0;
219 }
220
221 return count;
222}
223
224static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
225 size_t count, loff_t *ppos)
226{
227 struct iwl_mvm *mvm = file->private_data;
228 struct ieee80211_sta *sta;
229 char buf[400];
230 int i, pos = 0, bufsz = sizeof(buf);
231
232 mutex_lock(&mvm->mutex);
233
234 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
235 pos += scnprintf(buf + pos, bufsz - pos, "%.2d: ", i);
236 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
237 lockdep_is_held(&mvm->mutex));
238 if (!sta)
239 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
240 else if (IS_ERR(sta))
241 pos += scnprintf(buf + pos, bufsz - pos, "%ld\n",
242 PTR_ERR(sta));
243 else
244 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
245 sta->addr);
246 }
247
248 mutex_unlock(&mvm->mutex);
249
250 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
251}
252
253static ssize_t iwl_dbgfs_power_down_allow_write(struct file *file,
254 const char __user *user_buf,
255 size_t count, loff_t *ppos)
256{
257 struct iwl_mvm *mvm = file->private_data;
258 char buf[8] = {};
259 int allow;
260
261 if (!mvm->ucode_loaded)
262 return -EIO;
263
264 if (copy_from_user(buf, user_buf, sizeof(buf)))
265 return -EFAULT;
266
267 if (sscanf(buf, "%d", &allow) != 1)
268 return -EINVAL;
269
270 IWL_DEBUG_POWER(mvm, "%s device power down\n",
271 allow ? "allow" : "prevent");
272
273 /*
274 * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
275 */
276
277 return count;
278}
279
280static ssize_t iwl_dbgfs_power_down_d3_allow_write(struct file *file,
281 const char __user *user_buf,
282 size_t count, loff_t *ppos)
283{
284 struct iwl_mvm *mvm = file->private_data;
285 char buf[8] = {};
286 int allow;
287
288 if (copy_from_user(buf, user_buf, sizeof(buf)))
289 return -EFAULT;
290
291 if (sscanf(buf, "%d", &allow) != 1)
292 return -EINVAL;
293
294 IWL_DEBUG_POWER(mvm, "%s device power down in d3\n",
295 allow ? "allow" : "prevent");
296
297 /*
298 * TODO: When WoWLAN FW alive notification happens, driver will send
299 * REPLY_DEBUG_CMD setting power_down_allow flag according to
300 * mvm->prevent_power_down_d3
301 */
302 mvm->prevent_power_down_d3 = !allow;
303
304 return count;
305}
306
Johannes Berg63494372013-03-26 10:47:53 +0100307static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
308 char __user *user_buf,
309 size_t count, loff_t *ppos)
310{
311 struct ieee80211_vif *vif = file->private_data;
312 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
313 struct iwl_mvm *mvm = mvmvif->dbgfs_data;
314 u8 ap_sta_id;
315 struct ieee80211_chanctx_conf *chanctx_conf;
316 char buf[512];
317 int bufsz = sizeof(buf);
318 int pos = 0;
319 int i;
320
321 mutex_lock(&mvm->mutex);
322
323 ap_sta_id = mvmvif->ap_sta_id;
324
325 pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
326 mvmvif->id, mvmvif->color);
327 pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
328 vif->bss_conf.bssid);
329 pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
330 for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++) {
331 pos += scnprintf(buf+pos, bufsz-pos,
332 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
333 i, mvmvif->queue_params[i].txop,
334 mvmvif->queue_params[i].cw_min,
335 mvmvif->queue_params[i].cw_max,
336 mvmvif->queue_params[i].aifs,
337 mvmvif->queue_params[i].uapsd);
338 }
339
Emmanuel Grumbach2b76ef12013-01-24 10:35:13 +0200340 if (vif->type == NL80211_IFTYPE_STATION &&
341 ap_sta_id != IWL_MVM_STATION_COUNT) {
342 struct ieee80211_sta *sta;
343 struct iwl_mvm_sta *mvm_sta;
344
345 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[ap_sta_id],
346 lockdep_is_held(&mvm->mutex));
347 mvm_sta = (void *)sta->drv_priv;
348 pos += scnprintf(buf+pos, bufsz-pos,
349 "ap_sta_id %d - reduced Tx power %d\n",
350 ap_sta_id, mvm_sta->bt_reduced_txpower);
351 }
Johannes Berg63494372013-03-26 10:47:53 +0100352
353 rcu_read_lock();
354 chanctx_conf = rcu_dereference(vif->chanctx_conf);
355 if (chanctx_conf) {
356 pos += scnprintf(buf+pos, bufsz-pos,
357 "idle rx chains %d, active rx chains: %d\n",
358 chanctx_conf->rx_chains_static,
359 chanctx_conf->rx_chains_dynamic);
360 }
361 rcu_read_unlock();
362
363 mutex_unlock(&mvm->mutex);
364
365 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
366}
367
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200368#define BT_MBOX_MSG(_notif, _num, _field) \
369 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
370 >> BT_MBOX##_num##_##_field##_POS)
371
372
373#define BT_MBOX_PRINT(_num, _field, _end) \
374 pos += scnprintf(buf + pos, bufsz - pos, \
375 "\t%s: %d%s", \
376 #_field, \
377 BT_MBOX_MSG(notif, _num, _field), \
378 true ? "\n" : ", ");
379
380static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
381 size_t count, loff_t *ppos)
382{
383 struct iwl_mvm *mvm = file->private_data;
384 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
385 char *buf;
386 int ret, pos = 0, bufsz = sizeof(char) * 1024;
387
388 buf = kmalloc(bufsz, GFP_KERNEL);
389 if (!buf)
390 return -ENOMEM;
391
392 mutex_lock(&mvm->mutex);
393
394 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
395
396 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
397 BT_MBOX_PRINT(0, LE_PROF1, false);
398 BT_MBOX_PRINT(0, LE_PROF2, false);
399 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
400 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
401 BT_MBOX_PRINT(0, INBAND_S, false);
402 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
403 BT_MBOX_PRINT(0, LE_SCAN, false);
404 BT_MBOX_PRINT(0, LE_ADV, false);
405 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
406 BT_MBOX_PRINT(0, OPEN_CON_1, true);
407
408 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
409
410 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
411 BT_MBOX_PRINT(1, IP_SR, false);
412 BT_MBOX_PRINT(1, LE_MSTR, false);
413 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
414 BT_MBOX_PRINT(1, MSG_TYPE, false);
415 BT_MBOX_PRINT(1, SSN, true);
416
417 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
418
419 BT_MBOX_PRINT(2, SNIFF_ACT, false);
420 BT_MBOX_PRINT(2, PAG, false);
421 BT_MBOX_PRINT(2, INQUIRY, false);
422 BT_MBOX_PRINT(2, CONN, false);
423 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
424 BT_MBOX_PRINT(2, DISC, false);
425 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
426 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
427 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
428 BT_MBOX_PRINT(2, SCO_DURATION, true);
429
430 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
431
432 BT_MBOX_PRINT(3, SCO_STATE, false);
433 BT_MBOX_PRINT(3, SNIFF_STATE, false);
434 BT_MBOX_PRINT(3, A2DP_STATE, false);
435 BT_MBOX_PRINT(3, ACL_STATE, false);
436 BT_MBOX_PRINT(3, MSTR_STATE, false);
437 BT_MBOX_PRINT(3, OBX_STATE, false);
438 BT_MBOX_PRINT(3, OPEN_CON_2, false);
439 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
440 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
441 BT_MBOX_PRINT(3, INBAND_P, false);
442 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
443 BT_MBOX_PRINT(3, SSN_2, false);
444 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
445
446 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
447 notif->bt_status);
448 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
449 notif->bt_open_conn);
450 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
451 notif->bt_traffic_load);
452 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
453 notif->bt_agg_traffic_load);
454 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
455 notif->bt_ci_compliance);
456
457 mutex_unlock(&mvm->mutex);
458
459 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
460 kfree(buf);
461
462 return ret;
463}
464#undef BT_MBOX_PRINT
465
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200466static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
467 const char __user *user_buf,
468 size_t count, loff_t *ppos)
469{
470 struct iwl_mvm *mvm = file->private_data;
471 bool restart_fw = iwlwifi_mod_params.restart_fw;
472 int ret;
473
474 iwlwifi_mod_params.restart_fw = true;
475
476 mutex_lock(&mvm->mutex);
477
478 /* take the return value to make compiler happy - it will fail anyway */
479 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
480
481 mutex_unlock(&mvm->mutex);
482
483 iwlwifi_mod_params.restart_fw = restart_fw;
484
485 return count;
486}
487
Johannes Berg8ca151b2013-01-24 14:25:36 +0100488#define MVM_DEBUGFS_READ_FILE_OPS(name) \
489static const struct file_operations iwl_dbgfs_##name##_ops = { \
490 .read = iwl_dbgfs_##name##_read, \
Wei Yongjunba5295f2013-02-25 21:24:11 +0800491 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +0100492 .llseek = generic_file_llseek, \
493}
494
495#define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
496static const struct file_operations iwl_dbgfs_##name##_ops = { \
497 .write = iwl_dbgfs_##name##_write, \
498 .read = iwl_dbgfs_##name##_read, \
Wei Yongjunba5295f2013-02-25 21:24:11 +0800499 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +0100500 .llseek = generic_file_llseek, \
501};
502
503#define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
504static const struct file_operations iwl_dbgfs_##name##_ops = { \
505 .write = iwl_dbgfs_##name##_write, \
Wei Yongjunba5295f2013-02-25 21:24:11 +0800506 .open = simple_open, \
Johannes Berg8ca151b2013-01-24 14:25:36 +0100507 .llseek = generic_file_llseek, \
508};
509
510#define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
511 if (!debugfs_create_file(#name, mode, parent, mvm, \
512 &iwl_dbgfs_##name##_ops)) \
513 goto err; \
514 } while (0)
515
516#define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
517 if (!debugfs_create_file(#name, mode, parent, vif, \
518 &iwl_dbgfs_##name##_ops)) \
519 goto err; \
520 } while (0)
521
522/* Device wide debugfs entries */
523MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
524MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
525MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
526MVM_DEBUGFS_READ_FILE_OPS(stations);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200527MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100528MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
529MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200530MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531
Johannes Berg63494372013-03-26 10:47:53 +0100532/* Interface specific debugfs entries */
533MVM_DEBUGFS_READ_FILE_OPS(mac_params);
534
Johannes Berg8ca151b2013-01-24 14:25:36 +0100535int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
536{
537 char buf[100];
538
539 mvm->debugfs_dir = dbgfs_dir;
540
541 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
542 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
543 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
544 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
Emmanuel Grumbach10942342013-02-19 11:02:36 +0200545 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100546 MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
547 MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +0200548 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100549
550 /*
551 * Create a symlink with mac80211. It will be removed when mac80211
552 * exists (before the opmode exists which removes the target.)
553 */
554 snprintf(buf, 100, "../../%s/%s",
555 dbgfs_dir->d_parent->d_parent->d_name.name,
556 dbgfs_dir->d_parent->d_name.name);
557 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
558 goto err;
559
560 return 0;
561err:
562 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");
563 return -ENOMEM;
564}
Johannes Berg63494372013-03-26 10:47:53 +0100565
566void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
567{
568 struct dentry *dbgfs_dir = vif->debugfs_dir;
569 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
570 char buf[100];
571
572 if (!dbgfs_dir)
573 return;
574
575 mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
576 mvmvif->dbgfs_data = mvm;
577
578 if (!mvmvif->dbgfs_dir) {
579 IWL_ERR(mvm, "Failed to create debugfs directory under %s\n",
580 dbgfs_dir->d_name.name);
581 return;
582 }
583
584 MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir,
585 S_IRUSR);
586
587 /*
588 * Create symlink for convenience pointing to interface specific
589 * debugfs entries for the driver. For example, under
590 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
591 * find
592 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
593 */
594 snprintf(buf, 100, "../../../%s/%s/%s/%s",
595 dbgfs_dir->d_parent->d_parent->d_name.name,
596 dbgfs_dir->d_parent->d_name.name,
597 dbgfs_dir->d_name.name,
598 mvmvif->dbgfs_dir->d_name.name);
599
600 mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
601 mvm->debugfs_dir, buf);
602 if (!mvmvif->dbgfs_slink)
603 IWL_ERR(mvm, "Can't create debugfs symbolic link under %s\n",
604 dbgfs_dir->d_name.name);
605 return;
606err:
607 IWL_ERR(mvm, "Can't create debugfs entity\n");
608}
609
610void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
611{
612 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
613
614 debugfs_remove(mvmvif->dbgfs_slink);
615 mvmvif->dbgfs_slink = NULL;
616
617 debugfs_remove_recursive(mvmvif->dbgfs_dir);
618 mvmvif->dbgfs_dir = NULL;
619}