Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/hskinnemoen...
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-debugfs.c
1 /******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
6 *
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.
10 *
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.
15 *
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,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Tomas Winkler <tomas.winkler@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/debugfs.h>
32
33 #include <linux/ieee80211.h>
34 #include <net/mac80211.h>
35
36
37 #include "iwl-4965.h"
38 #include "iwl-debug.h"
39 #include "iwl-core.h"
40 #include "iwl-io.h"
41
42
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)) \
47 goto err; \
48 } while (0)
49
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)) \
55 goto err; \
56 } while (0)
57
58 #define DEBUGFS_REMOVE(name) do { \
59 debugfs_remove(name); \
60 name = NULL; \
61 } while (0);
62
63 /* file operation */
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);
68
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);
73
74
75 static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
76 {
77 file->private_data = inode->i_private;
78 return 0;
79 }
80
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, \
86 };
87
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, \
95 };
96
97
98 static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
99 char __user *user_buf,
100 size_t count, loff_t *ppos) {
101
102 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
103 char buf[256];
104 int pos = 0;
105 const size_t bufsz = sizeof(buf);
106
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);
113
114 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
115 }
116
117 static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
118 char __user *user_buf,
119 size_t count, loff_t *ppos) {
120
121 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
122 char buf[256];
123 int pos = 0;
124 const size_t bufsz = sizeof(buf);
125
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);
132
133 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
134 }
135
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)
142 {
143 u32 val;
144 char buf[1024];
145 ssize_t ret;
146 int i;
147 int pos = 0;
148 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
149 const size_t bufsz = sizeof(buf);
150
151 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
152 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
153
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);
158 if (i < 4) {
159 switch (i) {
160 case 1:
161 val &= BYTE1_MASK;
162 break;
163 case 2:
164 val &= BYTE2_MASK;
165 break;
166 case 3:
167 val &= BYTE3_MASK;
168 break;
169 }
170 }
171 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
172 }
173 pos += scnprintf(buf + pos, bufsz - pos, "\n");
174 iwl_release_nic_access(priv);
175
176 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
177 return ret;
178 }
179
180 static ssize_t iwl_dbgfs_sram_write(struct file *file,
181 const char __user *user_buf,
182 size_t count, loff_t *ppos)
183 {
184 struct iwl_priv *priv = file->private_data;
185 char buf[64];
186 int buf_size;
187 u32 offset, len;
188
189 memset(buf, 0, sizeof(buf));
190 buf_size = min(count, sizeof(buf) - 1);
191 if (copy_from_user(buf, user_buf, buf_size))
192 return -EFAULT;
193
194 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
195 priv->dbgfs->sram_offset = offset;
196 priv->dbgfs->sram_len = len;
197 } else {
198 priv->dbgfs->sram_offset = 0;
199 priv->dbgfs->sram_len = 0;
200 }
201
202 return count;
203 }
204
205 static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
206 size_t count, loff_t *ppos)
207 {
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;
211 char *buf;
212 int i, j, pos = 0;
213 ssize_t ret;
214 /* Add 30 for initial string */
215 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
216 DECLARE_MAC_BUF(mac);
217
218 buf = kmalloc(bufsz, GFP_KERNEL);
219 if(!buf)
220 return -ENOMEM;
221
222 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
223 priv->num_stations);
224
225 for (i = 0; i < max_sta; i++) {
226 station = &priv->stations[i];
227 if (station->used) {
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",
234 station->sta.mode);
235 pos += scnprintf(buf + pos, bufsz - pos,
236 "flags: 0x%x\n",
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\t");
243 pos += scnprintf(buf + pos, bufsz - pos,
244 "frame_count\twait_for_ba\t");
245 pos += scnprintf(buf + pos, bufsz - pos,
246 "start_idx\tbitmap0\t");
247 pos += scnprintf(buf + pos, bufsz - pos,
248 "bitmap1\trate_n_flags\n");
249
250 for (j = 0; j < MAX_TID_COUNT; j++) {
251 pos += scnprintf(buf + pos, bufsz - pos,
252 "[%d]:\t\t%u\t", j,
253 station->tid[j].seq_number);
254 pos += scnprintf(buf + pos, bufsz - pos,
255 "%u\t\t%u\t\t%u\t\t",
256 station->tid[j].agg.txq_id,
257 station->tid[j].agg.frame_count,
258 station->tid[j].agg.wait_for_ba);
259 pos += scnprintf(buf + pos, bufsz - pos,
260 "%u\t%llu\t%u\n",
261 station->tid[j].agg.start_idx,
262 (unsigned long long)station->tid[j].agg.bitmap,
263 station->tid[j].agg.rate_n_flags);
264 }
265 pos += scnprintf(buf + pos, bufsz - pos, "\n");
266 }
267 }
268
269 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
270 kfree(buf);
271 return ret;
272 }
273
274
275 DEBUGFS_READ_WRITE_FILE_OPS(sram);
276 DEBUGFS_READ_FILE_OPS(stations);
277 DEBUGFS_READ_FILE_OPS(rx_statistics);
278 DEBUGFS_READ_FILE_OPS(tx_statistics);
279
280 /*
281 * Create the debugfs files and directories
282 *
283 */
284 int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
285 {
286 struct iwl_debugfs *dbgfs;
287
288 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
289 if (!dbgfs) {
290 goto err;
291 }
292
293 priv->dbgfs = dbgfs;
294 dbgfs->name = name;
295 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
296 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
297 goto err;
298 }
299
300 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
301 DEBUGFS_ADD_FILE(sram, data);
302 DEBUGFS_ADD_FILE(stations, data);
303 DEBUGFS_ADD_FILE(rx_statistics, data);
304 DEBUGFS_ADD_FILE(tx_statistics, data);
305
306 return 0;
307
308 err:
309 IWL_ERROR("Can't open the debugfs directory\n");
310 iwl_dbgfs_unregister(priv);
311 return -ENOENT;
312 }
313 EXPORT_SYMBOL(iwl_dbgfs_register);
314
315 /**
316 * Remove the debugfs files and directories
317 *
318 */
319 void iwl_dbgfs_unregister(struct iwl_priv *priv)
320 {
321 if (!(priv->dbgfs))
322 return;
323
324 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
325 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
326 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
327 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
328 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
329 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
330 kfree(priv->dbgfs);
331 priv->dbgfs = NULL;
332 }
333 EXPORT_SYMBOL(iwl_dbgfs_unregister);
334
335
This page took 0.119106 seconds and 6 git commands to generate.