blob: af70229144b337fe88ef4642e4d6df14b54ec0ae [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Reinette Chatre01f81622009-01-08 10:20:02 -08005 * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
Tomas Winkler712b6cf2008-03-12 16:58:52 -07006 *
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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070026 * 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); \
Zhaolei9b240012008-10-22 17:06:12 +080061 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
62 || !dbgfs->dbgfs_##parent##_files.file_##name) \
Tomas Winkler445c2df2008-05-15 13:54:16 +080063 goto err; \
64} while (0)
65
Winkler, Tomas2ddfa122008-12-22 11:31:20 +080066#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
67 dbgfs->dbgfs_##parent##_files.file_##name = \
68 debugfs_create_x32(#name, 0444, dbgfs->dir_##parent, ptr); \
69 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
70 || !dbgfs->dbgfs_##parent##_files.file_##name) \
71 goto err; \
72} while (0)
73
Tomas Winkler712b6cf2008-03-12 16:58:52 -070074#define DEBUGFS_REMOVE(name) do { \
75 debugfs_remove(name); \
76 name = NULL; \
77} while (0);
78
79/* file operation */
80#define DEBUGFS_READ_FUNC(name) \
81static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
82 char __user *user_buf, \
83 size_t count, loff_t *ppos);
84
85#define DEBUGFS_WRITE_FUNC(name) \
86static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
87 const char __user *user_buf, \
88 size_t count, loff_t *ppos);
89
90
91static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
92{
93 file->private_data = inode->i_private;
94 return 0;
95}
96
97#define DEBUGFS_READ_FILE_OPS(name) \
98 DEBUGFS_READ_FUNC(name); \
99static const struct file_operations iwl_dbgfs_##name##_ops = { \
100 .read = iwl_dbgfs_##name##_read, \
101 .open = iwl_dbgfs_open_file_generic, \
102};
103
Ester Kummer189a2b52008-05-15 13:54:18 +0800104#define DEBUGFS_WRITE_FILE_OPS(name) \
105 DEBUGFS_WRITE_FUNC(name); \
106static const struct file_operations iwl_dbgfs_##name##_ops = { \
107 .write = iwl_dbgfs_##name##_write, \
108 .open = iwl_dbgfs_open_file_generic, \
109};
110
111
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700112#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
113 DEBUGFS_READ_FUNC(name); \
114 DEBUGFS_WRITE_FUNC(name); \
115static const struct file_operations iwl_dbgfs_##name##_ops = { \
116 .write = iwl_dbgfs_##name##_write, \
117 .read = iwl_dbgfs_##name##_read, \
118 .open = iwl_dbgfs_open_file_generic, \
119};
120
121
122static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
123 char __user *user_buf,
124 size_t count, loff_t *ppos) {
125
126 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
127 char buf[256];
128 int pos = 0;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700129 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700130
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700131 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
132 priv->tx_stats[0].cnt);
133 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
134 priv->tx_stats[1].cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
136 priv->tx_stats[2].cnt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700137
138 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
139}
140
141static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
142 char __user *user_buf,
143 size_t count, loff_t *ppos) {
144
145 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
146 char buf[256];
147 int pos = 0;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700148 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700149
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700150 pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
151 priv->rx_stats[0].cnt);
152 pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
153 priv->rx_stats[1].cnt);
154 pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
155 priv->rx_stats[2].cnt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700156
157 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
158}
159
160#define BYTE1_MASK 0x000000ff;
161#define BYTE2_MASK 0x0000ffff;
162#define BYTE3_MASK 0x00ffffff;
163static ssize_t iwl_dbgfs_sram_read(struct file *file,
164 char __user *user_buf,
165 size_t count, loff_t *ppos)
166{
167 u32 val;
168 char buf[1024];
169 ssize_t ret;
170 int i;
171 int pos = 0;
172 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700173 const size_t bufsz = sizeof(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700174
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700175 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700176 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700177 priv->dbgfs->sram_len - i);
178 if (i < 4) {
179 switch (i) {
180 case 1:
181 val &= BYTE1_MASK;
182 break;
183 case 2:
184 val &= BYTE2_MASK;
185 break;
186 case 3:
187 val &= BYTE3_MASK;
188 break;
189 }
190 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700191 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700192 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700193 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700194
195 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
196 return ret;
197}
198
199static ssize_t iwl_dbgfs_sram_write(struct file *file,
200 const char __user *user_buf,
201 size_t count, loff_t *ppos)
202{
203 struct iwl_priv *priv = file->private_data;
204 char buf[64];
205 int buf_size;
206 u32 offset, len;
207
208 memset(buf, 0, sizeof(buf));
209 buf_size = min(count, sizeof(buf) - 1);
210 if (copy_from_user(buf, user_buf, buf_size))
211 return -EFAULT;
212
213 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
214 priv->dbgfs->sram_offset = offset;
215 priv->dbgfs->sram_len = len;
216 } else {
217 priv->dbgfs->sram_offset = 0;
218 priv->dbgfs->sram_len = 0;
219 }
220
221 return count;
222}
223
224static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
225 size_t count, loff_t *ppos)
226{
227 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800228 struct iwl_station_entry *station;
Tomas Winkler5425e492008-04-15 16:01:38 -0700229 int max_sta = priv->hw_params.max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 char *buf;
231 int i, j, pos = 0;
232 ssize_t ret;
233 /* Add 30 for initial string */
234 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700235
236 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300237 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700238 return -ENOMEM;
239
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700240 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700241 priv->num_stations);
242
243 for (i = 0; i < max_sta; i++) {
244 station = &priv->stations[i];
245 if (station->used) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700246 pos += scnprintf(buf + pos, bufsz - pos,
247 "station %d:\ngeneral data:\n", i+1);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700248 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700249 station->sta.sta.sta_id);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700250 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700251 station->sta.mode);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700252 pos += scnprintf(buf + pos, bufsz - pos,
253 "flags: 0x%x\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700254 station->sta.station_flags_msk);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700255 pos += scnprintf(buf + pos, bufsz - pos,
256 "ps_status: %u\n", station->ps_status);
257 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
258 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700259 "seq_num\t\ttxq_id");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700260 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700261 "\tframe_count\twait_for_ba\t");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700262 pos += scnprintf(buf + pos, bufsz - pos,
263 "start_idx\tbitmap0\t");
264 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700265 "bitmap1\trate_n_flags");
David S. Miller344234d2008-04-19 18:09:39 -0700266 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700267
268 for (j = 0; j < MAX_TID_COUNT; j++) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700269 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700270 "[%d]:\t\t%u", j,
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700271 station->tid[j].seq_number);
272 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700273 "\t%u\t\t%u\t\t%u\t\t",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700274 station->tid[j].agg.txq_id,
275 station->tid[j].agg.frame_count,
276 station->tid[j].agg.wait_for_ba);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700277 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700278 "%u\t%llu\t%u",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700279 station->tid[j].agg.start_idx,
John W. Linville16788592008-04-01 20:59:32 -0400280 (unsigned long long)station->tid[j].agg.bitmap,
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700281 station->tid[j].agg.rate_n_flags);
David S. Miller344234d2008-04-19 18:09:39 -0700282 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700283 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700284 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700285 }
286 }
287
288 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
289 kfree(buf);
290 return ret;
291}
292
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700293static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800294 char __user *user_buf,
295 size_t count,
296 loff_t *ppos)
297{
298 ssize_t ret;
299 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
300 int pos = 0, ofs = 0, buf_size = 0;
301 const u8 *ptr;
302 char *buf;
303 size_t eeprom_len = priv->cfg->eeprom_size;
304 buf_size = 4 * eeprom_len + 256;
305
306 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700307 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800308 return -ENODATA;
309 }
310
311 /* 4 characters for byte 0xYY */
312 buf = kzalloc(buf_size, GFP_KERNEL);
313 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800314 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800315 return -ENOMEM;
316 }
317
318 ptr = priv->eeprom;
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700319 if (!ptr) {
320 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
321 return -ENOMEM;
322 }
323 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s\n",
324 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
325 ? "OTP" : "EEPROM");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800326 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
327 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
328 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
329 buf_size - pos, 0);
330 pos += strlen(buf);
331 if (buf_size - pos > 0)
332 buf[pos++] = '\n';
333 }
334
335 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
336 kfree(buf);
337 return ret;
338}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700339
Ester Kummer189a2b52008-05-15 13:54:18 +0800340static ssize_t iwl_dbgfs_log_event_write(struct file *file,
341 const char __user *user_buf,
342 size_t count, loff_t *ppos)
343{
344 struct iwl_priv *priv = file->private_data;
345 u32 event_log_flag;
346 char buf[8];
347 int buf_size;
348
349 memset(buf, 0, sizeof(buf));
350 buf_size = min(count, sizeof(buf) - 1);
351 if (copy_from_user(buf, user_buf, buf_size))
352 return -EFAULT;
353 if (sscanf(buf, "%d", &event_log_flag) != 1)
354 return -EFAULT;
355 if (event_log_flag == 1)
356 iwl_dump_nic_event_log(priv);
357
358 return count;
359}
360
Winkler, Tomasd366df52008-12-02 12:14:01 -0800361
362
363static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
364 size_t count, loff_t *ppos)
365{
366 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
367 struct ieee80211_channel *channels = NULL;
368 const struct ieee80211_supported_band *supp_band = NULL;
369 int pos = 0, i, bufsz = PAGE_SIZE;
370 char *buf;
371 ssize_t ret;
372
373 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
374 return -EAGAIN;
375
376 buf = kzalloc(bufsz, GFP_KERNEL);
377 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800378 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800379 return -ENOMEM;
380 }
381
382 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700383 if (supp_band) {
384 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800385
Winkler, Tomasd366df52008-12-02 12:14:01 -0800386 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700387 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
388 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800389
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700390 for (i = 0; i < supp_band->n_channels; i++)
391 pos += scnprintf(buf + pos, bufsz - pos,
392 "%d: %ddBm: BSS%s%s, %s.\n",
393 ieee80211_frequency_to_channel(
394 channels[i].center_freq),
395 channels[i].max_power,
396 channels[i].flags & IEEE80211_CHAN_RADAR ?
397 " (IEEE 802.11h required)" : "",
398 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
399 || (channels[i].flags &
400 IEEE80211_CHAN_RADAR)) ? "" :
401 ", IBSS",
402 channels[i].flags &
403 IEEE80211_CHAN_PASSIVE_SCAN ?
404 "passive only" : "active/passive");
405 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800406 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700407 if (supp_band) {
408 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800409
Winkler, Tomasd366df52008-12-02 12:14:01 -0800410 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700411 "Displaying %d channels in 5.2GHz band (802.11a)\n",
412 supp_band->n_channels);
413
414 for (i = 0; i < supp_band->n_channels; i++)
415 pos += scnprintf(buf + pos, bufsz - pos,
416 "%d: %ddBm: BSS%s%s, %s.\n",
417 ieee80211_frequency_to_channel(
418 channels[i].center_freq),
419 channels[i].max_power,
420 channels[i].flags & IEEE80211_CHAN_RADAR ?
421 " (IEEE 802.11h required)" : "",
422 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
423 || (channels[i].flags &
424 IEEE80211_CHAN_RADAR)) ? "" :
425 ", IBSS",
426 channels[i].flags &
427 IEEE80211_CHAN_PASSIVE_SCAN ?
428 "passive only" : "active/passive");
429 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800430 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
431 kfree(buf);
432 return ret;
433}
434
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700435static ssize_t iwl_dbgfs_status_read(struct file *file,
436 char __user *user_buf,
437 size_t count, loff_t *ppos) {
438
439 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
440 char buf[512];
441 int pos = 0;
442 const size_t bufsz = sizeof(buf);
443
444 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
445 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
446 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
447 test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
448 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
449 test_bit(STATUS_INT_ENABLED, &priv->status));
450 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
451 test_bit(STATUS_RF_KILL_HW, &priv->status));
452 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_SW:\t %d\n",
453 test_bit(STATUS_RF_KILL_SW, &priv->status));
454 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
455 test_bit(STATUS_INIT, &priv->status));
456 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
457 test_bit(STATUS_ALIVE, &priv->status));
458 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
459 test_bit(STATUS_READY, &priv->status));
460 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
461 test_bit(STATUS_TEMPERATURE, &priv->status));
462 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
463 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
464 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
465 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700466 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
467 test_bit(STATUS_STATISTICS, &priv->status));
468 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
469 test_bit(STATUS_SCANNING, &priv->status));
470 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
471 test_bit(STATUS_SCAN_ABORTING, &priv->status));
472 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
473 test_bit(STATUS_SCAN_HW, &priv->status));
474 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
475 test_bit(STATUS_POWER_PMI, &priv->status));
476 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
477 test_bit(STATUS_FW_ERROR, &priv->status));
478 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
479 test_bit(STATUS_MODE_PENDING, &priv->status));
480 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
481}
482
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700483static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
484 char __user *user_buf,
485 size_t count, loff_t *ppos) {
486
487 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
488 int pos = 0;
489 int cnt = 0;
490 char *buf;
491 int bufsz = 24 * 64; /* 24 items * 64 char per item */
492 ssize_t ret;
493
494 buf = kzalloc(bufsz, GFP_KERNEL);
495 if (!buf) {
496 IWL_ERR(priv, "Can not allocate Buffer\n");
497 return -ENOMEM;
498 }
499
500 pos += scnprintf(buf + pos, bufsz - pos,
501 "Interrupt Statistics Report:\n");
502
503 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
504 priv->isr_stats.hw);
505 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
506 priv->isr_stats.sw);
507 if (priv->isr_stats.sw > 0) {
508 pos += scnprintf(buf + pos, bufsz - pos,
509 "\tLast Restarting Code: 0x%X\n",
510 priv->isr_stats.sw_err);
511 }
512#ifdef CONFIG_IWLWIFI_DEBUG
513 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
514 priv->isr_stats.sch);
515 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
516 priv->isr_stats.alive);
517#endif
518 pos += scnprintf(buf + pos, bufsz - pos,
519 "HW RF KILL switch toggled:\t %u\n",
520 priv->isr_stats.rfkill);
521
522 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
523 priv->isr_stats.ctkill);
524
525 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
526 priv->isr_stats.wakeup);
527
528 pos += scnprintf(buf + pos, bufsz - pos,
529 "Rx command responses:\t\t %u\n",
530 priv->isr_stats.rx);
531 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
532 if (priv->isr_stats.rx_handlers[cnt] > 0)
533 pos += scnprintf(buf + pos, bufsz - pos,
534 "\tRx handler[%36s]:\t\t %u\n",
535 get_cmd_string(cnt),
536 priv->isr_stats.rx_handlers[cnt]);
537 }
538
539 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
540 priv->isr_stats.tx);
541
542 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
543 priv->isr_stats.unhandled);
544
545 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
546 kfree(buf);
547 return ret;
548}
549
550static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
551 const char __user *user_buf,
552 size_t count, loff_t *ppos)
553{
554 struct iwl_priv *priv = file->private_data;
555 char buf[8];
556 int buf_size;
557 u32 reset_flag;
558
559 memset(buf, 0, sizeof(buf));
560 buf_size = min(count, sizeof(buf) - 1);
561 if (copy_from_user(buf, user_buf, buf_size))
562 return -EFAULT;
563 if (sscanf(buf, "%x", &reset_flag) != 1)
564 return -EFAULT;
565 if (reset_flag == 0)
566 iwl_clear_isr_stats(priv);
567
568 return count;
569}
570
571
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700572DEBUGFS_READ_WRITE_FILE_OPS(sram);
Ester Kummer189a2b52008-05-15 13:54:18 +0800573DEBUGFS_WRITE_FILE_OPS(log_event);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700574DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700575DEBUGFS_READ_FILE_OPS(stations);
576DEBUGFS_READ_FILE_OPS(rx_statistics);
577DEBUGFS_READ_FILE_OPS(tx_statistics);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800578DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700579DEBUGFS_READ_FILE_OPS(status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700580DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700581
582/*
583 * Create the debugfs files and directories
584 *
585 */
586int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
587{
588 struct iwl_debugfs *dbgfs;
Zhu Yi95b1a822008-05-29 16:34:50 +0800589 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300590 int ret = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700591
592 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
593 if (!dbgfs) {
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300594 ret = -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700595 goto err;
596 }
597
598 priv->dbgfs = dbgfs;
599 dbgfs->name = name;
Zhu Yi95b1a822008-05-29 16:34:50 +0800600 dbgfs->dir_drv = debugfs_create_dir(name, phyd);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300601 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
602 ret = -ENOENT;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700603 goto err;
604 }
605
606 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800607 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700608 DEBUGFS_ADD_FILE(nvm, data);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700609 DEBUGFS_ADD_FILE(sram, data);
Ester Kummer189a2b52008-05-15 13:54:18 +0800610 DEBUGFS_ADD_FILE(log_event, data);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700611 DEBUGFS_ADD_FILE(stations, data);
612 DEBUGFS_ADD_FILE(rx_statistics, data);
613 DEBUGFS_ADD_FILE(tx_statistics, data);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800614 DEBUGFS_ADD_FILE(channels, data);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700615 DEBUGFS_ADD_FILE(status, data);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700616 DEBUGFS_ADD_FILE(interrupt, data);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800617 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
618 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
619 &priv->disable_chain_noise_cal);
Emmanuel Grumbach203566f2008-06-12 09:46:54 +0800620 DEBUGFS_ADD_BOOL(disable_tx_power, rf, &priv->disable_tx_power_cal);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700621 return 0;
622
623err:
Winkler, Tomas15b16872008-12-19 10:37:33 +0800624 IWL_ERR(priv, "Can't open the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700625 iwl_dbgfs_unregister(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300626 return ret;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700627}
628EXPORT_SYMBOL(iwl_dbgfs_register);
629
630/**
631 * Remove the debugfs files and directories
632 *
633 */
634void iwl_dbgfs_unregister(struct iwl_priv *priv)
635{
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300636 if (!priv->dbgfs)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700637 return;
638
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700639 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700640 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_rx_statistics);
641 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_tx_statistics);
642 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
Ester Kummer189a2b52008-05-15 13:54:18 +0800643 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700644 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800645 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700646 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700647 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700648 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800649 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
650 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
Emmanuel Grumbach203566f2008-06-12 09:46:54 +0800651 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
Tomas Winkler445c2df2008-05-15 13:54:16 +0800652 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700653 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
654 kfree(priv->dbgfs);
655 priv->dbgfs = NULL;
656}
657EXPORT_SYMBOL(iwl_dbgfs_unregister);
658
659
Tomas Winkler445c2df2008-05-15 13:54:16 +0800660