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"
39 #include "iwl-4965-io.h"
42 /* create and remove of files */
43 #define DEBUGFS_ADD_DIR(name, parent) do { \
44 dbgfs->dir_##name = debugfs_create_dir(#name, parent); \
45 if (!(dbgfs->dir_##name)) \
49 #define DEBUGFS_ADD_FILE(name, parent) do { \
50 dbgfs->dbgfs_##parent##_files.file_##name = \
51 debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
52 &iwl_dbgfs_##name##_ops); \
53 if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
57 #define DEBUGFS_REMOVE(name) do { \
58 debugfs_remove(name); \
63 #define DEBUGFS_READ_FUNC(name) \
64 static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
65 char __user *user_buf, \
66 size_t count, loff_t *ppos);
68 #define DEBUGFS_WRITE_FUNC(name) \
69 static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
70 const char __user *user_buf, \
71 size_t count, loff_t *ppos);
74 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
76 file->private_data = inode->i_private;
80 #define DEBUGFS_READ_FILE_OPS(name) \
81 DEBUGFS_READ_FUNC(name); \
82 static const struct file_operations iwl_dbgfs_##name##_ops = { \
83 .read = iwl_dbgfs_##name##_read, \
84 .open = iwl_dbgfs_open_file_generic, \
87 #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
88 DEBUGFS_READ_FUNC(name); \
89 DEBUGFS_WRITE_FUNC(name); \
90 static const struct file_operations iwl_dbgfs_##name##_ops = { \
91 .write = iwl_dbgfs_##name##_write, \
92 .read = iwl_dbgfs_##name##_read, \
93 .open = iwl_dbgfs_open_file_generic, \
97 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
98 char __user *user_buf,
99 size_t count, loff_t *ppos) {
101 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
105 pos += sprintf(buf+pos, "mgmt: %u\n", priv->tx_stats[0].cnt);
106 pos += sprintf(buf+pos, "ctrl: %u\n", priv->tx_stats[1].cnt);
107 pos += sprintf(buf+pos, "data: %u\n", priv->tx_stats[2].cnt);
109 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
112 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
113 char __user *user_buf,
114 size_t count, loff_t *ppos) {
116 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
120 pos += sprintf(buf+pos, "mgmt: %u\n", priv->rx_stats[0].cnt);
121 pos += sprintf(buf+pos, "ctrl: %u\n", priv->rx_stats[1].cnt);
122 pos += sprintf(buf+pos, "data: %u\n", priv->rx_stats[2].cnt);
124 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
127 #define BYTE1_MASK 0x000000ff;
128 #define BYTE2_MASK 0x0000ffff;
129 #define BYTE3_MASK 0x00ffffff;
130 static ssize_t iwl_dbgfs_sram_read(struct file *file,
131 char __user *user_buf,
132 size_t count, loff_t *ppos)
139 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
141 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
142 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
144 iwl4965_grab_nic_access(priv);
145 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
146 val = iwl4965_read_targ_mem(priv, priv->dbgfs->sram_offset + \
147 priv->dbgfs->sram_len - i);
161 pos += sprintf(buf+pos, "0x%08x ", val);
163 pos += sprintf(buf+pos, "\n");
164 iwl4965_release_nic_access(priv);
166 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
170 static ssize_t iwl_dbgfs_sram_write(struct file *file,
171 const char __user *user_buf,
172 size_t count, loff_t *ppos)
174 struct iwl_priv *priv = file->private_data;
179 memset(buf, 0, sizeof(buf));
180 buf_size = min(count, sizeof(buf) - 1);
181 if (copy_from_user(buf, user_buf, buf_size))
184 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
185 priv->dbgfs->sram_offset = offset;
186 priv->dbgfs->sram_len = len;
188 priv->dbgfs->sram_offset = 0;
189 priv->dbgfs->sram_len = 0;
195 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos)
198 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
199 struct iwl4965_station_entry *station;
200 int max_sta = priv->hw_setting.max_stations;
204 /* Add 30 for initial string */
205 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
206 DECLARE_MAC_BUF(mac);
208 buf = kmalloc(bufsz, GFP_KERNEL);
212 pos += sprintf(buf+pos, "num of stations: %d\n\n",
215 for (i = 0; i < max_sta; i++) {
216 station = &priv->stations[i];
218 pos += sprintf(buf+pos, "station %d:\ngeneral data:\n",
220 print_mac(mac, station->sta.sta.addr);
221 pos += sprintf(buf+pos, "id: %u\n",
222 station->sta.sta.sta_id);
223 pos += sprintf(buf+pos, "mode: %u\n",
225 pos += sprintf(buf+pos, "flags: 0x%x\n",
226 station->sta.station_flags_msk);
227 pos += sprintf(buf+pos, "ps_status: %u\n",
230 pos += sprintf(buf+pos, "tid data:\n");
232 pos += sprintf(buf+pos, "seq_num\t\ttxq_id\t");
233 pos += sprintf(buf+pos, "frame_count\twait_for_ba\t");
234 pos += sprintf(buf+pos, "start_idx\tbitmap0\t");
235 pos += sprintf(buf+pos, "bitmap1\trate_n_flags\n");
237 for (j = 0; j < MAX_TID_COUNT; j++) {
238 pos += sprintf(buf+pos, "[%d]:\t\t%u\t",
239 j, station->tid[j].seq_number);
240 pos += sprintf(buf+pos, "%u\t\t%u\t\t%u\t\t",
241 station->tid[j].agg.txq_id,
242 station->tid[j].agg.frame_count,
243 station->tid[j].agg.wait_for_ba);
244 pos += sprintf(buf+pos, "%u\t%llu\t%u\n",
245 station->tid[j].agg.start_idx,
246 station->tid[j].agg.bitmap,
247 station->tid[j].agg.rate_n_flags);
249 pos += sprintf(buf+pos, "\n");
253 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
259 DEBUGFS_READ_WRITE_FILE_OPS(sram);
260 DEBUGFS_READ_FILE_OPS(stations);
261 DEBUGFS_READ_FILE_OPS(rx_statistics);
262 DEBUGFS_READ_FILE_OPS(tx_statistics);
265 * Create the debugfs files and directories
268 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
270 struct iwl_debugfs *dbgfs;
272 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
279 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
280 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
284 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
285 DEBUGFS_ADD_FILE(sram, data);
286 DEBUGFS_ADD_FILE(stations, data);
287 DEBUGFS_ADD_FILE(rx_statistics, data);
288 DEBUGFS_ADD_FILE(tx_statistics, data);
293 IWL_ERROR("Can't open the debugfs directory\n");
294 iwl_dbgfs_unregister(priv);
297 EXPORT_SYMBOL(iwl_dbgfs_register);
300 * Remove the debugfs files and directories
303 void iwl_dbgfs_unregister(struct iwl_priv *priv)
308 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
309 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
310 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
311 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
312 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
313 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
317 EXPORT_SYMBOL(iwl_dbgfs_unregister);