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;
105 const size_t bufsz = sizeof(buf);
107 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
108 priv->tx_stats[0].cnt);
109 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
110 priv->tx_stats[1].cnt);
111 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
112 priv->tx_stats[2].cnt);
114 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
117 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
118 char __user *user_buf,
119 size_t count, loff_t *ppos) {
121 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
124 const size_t bufsz = sizeof(buf);
126 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
127 priv->rx_stats[0].cnt);
128 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
129 priv->rx_stats[1].cnt);
130 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
131 priv->rx_stats[2].cnt);
133 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
136 #define BYTE1_MASK 0x000000ff;
137 #define BYTE2_MASK 0x0000ffff;
138 #define BYTE3_MASK 0x00ffffff;
139 static ssize_t iwl_dbgfs_sram_read(struct file *file,
140 char __user *user_buf,
141 size_t count, loff_t *ppos)
148 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
149 const size_t bufsz = sizeof(buf);
151 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
152 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
154 iwl_grab_nic_access(priv);
155 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
156 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
157 priv->dbgfs->sram_len - i);
171 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
173 pos += scnprintf(buf + pos, bufsz - pos, "\n");
174 iwl_release_nic_access(priv);
176 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
180 static ssize_t iwl_dbgfs_sram_write(struct file *file,
181 const char __user *user_buf,
182 size_t count, loff_t *ppos)
184 struct iwl_priv *priv = file->private_data;
189 memset(buf, 0, sizeof(buf));
190 buf_size = min(count, sizeof(buf) - 1);
191 if (copy_from_user(buf, user_buf, buf_size))
194 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
195 priv->dbgfs->sram_offset = offset;
196 priv->dbgfs->sram_len = len;
198 priv->dbgfs->sram_offset = 0;
199 priv->dbgfs->sram_len = 0;
205 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
206 size_t count, loff_t *ppos)
208 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
209 struct iwl4965_station_entry *station;
210 int max_sta = priv->hw_params.max_stations;
214 /* Add 30 for initial string */
215 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
216 DECLARE_MAC_BUF(mac);
218 buf = kmalloc(bufsz, GFP_KERNEL);
222 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
225 for (i = 0; i < max_sta; i++) {
226 station = &priv->stations[i];
228 pos += scnprintf(buf + pos, bufsz - pos,
229 "station %d:\ngeneral data:\n", i+1);
230 print_mac(mac, station->sta.sta.addr);
231 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
232 station->sta.sta.sta_id);
233 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
235 pos += scnprintf(buf + pos, bufsz - pos,
237 station->sta.station_flags_msk);
238 pos += scnprintf(buf + pos, bufsz - pos,
239 "ps_status: %u\n", station->ps_status);
240 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
241 pos += scnprintf(buf + pos, bufsz - pos,
242 "seq_num\t\ttxq_id");
243 #ifdef CONFIG_IWL4965_HT
244 pos += scnprintf(buf + pos, bufsz - pos,
245 "\tframe_count\twait_for_ba\t");
246 pos += scnprintf(buf + pos, bufsz - pos,
247 "start_idx\tbitmap0\t");
248 pos += scnprintf(buf + pos, bufsz - pos,
249 "bitmap1\trate_n_flags");
251 pos += scnprintf(buf + pos, bufsz - pos, "\n");
253 for (j = 0; j < MAX_TID_COUNT; j++) {
254 pos += scnprintf(buf + pos, bufsz - pos,
256 station->tid[j].seq_number);
257 #ifdef CONFIG_IWL4965_HT
258 pos += scnprintf(buf + pos, bufsz - pos,
259 "\t%u\t\t%u\t\t%u\t\t",
260 station->tid[j].agg.txq_id,
261 station->tid[j].agg.frame_count,
262 station->tid[j].agg.wait_for_ba);
263 pos += scnprintf(buf + pos, bufsz - pos,
265 station->tid[j].agg.start_idx,
266 (unsigned long long)station->tid[j].agg.bitmap,
267 station->tid[j].agg.rate_n_flags);
269 pos += scnprintf(buf + pos, bufsz - pos, "\n");
271 pos += scnprintf(buf + pos, bufsz - pos, "\n");
275 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
281 DEBUGFS_READ_WRITE_FILE_OPS(sram);
282 DEBUGFS_READ_FILE_OPS(stations);
283 DEBUGFS_READ_FILE_OPS(rx_statistics);
284 DEBUGFS_READ_FILE_OPS(tx_statistics);
287 * Create the debugfs files and directories
290 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
292 struct iwl_debugfs *dbgfs;
294 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
301 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
302 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
306 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
307 DEBUGFS_ADD_FILE(sram, data);
308 DEBUGFS_ADD_FILE(stations, data);
309 DEBUGFS_ADD_FILE(rx_statistics, data);
310 DEBUGFS_ADD_FILE(tx_statistics, data);
315 IWL_ERROR("Can't open the debugfs directory\n");
316 iwl_dbgfs_unregister(priv);
319 EXPORT_SYMBOL(iwl_dbgfs_register);
322 * Remove the debugfs files and directories
325 void iwl_dbgfs_unregister(struct iwl_priv *priv)
330 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
331 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
332 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
333 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
334 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
335 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
339 EXPORT_SYMBOL(iwl_dbgfs_unregister);