blob: f7ec2009cdf9ce93335d1739567f95835f88577e [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
Tomas Winkler445c2df2008-05-15 13:54:16 +080058#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
59 dbgfs->dbgfs_##parent##_files.file_##name = \
60 debugfs_create_bool(#name, 0644, dbgfs->dir_##parent, ptr); \
61 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name)) \
62 goto err; \
63} while (0)
64
Tomas Winkler712b6cf2008-03-12 16:58:52 -070065#define DEBUGFS_REMOVE(name) do { \
66 debugfs_remove(name); \
67 name = NULL; \
68} while (0);
69
70/* file operation */
71#define DEBUGFS_READ_FUNC(name) \
72static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
73 char __user *user_buf, \
74 size_t count, loff_t *ppos);
75
76#define DEBUGFS_WRITE_FUNC(name) \
77static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
78 const char __user *user_buf, \
79 size_t count, loff_t *ppos);
80
81
82static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
83{
84 file->private_data = inode->i_private;
85 return 0;
86}
87
88#define DEBUGFS_READ_FILE_OPS(name) \
89 DEBUGFS_READ_FUNC(name); \
90static const struct file_operations iwl_dbgfs_##name##_ops = { \
91 .read = iwl_dbgfs_##name##_read, \
92 .open = iwl_dbgfs_open_file_generic, \
93};
94
95#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
96 DEBUGFS_READ_FUNC(name); \
97 DEBUGFS_WRITE_FUNC(name); \
98static const struct file_operations iwl_dbgfs_##name##_ops = { \
99 .write = iwl_dbgfs_##name##_write, \
100 .read = iwl_dbgfs_##name##_read, \
101 .open = iwl_dbgfs_open_file_generic, \
102};
103
104
105static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
106 char __user *user_buf,
107 size_t count, loff_t *ppos) {
108
109 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
110 char buf[256];
111 int pos = 0;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700112 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700113
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700114 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
115 priv->tx_stats[0].cnt);
116 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
117 priv->tx_stats[1].cnt);
118 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
119 priv->tx_stats[2].cnt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120
121 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
122}
123
124static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
125 char __user *user_buf,
126 size_t count, loff_t *ppos) {
127
128 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
129 char buf[256];
130 int pos = 0;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700131 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700132
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700133 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
134 priv->rx_stats[0].cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
136 priv->rx_stats[1].cnt);
137 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
138 priv->rx_stats[2].cnt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700139
140 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
141}
142
143#define BYTE1_MASK 0x000000ff;
144#define BYTE2_MASK 0x0000ffff;
145#define BYTE3_MASK 0x00ffffff;
146static ssize_t iwl_dbgfs_sram_read(struct file *file,
147 char __user *user_buf,
148 size_t count, loff_t *ppos)
149{
150 u32 val;
151 char buf[1024];
152 ssize_t ret;
153 int i;
154 int pos = 0;
155 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700156 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700157
158 printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
159 priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
160
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700161 iwl_grab_nic_access(priv);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700162 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700163 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700164 priv->dbgfs->sram_len - i);
165 if (i < 4) {
166 switch (i) {
167 case 1:
168 val &= BYTE1_MASK;
169 break;
170 case 2:
171 val &= BYTE2_MASK;
172 break;
173 case 3:
174 val &= BYTE3_MASK;
175 break;
176 }
177 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700178 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700179 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700180 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700181 iwl_release_nic_access(priv);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700182
183 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
184 return ret;
185}
186
187static ssize_t iwl_dbgfs_sram_write(struct file *file,
188 const char __user *user_buf,
189 size_t count, loff_t *ppos)
190{
191 struct iwl_priv *priv = file->private_data;
192 char buf[64];
193 int buf_size;
194 u32 offset, len;
195
196 memset(buf, 0, sizeof(buf));
197 buf_size = min(count, sizeof(buf) - 1);
198 if (copy_from_user(buf, user_buf, buf_size))
199 return -EFAULT;
200
201 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
202 priv->dbgfs->sram_offset = offset;
203 priv->dbgfs->sram_len = len;
204 } else {
205 priv->dbgfs->sram_offset = 0;
206 priv->dbgfs->sram_len = 0;
207 }
208
209 return count;
210}
211
212static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
213 size_t count, loff_t *ppos)
214{
215 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800216 struct iwl_station_entry *station;
Tomas Winkler5425e492008-04-15 16:01:38 -0700217 int max_sta = priv->hw_params.max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700218 char *buf;
219 int i, j, pos = 0;
220 ssize_t ret;
221 /* Add 30 for initial string */
222 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
223 DECLARE_MAC_BUF(mac);
224
225 buf = kmalloc(bufsz, GFP_KERNEL);
226 if(!buf)
227 return -ENOMEM;
228
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700229 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 priv->num_stations);
231
232 for (i = 0; i < max_sta; i++) {
233 station = &priv->stations[i];
234 if (station->used) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700235 pos += scnprintf(buf + pos, bufsz - pos,
236 "station %d:\ngeneral data:\n", i+1);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700237 print_mac(mac, station->sta.sta.addr);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700238 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700239 station->sta.sta.sta_id);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700240 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700241 station->sta.mode);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700242 pos += scnprintf(buf + pos, bufsz - pos,
243 "flags: 0x%x\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700244 station->sta.station_flags_msk);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700245 pos += scnprintf(buf + pos, bufsz - pos,
246 "ps_status: %u\n", station->ps_status);
247 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
248 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700249 "seq_num\t\ttxq_id");
250#ifdef CONFIG_IWL4965_HT
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700251 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700252 "\tframe_count\twait_for_ba\t");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700253 pos += scnprintf(buf + pos, bufsz - pos,
254 "start_idx\tbitmap0\t");
255 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700256 "bitmap1\trate_n_flags");
257#endif
258 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700259
260 for (j = 0; j < MAX_TID_COUNT; j++) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700261 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700262 "[%d]:\t\t%u", j,
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700263 station->tid[j].seq_number);
David S. Miller344234d2008-04-19 18:09:39 -0700264#ifdef CONFIG_IWL4965_HT
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700265 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700266 "\t%u\t\t%u\t\t%u\t\t",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700267 station->tid[j].agg.txq_id,
268 station->tid[j].agg.frame_count,
269 station->tid[j].agg.wait_for_ba);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700270 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700271 "%u\t%llu\t%u",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700272 station->tid[j].agg.start_idx,
John W. Linville16788592008-04-01 20:59:32 -0400273 (unsigned long long)station->tid[j].agg.bitmap,
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700274 station->tid[j].agg.rate_n_flags);
David S. Miller344234d2008-04-19 18:09:39 -0700275#endif
276 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700277 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700278 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700279 }
280 }
281
282 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
283 kfree(buf);
284 return ret;
285}
286
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800287static ssize_t iwl_dbgfs_eeprom_read(struct file *file,
288 char __user *user_buf,
289 size_t count,
290 loff_t *ppos)
291{
292 ssize_t ret;
293 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
294 int pos = 0, ofs = 0, buf_size = 0;
295 const u8 *ptr;
296 char *buf;
297 size_t eeprom_len = priv->cfg->eeprom_size;
298 buf_size = 4 * eeprom_len + 256;
299
300 if (eeprom_len % 16) {
301 IWL_ERROR("EEPROM size is not multiple of 16.\n");
302 return -ENODATA;
303 }
304
305 /* 4 characters for byte 0xYY */
306 buf = kzalloc(buf_size, GFP_KERNEL);
307 if (!buf) {
308 IWL_ERROR("Can not allocate Buffer\n");
309 return -ENOMEM;
310 }
311
312 ptr = priv->eeprom;
313 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
314 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
315 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
316 buf_size - pos, 0);
317 pos += strlen(buf);
318 if (buf_size - pos > 0)
319 buf[pos++] = '\n';
320 }
321
322 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
323 kfree(buf);
324 return ret;
325}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700326
327DEBUGFS_READ_WRITE_FILE_OPS(sram);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800328DEBUGFS_READ_FILE_OPS(eeprom);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700329DEBUGFS_READ_FILE_OPS(stations);
330DEBUGFS_READ_FILE_OPS(rx_statistics);
331DEBUGFS_READ_FILE_OPS(tx_statistics);
332
333/*
334 * Create the debugfs files and directories
335 *
336 */
337int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
338{
339 struct iwl_debugfs *dbgfs;
340
341 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
342 if (!dbgfs) {
343 goto err;
344 }
345
346 priv->dbgfs = dbgfs;
347 dbgfs->name = name;
348 dbgfs->dir_drv = debugfs_create_dir(name, NULL);
349 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)){
350 goto err;
351 }
352
353 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800354 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800355 DEBUGFS_ADD_FILE(eeprom, data);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700356 DEBUGFS_ADD_FILE(sram, data);
357 DEBUGFS_ADD_FILE(stations, data);
358 DEBUGFS_ADD_FILE(rx_statistics, data);
359 DEBUGFS_ADD_FILE(tx_statistics, data);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800360#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
361 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
362 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
363 &priv->disable_chain_noise_cal);
364#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700365 return 0;
366
367err:
368 IWL_ERROR("Can't open the debugfs directory\n");
369 iwl_dbgfs_unregister(priv);
370 return -ENOENT;
371}
372EXPORT_SYMBOL(iwl_dbgfs_register);
373
374/**
375 * Remove the debugfs files and directories
376 *
377 */
378void iwl_dbgfs_unregister(struct iwl_priv *priv)
379{
380 if (!(priv->dbgfs))
381 return;
382
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800383 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_eeprom);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700384 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
385 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
386 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
387 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
388 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800389#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
390 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
391 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
392#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
393 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700394 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
395 kfree(priv->dbgfs);
396 priv->dbgfs = NULL;
397}
398EXPORT_SYMBOL(iwl_dbgfs_unregister);
399
400
Tomas Winkler445c2df2008-05-15 13:54:16 +0800401