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 * Tomas Winkler <tomas.winkler@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_REMOVE(name) do { \
59 debugfs_remove(name); \
64 #define DEBUGFS_READ_FUNC(name) \
65 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
66 char __user *user_buf, \
67 size_t count, loff_t *ppos);
69 #define DEBUGFS_WRITE_FUNC(name) \
70 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
71 const char __user *user_buf, \
72 size_t count, loff_t *ppos);
75 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
77 file->private_data = inode->i_private;
81 #define DEBUGFS_READ_FILE_OPS(name) \
82 DEBUGFS_READ_FUNC(name); \
83 static const struct file_operations iwl_dbgfs_##name##_ops = { \
84 .read = iwl_dbgfs_##name##_read, \
85 .open = iwl_dbgfs_open_file_generic, \
88 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
89 DEBUGFS_READ_FUNC(name); \
90 DEBUGFS_WRITE_FUNC(name); \
91 static const struct file_operations iwl_dbgfs_##name##_ops = { \
92 .write = iwl_dbgfs_##name##_write, \
93 .read = iwl_dbgfs_##name##_read, \
94 .open = iwl_dbgfs_open_file_generic, \
98 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
99 char __user *user_buf,
100 size_t count, loff_t *ppos) {
102 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
106 pos += sprintf(buf+pos, "mgmt: %u\n", priv->tx_stats[0].cnt);
107 pos += sprintf(buf+pos, "ctrl: %u\n", priv->tx_stats[1].cnt);
108 pos += sprintf(buf+pos, "data: %u\n", priv->tx_stats[2].cnt);
110 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
113 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
114 char __user *user_buf,
115 size_t count, loff_t *ppos) {
117 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
121 pos += sprintf(buf+pos, "mgmt: %u\n", priv->rx_stats[0].cnt);
122 pos += sprintf(buf+pos, "ctrl: %u\n", priv->rx_stats[1].cnt);
123 pos += sprintf(buf+pos, "data: %u\n", priv->rx_stats[2].cnt);
125 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
128 #define BYTE1_MASK 0x000000ff;
129 #define BYTE2_MASK 0x0000ffff;
130 #define BYTE3_MASK 0x00ffffff;
131 static ssize_t iwl_dbgfs_sram_read(struct file *file,
132 char __user *user_buf,
133 size_t count, loff_t *ppos)
140 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
142 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
143 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
145 iwl_grab_nic_access(priv);
146 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
147 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
148 priv->dbgfs->sram_len - i);
162 pos += sprintf(buf+pos, "0x%08x ", val);
164 pos += sprintf(buf+pos, "\n");
165 iwl_release_nic_access(priv);
167 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
171 static ssize_t iwl_dbgfs_sram_write(struct file *file,
172 const char __user *user_buf,
173 size_t count, loff_t *ppos)
175 struct iwl_priv *priv = file->private_data;
180 memset(buf, 0, sizeof(buf));
181 buf_size = min(count, sizeof(buf) - 1);
182 if (copy_from_user(buf, user_buf, buf_size))
185 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
186 priv->dbgfs->sram_offset = offset;
187 priv->dbgfs->sram_len = len;
189 priv->dbgfs->sram_offset = 0;
190 priv->dbgfs->sram_len = 0;
196 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
197 size_t count, loff_t *ppos)
199 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
200 struct iwl4965_station_entry *station;
201 int max_sta = priv->hw_setting.max_stations;
205 /* Add 30 for initial string */
206 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
207 DECLARE_MAC_BUF(mac);
209 buf = kmalloc(bufsz, GFP_KERNEL);
213 pos += sprintf(buf+pos, "num of stations: %d\n\n",
216 for (i = 0; i < max_sta; i++) {
217 station = &priv->stations[i];
219 pos += sprintf(buf+pos, "station %d:\ngeneral data:\n",
221 print_mac(mac, station->sta.sta.addr);
222 pos += sprintf(buf+pos, "id: %u\n",
223 station->sta.sta.sta_id);
224 pos += sprintf(buf+pos, "mode: %u\n",
226 pos += sprintf(buf+pos, "flags: 0x%x\n",
227 station->sta.station_flags_msk);
228 pos += sprintf(buf+pos, "ps_status: %u\n",
231 pos += sprintf(buf+pos, "tid data:\n");
233 pos += sprintf(buf+pos, "seq_num\t\ttxq_id\t");
234 pos += sprintf(buf+pos, "frame_count\twait_for_ba\t");
235 pos += sprintf(buf+pos, "start_idx\tbitmap0\t");
236 pos += sprintf(buf+pos, "bitmap1\trate_n_flags\n");
238 for (j = 0; j < MAX_TID_COUNT; j++) {
239 pos += sprintf(buf+pos, "[%d]:\t\t%u\t",
240 j, station->tid[j].seq_number);
241 pos += sprintf(buf+pos, "%u\t\t%u\t\t%u\t\t",
242 station->tid[j].agg.txq_id,
243 station->tid[j].agg.frame_count,
244 station->tid[j].agg.wait_for_ba);
245 pos += sprintf(buf+pos, "%u\t%llu\t%u\n",
246 station->tid[j].agg.start_idx,
247 (unsigned long long)station->tid[j].agg.bitmap,
248 station->tid[j].agg.rate_n_flags);
250 pos += sprintf(buf+pos, "\n");
254 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
260 DEBUGFS_READ_WRITE_FILE_OPS(sram);
261 DEBUGFS_READ_FILE_OPS(stations);
262 DEBUGFS_READ_FILE_OPS(rx_statistics);
263 DEBUGFS_READ_FILE_OPS(tx_statistics);
266 * Create the debugfs files and directories
269 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
271 struct iwl_debugfs *dbgfs;
273 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
280 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
281 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
285 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
286 DEBUGFS_ADD_FILE(sram, data);
287 DEBUGFS_ADD_FILE(stations, data);
288 DEBUGFS_ADD_FILE(rx_statistics, data);
289 DEBUGFS_ADD_FILE(tx_statistics, data);
294 IWL_ERROR("Can't open the debugfs directory\n");
295 iwl_dbgfs_unregister(priv);
298 EXPORT_SYMBOL(iwl_dbgfs_register);
301 * Remove the debugfs files and directories
304 void iwl_dbgfs_unregister(struct iwl_priv *priv)
309 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
310 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
311 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
312 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
313 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
314 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
318 EXPORT_SYMBOL(iwl_dbgfs_unregister);