blob: ad25806dfaf1862aa690a7bf37c067d0b27443b0 [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
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
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070037#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070038#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070039#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070040#include "iwl-io.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070041
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) \
65static 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) \
70static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
71 const char __user *user_buf, \
72 size_t count, loff_t *ppos);
73
74
75static 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); \
83static 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); \
91static 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
98static 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;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700105 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700106
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700107 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);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700113
114 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
115}
116
117static 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;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700124 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700125
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700126 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);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700132
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;
139static 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;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700149 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700150
151 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
152 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
153
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700154 iwl_grab_nic_access(priv);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700155 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700156 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700157 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 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700171 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700172 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700173 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700174 iwl_release_nic_access(priv);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700175
176 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
177 return ret;
178}
179
180static 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
205static 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;
Tomas Winkler6def9762008-05-05 10:22:31 +0800209 struct iwl_station_entry *station;
Tomas Winkler5425e492008-04-15 16:01:38 -0700210 int max_sta = priv->hw_params.max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700211 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
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700222 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700223 priv->num_stations);
224
225 for (i = 0; i < max_sta; i++) {
226 station = &priv->stations[i];
227 if (station->used) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700228 pos += scnprintf(buf + pos, bufsz - pos,
229 "station %d:\ngeneral data:\n", i+1);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 print_mac(mac, station->sta.sta.addr);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700231 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700232 station->sta.sta.sta_id);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700233 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700234 station->sta.mode);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700235 pos += scnprintf(buf + pos, bufsz - pos,
236 "flags: 0x%x\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700237 station->sta.station_flags_msk);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700238 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,
David S. Miller344234d2008-04-19 18:09:39 -0700242 "seq_num\t\ttxq_id");
243#ifdef CONFIG_IWL4965_HT
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700244 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700245 "\tframe_count\twait_for_ba\t");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700246 pos += scnprintf(buf + pos, bufsz - pos,
247 "start_idx\tbitmap0\t");
248 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700249 "bitmap1\trate_n_flags");
250#endif
251 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700252
253 for (j = 0; j < MAX_TID_COUNT; j++) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700254 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700255 "[%d]:\t\t%u", j,
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700256 station->tid[j].seq_number);
David S. Miller344234d2008-04-19 18:09:39 -0700257#ifdef CONFIG_IWL4965_HT
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700258 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700259 "\t%u\t\t%u\t\t%u\t\t",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700260 station->tid[j].agg.txq_id,
261 station->tid[j].agg.frame_count,
262 station->tid[j].agg.wait_for_ba);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700263 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700264 "%u\t%llu\t%u",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700265 station->tid[j].agg.start_idx,
John W. Linville16788592008-04-01 20:59:32 -0400266 (unsigned long long)station->tid[j].agg.bitmap,
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700267 station->tid[j].agg.rate_n_flags);
David S. Miller344234d2008-04-19 18:09:39 -0700268#endif
269 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700270 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700271 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700272 }
273 }
274
275 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
276 kfree(buf);
277 return ret;
278}
279
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800280static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
281 char __user *user_buf,
282 size_t count,
283 loff_t *ppos)
284{
285 ssize_t ret;
286 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
287 int pos = 0, ofs = 0, buf_size = 0;
288 const u8 *ptr;
289 char *buf;
290 size_t eeprom_len = priv->cfg->eeprom_size;
291 buf_size = 4 * eeprom_len + 256;
292
293 if (eeprom_len % 16) {
294 IWL_ERROR("EEPROM size is not multiple of 16.\n");
295 return -ENODATA;
296 }
297
298 /* 4 characters for byte 0xYY */
299 buf = kzalloc(buf_size, GFP_KERNEL);
300 if (!buf) {
301 IWL_ERROR("Can not allocate Buffer\n");
302 return -ENOMEM;
303 }
304
305 ptr = priv->eeprom;
306 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
307 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
308 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
309 buf_size - pos, 0);
310 pos += strlen(buf);
311 if (buf_size - pos > 0)
312 buf[pos++] = '\n';
313 }
314
315 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
316 kfree(buf);
317 return ret;
318}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700319
320DEBUGFS_READ_WRITE_FILE_OPS(sram);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800321DEBUGFS_READ_FILE_OPS(eeprom);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700322DEBUGFS_READ_FILE_OPS(stations);
323DEBUGFS_READ_FILE_OPS(rx_statistics);
324DEBUGFS_READ_FILE_OPS(tx_statistics);
325
326/*
327 * Create the debugfs files and directories
328 *
329 */
330int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
331{
332 struct iwl_debugfs *dbgfs;
333
334 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
335 if (!dbgfs) {
336 goto err;
337 }
338
339 priv->dbgfs = dbgfs;
340 dbgfs->name = name;
341 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
342 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
343 goto err;
344 }
345
346 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800347 DEBUGFS_ADD_FILE(eeprom, data);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700348 DEBUGFS_ADD_FILE(sram, data);
349 DEBUGFS_ADD_FILE(stations, data);
350 DEBUGFS_ADD_FILE(rx_statistics, data);
351 DEBUGFS_ADD_FILE(tx_statistics, data);
352
353 return 0;
354
355err:
356 IWL_ERROR("Can't open the debugfs directory\n");
357 iwl_dbgfs_unregister(priv);
358 return -ENOENT;
359}
360EXPORT_SYMBOL(iwl_dbgfs_register);
361
362/**
363 * Remove the debugfs files and directories
364 *
365 */
366void iwl_dbgfs_unregister(struct iwl_priv *priv)
367{
368 if (!(priv->dbgfs))
369 return;
370
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800371 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700372 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
373 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
374 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
375 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
376 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
377 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
378 kfree(priv->dbgfs);
379 priv->dbgfs = NULL;
380}
381EXPORT_SYMBOL(iwl_dbgfs_unregister);
382
383