1 /******************************************************************************
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/debugfs.h>
33 #include <linux/ieee80211.h>
34 #include <net/mac80211.h>
38 #include "iwl-debug.h"
43 /* create and remove of files */
44 #define DEBUGFS_ADD_DIR(name, parent) do { \
45 dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
46 if (!(dbgfs->dir_##name)) \
50 #define DEBUGFS_ADD_FILE(name, parent) do { \
51 dbgfs->dbgfs_##parent##_files.file_##name = \
52 debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
53 &iwl_dbgfs_##name##_ops); \
54 if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
58 #define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
59 dbgfs->dbgfs_##parent##_files.file_##name = \
60 debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
61 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
62 || !dbgfs->dbgfs_##parent##_files.file_##name) \
66 #define DEBUGFS_ADD_X32(name, parent, ptr) do { \
67 dbgfs->dbgfs_##parent##_files.file_##name = \
68 debugfs_create_x32(#name, 0444, dbgfs->dir_##parent, ptr); \
69 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
70 || !dbgfs->dbgfs_##parent##_files.file_##name) \
74 #define DEBUGFS_REMOVE(name) do { \
75 debugfs_remove(name); \
80 #define DEBUGFS_READ_FUNC(name) \
81 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
82 char __user *user_buf, \
83 size_t count, loff_t *ppos);
85 #define DEBUGFS_WRITE_FUNC(name) \
86 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
87 const char __user *user_buf, \
88 size_t count, loff_t *ppos);
91 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
93 file->private_data = inode->i_private;
97 #define DEBUGFS_READ_FILE_OPS(name) \
98 DEBUGFS_READ_FUNC(name); \
99 static const struct file_operations iwl_dbgfs_##name##_ops = { \
100 .read = iwl_dbgfs_##name##_read, \
101 .open = iwl_dbgfs_open_file_generic, \
104 #define DEBUGFS_WRITE_FILE_OPS(name) \
105 DEBUGFS_WRITE_FUNC(name); \
106 static const struct file_operations iwl_dbgfs_##name##_ops = { \
107 .write = iwl_dbgfs_##name##_write, \
108 .open = iwl_dbgfs_open_file_generic, \
112 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
113 DEBUGFS_READ_FUNC(name); \
114 DEBUGFS_WRITE_FUNC(name); \
115 static const struct file_operations iwl_dbgfs_##name##_ops = { \
116 .write = iwl_dbgfs_##name##_write, \
117 .read = iwl_dbgfs_##name##_read, \
118 .open = iwl_dbgfs_open_file_generic, \
122 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
123 char __user *user_buf,
124 size_t count, loff_t *ppos) {
126 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
129 const size_t bufsz = sizeof(buf);
131 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
132 priv->tx_stats[0].cnt);
133 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
134 priv->tx_stats[1].cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
136 priv->tx_stats[2].cnt);
138 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
141 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
142 char __user *user_buf,
143 size_t count, loff_t *ppos) {
145 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
148 const size_t bufsz = sizeof(buf);
150 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
151 priv->rx_stats[0].cnt);
152 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
153 priv->rx_stats[1].cnt);
154 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
155 priv->rx_stats[2].cnt);
157 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
160 #define BYTE1_MASK 0x000000ff;
161 #define BYTE2_MASK 0x0000ffff;
162 #define BYTE3_MASK 0x00ffffff;
163 static ssize_t iwl_dbgfs_sram_read(struct file *file,
164 char __user *user_buf,
165 size_t count, loff_t *ppos)
172 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
173 const size_t bufsz = sizeof(buf);
175 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
176 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
178 iwl_grab_nic_access(priv);
179 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
180 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
181 priv->dbgfs->sram_len - i);
195 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
197 pos += scnprintf(buf + pos, bufsz - pos, "\n");
198 iwl_release_nic_access(priv);
200 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
204 static ssize_t iwl_dbgfs_sram_write(struct file *file,
205 const char __user *user_buf,
206 size_t count, loff_t *ppos)
208 struct iwl_priv *priv = file->private_data;
213 memset(buf, 0, sizeof(buf));
214 buf_size = min(count, sizeof(buf) - 1);
215 if (copy_from_user(buf, user_buf, buf_size))
218 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
219 priv->dbgfs->sram_offset = offset;
220 priv->dbgfs->sram_len = len;
222 priv->dbgfs->sram_offset = 0;
223 priv->dbgfs->sram_len = 0;
229 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
230 size_t count, loff_t *ppos)
232 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
233 struct iwl_station_entry *station;
234 int max_sta = priv->hw_params.max_stations;
238 /* Add 30 for initial string */
239 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
241 buf = kmalloc(bufsz, GFP_KERNEL);
245 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
248 for (i = 0; i < max_sta; i++) {
249 station = &priv->stations[i];
251 pos += scnprintf(buf + pos, bufsz - pos,
252 "station %d:\ngeneral data:\n", i+1);
253 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
254 station->sta.sta.sta_id);
255 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
257 pos += scnprintf(buf + pos, bufsz - pos,
259 station->sta.station_flags_msk);
260 pos += scnprintf(buf + pos, bufsz - pos,
261 "ps_status: %u\n", station->ps_status);
262 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
263 pos += scnprintf(buf + pos, bufsz - pos,
264 "seq_num\t\ttxq_id");
265 pos += scnprintf(buf + pos, bufsz - pos,
266 "\tframe_count\twait_for_ba\t");
267 pos += scnprintf(buf + pos, bufsz - pos,
268 "start_idx\tbitmap0\t");
269 pos += scnprintf(buf + pos, bufsz - pos,
270 "bitmap1\trate_n_flags");
271 pos += scnprintf(buf + pos, bufsz - pos, "\n");
273 for (j = 0; j < MAX_TID_COUNT; j++) {
274 pos += scnprintf(buf + pos, bufsz - pos,
276 station->tid[j].seq_number);
277 pos += scnprintf(buf + pos, bufsz - pos,
278 "\t%u\t\t%u\t\t%u\t\t",
279 station->tid[j].agg.txq_id,
280 station->tid[j].agg.frame_count,
281 station->tid[j].agg.wait_for_ba);
282 pos += scnprintf(buf + pos, bufsz - pos,
284 station->tid[j].agg.start_idx,
285 (unsigned long long)station->tid[j].agg.bitmap,
286 station->tid[j].agg.rate_n_flags);
287 pos += scnprintf(buf + pos, bufsz - pos, "\n");
289 pos += scnprintf(buf + pos, bufsz - pos, "\n");
293 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
298 static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
299 char __user *user_buf,
304 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
305 int pos = 0, ofs = 0, buf_size = 0;
308 size_t eeprom_len = priv->cfg->eeprom_size;
309 buf_size = 4 * eeprom_len + 256;
311 if (eeprom_len % 16) {
312 IWL_ERROR("EEPROM size is not multiple of 16.\n");
316 /* 4 characters for byte 0xYY */
317 buf = kzalloc(buf_size, GFP_KERNEL);
319 IWL_ERROR("Can not allocate Buffer\n");
324 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
325 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
326 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
329 if (buf_size - pos > 0)
333 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
338 static ssize_t iwl_dbgfs_log_event_write(struct file *file,
339 const char __user *user_buf,
340 size_t count, loff_t *ppos)
342 struct iwl_priv *priv = file->private_data;
347 memset(buf, 0, sizeof(buf));
348 buf_size = min(count, sizeof(buf) - 1);
349 if (copy_from_user(buf, user_buf, buf_size))
351 if (sscanf(buf, "%d", &event_log_flag) != 1)
353 if (event_log_flag == 1)
354 iwl_dump_nic_event_log(priv);
361 static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
362 size_t count, loff_t *ppos)
364 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
365 struct ieee80211_channel *channels = NULL;
366 const struct ieee80211_supported_band *supp_band = NULL;
367 int pos = 0, i, bufsz = PAGE_SIZE;
371 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
374 buf = kzalloc(bufsz, GFP_KERNEL);
376 IWL_ERROR("Can not allocate Buffer\n");
380 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
381 channels = supp_band->channels;
383 pos += scnprintf(buf + pos, bufsz - pos,
384 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
385 supp_band->n_channels);
387 for (i = 0; i < supp_band->n_channels; i++)
388 pos += scnprintf(buf + pos, bufsz - pos,
389 "%d: %ddBm: BSS%s%s, %s.\n",
390 ieee80211_frequency_to_channel(
391 channels[i].center_freq),
392 channels[i].max_power,
393 channels[i].flags & IEEE80211_CHAN_RADAR ?
394 " (IEEE 802.11h required)" : "",
395 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
396 || (channels[i].flags &
397 IEEE80211_CHAN_RADAR)) ? "" :
400 IEEE80211_CHAN_PASSIVE_SCAN ?
401 "passive only" : "active/passive");
403 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
404 channels = supp_band->channels;
406 pos += scnprintf(buf + pos, bufsz - pos,
407 "Displaying %d channels in 5.2GHz band (802.11a)\n",
408 supp_band->n_channels);
410 for (i = 0; i < supp_band->n_channels; i++)
411 pos += scnprintf(buf + pos, bufsz - pos,
412 "%d: %ddBm: BSS%s%s, %s.\n",
413 ieee80211_frequency_to_channel(
414 channels[i].center_freq),
415 channels[i].max_power,
416 channels[i].flags & IEEE80211_CHAN_RADAR ?
417 " (IEEE 802.11h required)" : "",
418 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
419 || (channels[i].flags &
420 IEEE80211_CHAN_RADAR)) ? "" :
423 IEEE80211_CHAN_PASSIVE_SCAN ?
424 "passive only" : "active/passive");
426 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
431 DEBUGFS_READ_WRITE_FILE_OPS(sram);
432 DEBUGFS_WRITE_FILE_OPS(log_event);
433 DEBUGFS_READ_FILE_OPS(eeprom);
434 DEBUGFS_READ_FILE_OPS(stations);
435 DEBUGFS_READ_FILE_OPS(rx_statistics);
436 DEBUGFS_READ_FILE_OPS(tx_statistics);
437 DEBUGFS_READ_FILE_OPS(channels);
440 * Create the debugfs files and directories
443 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
445 struct iwl_debugfs *dbgfs;
446 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
449 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
457 dbgfs->dir_drv = debugfs_create_dir(name, phyd);
458 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
463 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
464 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
465 DEBUGFS_ADD_FILE(eeprom, data);
466 DEBUGFS_ADD_FILE(sram, data);
467 DEBUGFS_ADD_FILE(log_event, data);
468 DEBUGFS_ADD_FILE(stations, data);
469 DEBUGFS_ADD_FILE(rx_statistics, data);
470 DEBUGFS_ADD_FILE(tx_statistics, data);
471 DEBUGFS_ADD_FILE(channels, data);
472 DEBUGFS_ADD_X32(status, data, (u32 *)&priv->status);
473 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
474 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
475 &priv->disable_chain_noise_cal);
476 DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
480 IWL_ERROR("Can't open the debugfs directory\n");
481 iwl_dbgfs_unregister(priv);
484 EXPORT_SYMBOL(iwl_dbgfs_register);
487 * Remove the debugfs files and directories
490 void iwl_dbgfs_unregister(struct iwl_priv *priv)
495 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom);
496 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
497 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
498 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
499 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
500 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
501 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
502 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
503 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
504 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
505 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
506 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
507 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
511 EXPORT_SYMBOL(iwl_dbgfs_unregister);