1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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.
62 *****************************************************************************/
67 struct iwl_dbgfs_mvm_ctx {
69 struct ieee80211_vif *vif;
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)
76 struct iwl_mvm *mvm = file->private_data;
82 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
85 memset(buf, 0, sizeof(buf));
86 buf_size = min(count, sizeof(buf) - 1);
87 if (copy_from_user(buf, user_buf, buf_size))
90 if (sscanf(buf, "%x", &scd_q_msk) != 1)
93 IWL_ERR(mvm, "FLUSHING queues: scd_q_msk = 0x%x\n", scd_q_msk);
95 mutex_lock(&mvm->mutex);
96 ret = iwl_mvm_flush_tx_path(mvm, scd_q_msk, true) ? : count;
97 mutex_unlock(&mvm->mutex);
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)
106 struct iwl_mvm *mvm = file->private_data;
107 struct ieee80211_sta *sta;
110 int buf_size, sta_id, drain, ret;
112 if (!mvm->ucode_loaded || mvm->cur_ucode != IWL_UCODE_REGULAR)
115 memset(buf, 0, sizeof(buf));
116 buf_size = min(count, sizeof(buf) - 1);
117 if (copy_from_user(buf, user_buf, buf_size))
120 if (sscanf(buf, "%d %d", &sta_id, &drain) != 2)
123 mutex_lock(&mvm->mutex);
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))
130 ret = iwl_mvm_drain_sta(mvm, (void *)sta->drv_priv, drain) ? :
133 mutex_unlock(&mvm->mutex);
138 static ssize_t iwl_dbgfs_sram_read(struct file *file, char __user *user_buf,
139 size_t count, loff_t *ppos)
141 struct iwl_mvm *mvm = file->private_data;
142 const struct fw_img *img;
143 int ofs, len, pos = 0;
148 /* default is to dump the entire data segment */
149 if (!mvm->dbgfs_sram_offset && !mvm->dbgfs_sram_len) {
150 mvm->dbgfs_sram_offset = 0x800000;
151 if (!mvm->ucode_loaded)
153 img = &mvm->fw->img[mvm->cur_ucode];
154 mvm->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
156 len = mvm->dbgfs_sram_len;
158 bufsz = len * 4 + 256;
159 buf = kzalloc(bufsz, GFP_KERNEL);
163 ptr = kzalloc(len, GFP_KERNEL);
169 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n", len);
170 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
171 mvm->dbgfs_sram_offset);
173 iwl_trans_read_mem_bytes(mvm->trans,
174 mvm->dbgfs_sram_offset,
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,
180 pos += strlen(buf + pos);
185 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
193 static ssize_t iwl_dbgfs_sram_write(struct file *file,
194 const char __user *user_buf, size_t count,
197 struct iwl_mvm *mvm = file->private_data;
202 memset(buf, 0, sizeof(buf));
203 buf_size = min(count, sizeof(buf) - 1);
204 if (copy_from_user(buf, user_buf, buf_size))
207 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
208 if ((offset & 0x3) || (len & 0x3))
210 mvm->dbgfs_sram_offset = offset;
211 mvm->dbgfs_sram_len = len;
213 mvm->dbgfs_sram_offset = 0;
214 mvm->dbgfs_sram_len = 0;
220 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
221 size_t count, loff_t *ppos)
223 struct iwl_mvm *mvm = file->private_data;
224 struct ieee80211_sta *sta;
226 int i, pos = 0, bufsz = sizeof(buf);
228 mutex_lock(&mvm->mutex);
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));
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",
240 pos += scnprintf(buf + pos, bufsz - pos, "%pM\n",
244 mutex_unlock(&mvm->mutex);
246 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
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)
253 struct iwl_mvm *mvm = file->private_data;
257 if (!mvm->ucode_loaded)
260 if (copy_from_user(buf, user_buf, sizeof(buf)))
263 if (sscanf(buf, "%d", &allow) != 1)
266 IWL_DEBUG_POWER(mvm, "%s device power down\n",
267 allow ? "allow" : "prevent");
270 * TODO: Send REPLY_DEBUG_CMD (0xf0) when FW support it
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)
280 struct iwl_mvm *mvm = file->private_data;
284 if (copy_from_user(buf, user_buf, sizeof(buf)))
287 if (sscanf(buf, "%d", &allow) != 1)
290 IWL_DEBUG_POWER(mvm, "%s device power down in d3\n",
291 allow ? "allow" : "prevent");
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
298 mvm->prevent_power_down_d3 = !allow;
303 #define BT_MBOX_MSG(_notif, _num, _field) \
304 ((le32_to_cpu((_notif)->mbox_msg[(_num)]) & BT_MBOX##_num##_##_field)\
305 >> BT_MBOX##_num##_##_field##_POS)
308 #define BT_MBOX_PRINT(_num, _field, _end) \
309 pos += scnprintf(buf + pos, bufsz - pos, \
312 BT_MBOX_MSG(notif, _num, _field), \
315 static ssize_t iwl_dbgfs_bt_notif_read(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
318 struct iwl_mvm *mvm = file->private_data;
319 struct iwl_bt_coex_profile_notif *notif = &mvm->last_bt_notif;
321 int ret, pos = 0, bufsz = sizeof(char) * 1024;
323 buf = kmalloc(bufsz, GFP_KERNEL);
327 mutex_lock(&mvm->mutex);
329 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw0:\n");
331 BT_MBOX_PRINT(0, LE_SLAVE_LAT, false);
332 BT_MBOX_PRINT(0, LE_PROF1, false);
333 BT_MBOX_PRINT(0, LE_PROF2, false);
334 BT_MBOX_PRINT(0, LE_PROF_OTHER, false);
335 BT_MBOX_PRINT(0, CHL_SEQ_N, false);
336 BT_MBOX_PRINT(0, INBAND_S, false);
337 BT_MBOX_PRINT(0, LE_MIN_RSSI, false);
338 BT_MBOX_PRINT(0, LE_SCAN, false);
339 BT_MBOX_PRINT(0, LE_ADV, false);
340 BT_MBOX_PRINT(0, LE_MAX_TX_POWER, false);
341 BT_MBOX_PRINT(0, OPEN_CON_1, true);
343 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw1:\n");
345 BT_MBOX_PRINT(1, BR_MAX_TX_POWER, false);
346 BT_MBOX_PRINT(1, IP_SR, false);
347 BT_MBOX_PRINT(1, LE_MSTR, false);
348 BT_MBOX_PRINT(1, AGGR_TRFC_LD, false);
349 BT_MBOX_PRINT(1, MSG_TYPE, false);
350 BT_MBOX_PRINT(1, SSN, true);
352 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw2:\n");
354 BT_MBOX_PRINT(2, SNIFF_ACT, false);
355 BT_MBOX_PRINT(2, PAG, false);
356 BT_MBOX_PRINT(2, INQUIRY, false);
357 BT_MBOX_PRINT(2, CONN, false);
358 BT_MBOX_PRINT(2, SNIFF_INTERVAL, false);
359 BT_MBOX_PRINT(2, DISC, false);
360 BT_MBOX_PRINT(2, SCO_TX_ACT, false);
361 BT_MBOX_PRINT(2, SCO_RX_ACT, false);
362 BT_MBOX_PRINT(2, ESCO_RE_TX, false);
363 BT_MBOX_PRINT(2, SCO_DURATION, true);
365 pos += scnprintf(buf+pos, bufsz-pos, "MBOX dw3:\n");
367 BT_MBOX_PRINT(3, SCO_STATE, false);
368 BT_MBOX_PRINT(3, SNIFF_STATE, false);
369 BT_MBOX_PRINT(3, A2DP_STATE, false);
370 BT_MBOX_PRINT(3, ACL_STATE, false);
371 BT_MBOX_PRINT(3, MSTR_STATE, false);
372 BT_MBOX_PRINT(3, OBX_STATE, false);
373 BT_MBOX_PRINT(3, OPEN_CON_2, false);
374 BT_MBOX_PRINT(3, TRAFFIC_LOAD, false);
375 BT_MBOX_PRINT(3, CHL_SEQN_LSB, false);
376 BT_MBOX_PRINT(3, INBAND_P, false);
377 BT_MBOX_PRINT(3, MSG_TYPE_2, false);
378 BT_MBOX_PRINT(3, SSN_2, false);
379 BT_MBOX_PRINT(3, UPDATE_REQUEST, true);
381 pos += scnprintf(buf+pos, bufsz-pos, "bt_status = %d\n",
383 pos += scnprintf(buf+pos, bufsz-pos, "bt_open_conn = %d\n",
384 notif->bt_open_conn);
385 pos += scnprintf(buf+pos, bufsz-pos, "bt_traffic_load = %d\n",
386 notif->bt_traffic_load);
387 pos += scnprintf(buf+pos, bufsz-pos, "bt_agg_traffic_load = %d\n",
388 notif->bt_agg_traffic_load);
389 pos += scnprintf(buf+pos, bufsz-pos, "bt_ci_compliance = %d\n",
390 notif->bt_ci_compliance);
392 mutex_unlock(&mvm->mutex);
394 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
401 static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
402 const char __user *user_buf,
403 size_t count, loff_t *ppos)
405 struct iwl_mvm *mvm = file->private_data;
406 bool restart_fw = iwlwifi_mod_params.restart_fw;
409 iwlwifi_mod_params.restart_fw = true;
411 mutex_lock(&mvm->mutex);
413 /* take the return value to make compiler happy - it will fail anyway */
414 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_ERROR, CMD_SYNC, 0, NULL);
416 mutex_unlock(&mvm->mutex);
418 iwlwifi_mod_params.restart_fw = restart_fw;
423 #define MVM_DEBUGFS_READ_FILE_OPS(name) \
424 static const struct file_operations iwl_dbgfs_##name##_ops = { \
425 .read = iwl_dbgfs_##name##_read, \
426 .open = simple_open, \
427 .llseek = generic_file_llseek, \
430 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name) \
431 static const struct file_operations iwl_dbgfs_##name##_ops = { \
432 .write = iwl_dbgfs_##name##_write, \
433 .read = iwl_dbgfs_##name##_read, \
434 .open = simple_open, \
435 .llseek = generic_file_llseek, \
438 #define MVM_DEBUGFS_WRITE_FILE_OPS(name) \
439 static const struct file_operations iwl_dbgfs_##name##_ops = { \
440 .write = iwl_dbgfs_##name##_write, \
441 .open = simple_open, \
442 .llseek = generic_file_llseek, \
445 #define MVM_DEBUGFS_ADD_FILE(name, parent, mode) do { \
446 if (!debugfs_create_file(#name, mode, parent, mvm, \
447 &iwl_dbgfs_##name##_ops)) \
451 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
452 if (!debugfs_create_file(#name, mode, parent, vif, \
453 &iwl_dbgfs_##name##_ops)) \
457 /* Device wide debugfs entries */
458 MVM_DEBUGFS_WRITE_FILE_OPS(tx_flush);
459 MVM_DEBUGFS_WRITE_FILE_OPS(sta_drain);
460 MVM_DEBUGFS_READ_WRITE_FILE_OPS(sram);
461 MVM_DEBUGFS_READ_FILE_OPS(stations);
462 MVM_DEBUGFS_READ_FILE_OPS(bt_notif);
463 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_allow);
464 MVM_DEBUGFS_WRITE_FILE_OPS(power_down_d3_allow);
465 MVM_DEBUGFS_WRITE_FILE_OPS(fw_restart);
467 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir)
471 mvm->debugfs_dir = dbgfs_dir;
473 MVM_DEBUGFS_ADD_FILE(tx_flush, mvm->debugfs_dir, S_IWUSR);
474 MVM_DEBUGFS_ADD_FILE(sta_drain, mvm->debugfs_dir, S_IWUSR);
475 MVM_DEBUGFS_ADD_FILE(sram, mvm->debugfs_dir, S_IWUSR | S_IRUSR);
476 MVM_DEBUGFS_ADD_FILE(stations, dbgfs_dir, S_IRUSR);
477 MVM_DEBUGFS_ADD_FILE(bt_notif, dbgfs_dir, S_IRUSR);
478 MVM_DEBUGFS_ADD_FILE(power_down_allow, mvm->debugfs_dir, S_IWUSR);
479 MVM_DEBUGFS_ADD_FILE(power_down_d3_allow, mvm->debugfs_dir, S_IWUSR);
480 MVM_DEBUGFS_ADD_FILE(fw_restart, mvm->debugfs_dir, S_IWUSR);
483 * Create a symlink with mac80211. It will be removed when mac80211
484 * exists (before the opmode exists which removes the target.)
486 snprintf(buf, 100, "../../%s/%s",
487 dbgfs_dir->d_parent->d_parent->d_name.name,
488 dbgfs_dir->d_parent->d_name.name);
489 if (!debugfs_create_symlink("iwlwifi", mvm->hw->wiphy->debugfsdir, buf))
494 IWL_ERR(mvm, "Can't create the mvm debugfs directory\n");