blob: 016ff4014a7b8b43da36f9535899fbfdf81f427b [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"
Wey-Yi Guy52259352009-08-07 15:41:43 -070041#include "iwl-calib.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070042
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
Wey-Yi Guy43e85112009-11-20 12:04:58 -080050#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070051 dbgfs->dbgfs_##parent##_files.file_##name = \
Wey-Yi Guy43e85112009-11-20 12:04:58 -080052 debugfs_create_file(#name, mode, \
Reinette Chatrefcf89d02009-07-09 10:33:38 -070053 dbgfs->dir_##parent, priv, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070054 &iwl_dbgfs_##name##_ops); \
55 if (!(dbgfs->dbgfs_##parent##_files.file_##name)) \
56 goto err; \
57} while (0)
58
Tomas Winkler445c2df2008-05-15 13:54:16 +080059#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
60 dbgfs->dbgfs_##parent##_files.file_##name = \
Reinette Chatrefcf89d02009-07-09 10:33:38 -070061 debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
62 dbgfs->dir_##parent, ptr); \
Zhaolei9b240012008-10-22 17:06:12 +080063 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
64 || !dbgfs->dbgfs_##parent##_files.file_##name) \
Tomas Winkler445c2df2008-05-15 13:54:16 +080065 goto err; \
66} while (0)
67
Winkler, Tomas2ddfa122008-12-22 11:31:20 +080068#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
69 dbgfs->dbgfs_##parent##_files.file_##name = \
Reinette Chatrefcf89d02009-07-09 10:33:38 -070070 debugfs_create_x32(#name, S_IRUSR, dbgfs->dir_##parent, ptr); \
Winkler, Tomas2ddfa122008-12-22 11:31:20 +080071 if (IS_ERR(dbgfs->dbgfs_##parent##_files.file_##name) \
72 || !dbgfs->dbgfs_##parent##_files.file_##name) \
73 goto err; \
74} while (0)
75
Tomas Winkler712b6cf2008-03-12 16:58:52 -070076#define DEBUGFS_REMOVE(name) do { \
77 debugfs_remove(name); \
78 name = NULL; \
79} while (0);
80
81/* file operation */
82#define DEBUGFS_READ_FUNC(name) \
83static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
84 char __user *user_buf, \
85 size_t count, loff_t *ppos);
86
87#define DEBUGFS_WRITE_FUNC(name) \
88static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
89 const char __user *user_buf, \
90 size_t count, loff_t *ppos);
91
92
93static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
94{
95 file->private_data = inode->i_private;
96 return 0;
97}
98
99#define DEBUGFS_READ_FILE_OPS(name) \
100 DEBUGFS_READ_FUNC(name); \
101static const struct file_operations iwl_dbgfs_##name##_ops = { \
102 .read = iwl_dbgfs_##name##_read, \
103 .open = iwl_dbgfs_open_file_generic, \
104};
105
Ester Kummer189a2b52008-05-15 13:54:18 +0800106#define DEBUGFS_WRITE_FILE_OPS(name) \
107 DEBUGFS_WRITE_FUNC(name); \
108static const struct file_operations iwl_dbgfs_##name##_ops = { \
109 .write = iwl_dbgfs_##name##_write, \
110 .open = iwl_dbgfs_open_file_generic, \
111};
112
113
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700114#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
115 DEBUGFS_READ_FUNC(name); \
116 DEBUGFS_WRITE_FUNC(name); \
117static const struct file_operations iwl_dbgfs_##name##_ops = { \
118 .write = iwl_dbgfs_##name##_write, \
119 .read = iwl_dbgfs_##name##_read, \
120 .open = iwl_dbgfs_open_file_generic, \
121};
122
123
124static ssize_t iwl_dbgfs_tx_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;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700129 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700130 int pos = 0;
131
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700132 int cnt;
133 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800134 const size_t bufsz = 100 +
135 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700136 buf = kzalloc(bufsz, GFP_KERNEL);
137 if (!buf)
138 return -ENOMEM;
139 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
140 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
141 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800142 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700143 get_mgmt_string(cnt),
144 priv->tx_stats.mgmt[cnt]);
145 }
146 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
147 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
148 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800149 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700150 get_ctrl_string(cnt),
151 priv->tx_stats.ctrl[cnt]);
152 }
153 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
154 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
155 priv->tx_stats.data_cnt);
156 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
157 priv->tx_stats.data_bytes);
158 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
159 kfree(buf);
160 return ret;
161}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700162
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800163static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700164 const char __user *user_buf,
165 size_t count, loff_t *ppos)
166{
167 struct iwl_priv *priv = file->private_data;
168 u32 clear_flag;
169 char buf[8];
170 int buf_size;
171
172 memset(buf, 0, sizeof(buf));
173 buf_size = min(count, sizeof(buf) - 1);
174 if (copy_from_user(buf, user_buf, buf_size))
175 return -EFAULT;
176 if (sscanf(buf, "%x", &clear_flag) != 1)
177 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800178 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700179
180 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700181}
182
183static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
184 char __user *user_buf,
185 size_t count, loff_t *ppos) {
186
187 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700188 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700189 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700190 int cnt;
191 ssize_t ret;
192 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800193 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700194 buf = kzalloc(bufsz, GFP_KERNEL);
195 if (!buf)
196 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700197
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700198 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
199 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
200 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800201 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700202 get_mgmt_string(cnt),
203 priv->rx_stats.mgmt[cnt]);
204 }
205 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
206 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
207 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800208 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700209 get_ctrl_string(cnt),
210 priv->rx_stats.ctrl[cnt]);
211 }
212 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
213 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
214 priv->rx_stats.data_cnt);
215 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
216 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700217
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700218 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
219 kfree(buf);
220 return ret;
221}
222
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700223#define BYTE1_MASK 0x000000ff;
224#define BYTE2_MASK 0x0000ffff;
225#define BYTE3_MASK 0x00ffffff;
226static ssize_t iwl_dbgfs_sram_read(struct file *file,
227 char __user *user_buf,
228 size_t count, loff_t *ppos)
229{
230 u32 val;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800231 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700232 ssize_t ret;
233 int i;
234 int pos = 0;
235 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800236 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700237
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800238 bufsz = 30 + priv->dbgfs->sram_len * sizeof(char) * 12;
239 buf = kmalloc(bufsz, GFP_KERNEL);
240 if (!buf)
241 return -ENOMEM;
242 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: %d\n",
243 priv->dbgfs->sram_len);
244 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: %d\n",
245 priv->dbgfs->sram_offset);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700246 for (i = priv->dbgfs->sram_len; i > 0; i -= 4) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700247 val = iwl_read_targ_mem(priv, priv->dbgfs->sram_offset + \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700248 priv->dbgfs->sram_len - i);
249 if (i < 4) {
250 switch (i) {
251 case 1:
252 val &= BYTE1_MASK;
253 break;
254 case 2:
255 val &= BYTE2_MASK;
256 break;
257 case 3:
258 val &= BYTE3_MASK;
259 break;
260 }
261 }
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800262 if (!(i % 16))
263 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700264 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700265 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700266 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700267
268 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800269 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700270 return ret;
271}
272
273static ssize_t iwl_dbgfs_sram_write(struct file *file,
274 const char __user *user_buf,
275 size_t count, loff_t *ppos)
276{
277 struct iwl_priv *priv = file->private_data;
278 char buf[64];
279 int buf_size;
280 u32 offset, len;
281
282 memset(buf, 0, sizeof(buf));
283 buf_size = min(count, sizeof(buf) - 1);
284 if (copy_from_user(buf, user_buf, buf_size))
285 return -EFAULT;
286
287 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
288 priv->dbgfs->sram_offset = offset;
289 priv->dbgfs->sram_len = len;
290 } else {
291 priv->dbgfs->sram_offset = 0;
292 priv->dbgfs->sram_len = 0;
293 }
294
295 return count;
296}
297
298static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
299 size_t count, loff_t *ppos)
300{
301 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800302 struct iwl_station_entry *station;
Tomas Winkler5425e492008-04-15 16:01:38 -0700303 int max_sta = priv->hw_params.max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700304 char *buf;
305 int i, j, pos = 0;
306 ssize_t ret;
307 /* Add 30 for initial string */
308 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700309
310 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300311 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700312 return -ENOMEM;
313
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700314 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700315 priv->num_stations);
316
317 for (i = 0; i < max_sta; i++) {
318 station = &priv->stations[i];
319 if (station->used) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700320 pos += scnprintf(buf + pos, bufsz - pos,
321 "station %d:\ngeneral data:\n", i+1);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700322 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700323 station->sta.sta.sta_id);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700324 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700325 station->sta.mode);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700326 pos += scnprintf(buf + pos, bufsz - pos,
327 "flags: 0x%x\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700328 station->sta.station_flags_msk);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700329 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
330 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700331 "seq_num\t\ttxq_id");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700332 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700333 "\tframe_count\twait_for_ba\t");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700334 pos += scnprintf(buf + pos, bufsz - pos,
335 "start_idx\tbitmap0\t");
336 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700337 "bitmap1\trate_n_flags");
David S. Miller344234d2008-04-19 18:09:39 -0700338 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700339
340 for (j = 0; j < MAX_TID_COUNT; j++) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700341 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700342 "[%d]:\t\t%u", j,
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700343 station->tid[j].seq_number);
344 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700345 "\t%u\t\t%u\t\t%u\t\t",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700346 station->tid[j].agg.txq_id,
347 station->tid[j].agg.frame_count,
348 station->tid[j].agg.wait_for_ba);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700349 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700350 "%u\t%llu\t%u",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700351 station->tid[j].agg.start_idx,
John W. Linville16788592008-04-01 20:59:32 -0400352 (unsigned long long)station->tid[j].agg.bitmap,
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700353 station->tid[j].agg.rate_n_flags);
David S. Miller344234d2008-04-19 18:09:39 -0700354 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700355 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700356 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700357 }
358 }
359
360 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
361 kfree(buf);
362 return ret;
363}
364
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700365static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800366 char __user *user_buf,
367 size_t count,
368 loff_t *ppos)
369{
370 ssize_t ret;
371 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
372 int pos = 0, ofs = 0, buf_size = 0;
373 const u8 *ptr;
374 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700375 u16 eeprom_ver;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800376 size_t eeprom_len = priv->cfg->eeprom_size;
377 buf_size = 4 * eeprom_len + 256;
378
379 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700380 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800381 return -ENODATA;
382 }
383
Julia Lawallc37457e2009-08-03 11:11:45 +0200384 ptr = priv->eeprom;
385 if (!ptr) {
386 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
387 return -ENOMEM;
388 }
389
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800390 /* 4 characters for byte 0xYY */
391 buf = kzalloc(buf_size, GFP_KERNEL);
392 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800393 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800394 return -ENOMEM;
395 }
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700396 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
397 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
398 "version: 0x%x\n",
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700399 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700400 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800401 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
402 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
403 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
404 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700405 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800406 if (buf_size - pos > 0)
407 buf[pos++] = '\n';
408 }
409
410 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
411 kfree(buf);
412 return ret;
413}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700414
Ester Kummer189a2b52008-05-15 13:54:18 +0800415static ssize_t iwl_dbgfs_log_event_write(struct file *file,
416 const char __user *user_buf,
417 size_t count, loff_t *ppos)
418{
419 struct iwl_priv *priv = file->private_data;
420 u32 event_log_flag;
421 char buf[8];
422 int buf_size;
423
424 memset(buf, 0, sizeof(buf));
425 buf_size = min(count, sizeof(buf) - 1);
426 if (copy_from_user(buf, user_buf, buf_size))
427 return -EFAULT;
428 if (sscanf(buf, "%d", &event_log_flag) != 1)
429 return -EFAULT;
430 if (event_log_flag == 1)
Reinette Chatreb7a79402009-09-25 14:24:23 -0700431 priv->cfg->ops->lib->dump_nic_event_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +0800432
433 return count;
434}
435
Winkler, Tomasd366df52008-12-02 12:14:01 -0800436
437
438static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
439 size_t count, loff_t *ppos)
440{
441 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
442 struct ieee80211_channel *channels = NULL;
443 const struct ieee80211_supported_band *supp_band = NULL;
444 int pos = 0, i, bufsz = PAGE_SIZE;
445 char *buf;
446 ssize_t ret;
447
448 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
449 return -EAGAIN;
450
451 buf = kzalloc(bufsz, GFP_KERNEL);
452 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800453 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800454 return -ENOMEM;
455 }
456
457 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700458 if (supp_band) {
459 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800460
Winkler, Tomasd366df52008-12-02 12:14:01 -0800461 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700462 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
463 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800464
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700465 for (i = 0; i < supp_band->n_channels; i++)
466 pos += scnprintf(buf + pos, bufsz - pos,
467 "%d: %ddBm: BSS%s%s, %s.\n",
468 ieee80211_frequency_to_channel(
469 channels[i].center_freq),
470 channels[i].max_power,
471 channels[i].flags & IEEE80211_CHAN_RADAR ?
472 " (IEEE 802.11h required)" : "",
473 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
474 || (channels[i].flags &
475 IEEE80211_CHAN_RADAR)) ? "" :
476 ", IBSS",
477 channels[i].flags &
478 IEEE80211_CHAN_PASSIVE_SCAN ?
479 "passive only" : "active/passive");
480 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800481 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700482 if (supp_band) {
483 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800484
Winkler, Tomasd366df52008-12-02 12:14:01 -0800485 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700486 "Displaying %d channels in 5.2GHz band (802.11a)\n",
487 supp_band->n_channels);
488
489 for (i = 0; i < supp_band->n_channels; i++)
490 pos += scnprintf(buf + pos, bufsz - pos,
491 "%d: %ddBm: BSS%s%s, %s.\n",
492 ieee80211_frequency_to_channel(
493 channels[i].center_freq),
494 channels[i].max_power,
495 channels[i].flags & IEEE80211_CHAN_RADAR ?
496 " (IEEE 802.11h required)" : "",
497 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
498 || (channels[i].flags &
499 IEEE80211_CHAN_RADAR)) ? "" :
500 ", IBSS",
501 channels[i].flags &
502 IEEE80211_CHAN_PASSIVE_SCAN ?
503 "passive only" : "active/passive");
504 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800505 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
506 kfree(buf);
507 return ret;
508}
509
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700510static ssize_t iwl_dbgfs_status_read(struct file *file,
511 char __user *user_buf,
512 size_t count, loff_t *ppos) {
513
514 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
515 char buf[512];
516 int pos = 0;
517 const size_t bufsz = sizeof(buf);
518
519 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
520 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
521 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
522 test_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status));
523 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
524 test_bit(STATUS_INT_ENABLED, &priv->status));
525 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
526 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
528 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
530 test_bit(STATUS_INIT, &priv->status));
531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
532 test_bit(STATUS_ALIVE, &priv->status));
533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
534 test_bit(STATUS_READY, &priv->status));
535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
536 test_bit(STATUS_TEMPERATURE, &priv->status));
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
538 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
540 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
542 test_bit(STATUS_STATISTICS, &priv->status));
543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
544 test_bit(STATUS_SCANNING, &priv->status));
545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
546 test_bit(STATUS_SCAN_ABORTING, &priv->status));
547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
548 test_bit(STATUS_SCAN_HW, &priv->status));
549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
550 test_bit(STATUS_POWER_PMI, &priv->status));
551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
552 test_bit(STATUS_FW_ERROR, &priv->status));
553 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_MODE_PENDING:\t %d\n",
554 test_bit(STATUS_MODE_PENDING, &priv->status));
555 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
556}
557
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700558static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
559 char __user *user_buf,
560 size_t count, loff_t *ppos) {
561
562 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
563 int pos = 0;
564 int cnt = 0;
565 char *buf;
566 int bufsz = 24 * 64; /* 24 items * 64 char per item */
567 ssize_t ret;
568
569 buf = kzalloc(bufsz, GFP_KERNEL);
570 if (!buf) {
571 IWL_ERR(priv, "Can not allocate Buffer\n");
572 return -ENOMEM;
573 }
574
575 pos += scnprintf(buf + pos, bufsz - pos,
576 "Interrupt Statistics Report:\n");
577
578 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
579 priv->isr_stats.hw);
580 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
581 priv->isr_stats.sw);
582 if (priv->isr_stats.sw > 0) {
583 pos += scnprintf(buf + pos, bufsz - pos,
584 "\tLast Restarting Code: 0x%X\n",
585 priv->isr_stats.sw_err);
586 }
587#ifdef CONFIG_IWLWIFI_DEBUG
588 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
589 priv->isr_stats.sch);
590 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
591 priv->isr_stats.alive);
592#endif
593 pos += scnprintf(buf + pos, bufsz - pos,
594 "HW RF KILL switch toggled:\t %u\n",
595 priv->isr_stats.rfkill);
596
597 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
598 priv->isr_stats.ctkill);
599
600 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
601 priv->isr_stats.wakeup);
602
603 pos += scnprintf(buf + pos, bufsz - pos,
604 "Rx command responses:\t\t %u\n",
605 priv->isr_stats.rx);
606 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
607 if (priv->isr_stats.rx_handlers[cnt] > 0)
608 pos += scnprintf(buf + pos, bufsz - pos,
609 "\tRx handler[%36s]:\t\t %u\n",
610 get_cmd_string(cnt),
611 priv->isr_stats.rx_handlers[cnt]);
612 }
613
614 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
615 priv->isr_stats.tx);
616
617 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
618 priv->isr_stats.unhandled);
619
620 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
621 kfree(buf);
622 return ret;
623}
624
625static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
626 const char __user *user_buf,
627 size_t count, loff_t *ppos)
628{
629 struct iwl_priv *priv = file->private_data;
630 char buf[8];
631 int buf_size;
632 u32 reset_flag;
633
634 memset(buf, 0, sizeof(buf));
635 buf_size = min(count, sizeof(buf) - 1);
636 if (copy_from_user(buf, user_buf, buf_size))
637 return -EFAULT;
638 if (sscanf(buf, "%x", &reset_flag) != 1)
639 return -EFAULT;
640 if (reset_flag == 0)
641 iwl_clear_isr_stats(priv);
642
643 return count;
644}
645
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700646static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
647 size_t count, loff_t *ppos)
648{
649 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
650 int pos = 0, i;
651 char buf[256];
652 const size_t bufsz = sizeof(buf);
653 ssize_t ret;
654
655 for (i = 0; i < AC_NUM; i++) {
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "\tcw_min\tcw_max\taifsn\ttxop\n");
658 pos += scnprintf(buf + pos, bufsz - pos,
659 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
660 priv->qos_data.def_qos_parm.ac[i].cw_min,
661 priv->qos_data.def_qos_parm.ac[i].cw_max,
662 priv->qos_data.def_qos_parm.ac[i].aifsn,
663 priv->qos_data.def_qos_parm.ac[i].edca_txop);
664 }
665 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
666 return ret;
667}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700668
Wey-Yi Guya283c012009-07-17 09:30:19 -0700669static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
670 size_t count, loff_t *ppos)
671{
672 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
673 int pos = 0;
674 char buf[256];
675 const size_t bufsz = sizeof(buf);
676 ssize_t ret;
677
678 pos += scnprintf(buf + pos, bufsz - pos,
679 "allow blinking: %s\n",
680 (priv->allow_blinking) ? "True" : "False");
681 if (priv->allow_blinking) {
682 pos += scnprintf(buf + pos, bufsz - pos,
683 "Led blinking rate: %u\n",
684 priv->last_blink_rate);
685 pos += scnprintf(buf + pos, bufsz - pos,
686 "Last blink time: %lu\n",
687 priv->last_blink_time);
688 }
689
690 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
691 return ret;
692}
Wey-Yi Guya283c012009-07-17 09:30:19 -0700693
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700694static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
695 char __user *user_buf,
696 size_t count, loff_t *ppos)
697{
698 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700699 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700700 struct iwl_tt_restriction *restriction;
701 char buf[100];
702 int pos = 0;
703 const size_t bufsz = sizeof(buf);
704 ssize_t ret;
705
706 pos += scnprintf(buf + pos, bufsz - pos,
707 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700708 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700709 pos += scnprintf(buf + pos, bufsz - pos,
710 "Thermal Throttling State: %d\n",
711 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700712 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700713 restriction = tt->restriction + tt->state;
714 pos += scnprintf(buf + pos, bufsz - pos,
715 "Tx mode: %d\n",
716 restriction->tx_stream);
717 pos += scnprintf(buf + pos, bufsz - pos,
718 "Rx mode: %d\n",
719 restriction->rx_stream);
720 pos += scnprintf(buf + pos, bufsz - pos,
721 "HT mode: %d\n",
722 restriction->is_ht);
723 }
724 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
725 return ret;
726}
727
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700728static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
729 const char __user *user_buf,
730 size_t count, loff_t *ppos)
731{
732 struct iwl_priv *priv = file->private_data;
733 char buf[8];
734 int buf_size;
735 int ht40;
736
737 memset(buf, 0, sizeof(buf));
738 buf_size = min(count, sizeof(buf) - 1);
739 if (copy_from_user(buf, user_buf, buf_size))
740 return -EFAULT;
741 if (sscanf(buf, "%d", &ht40) != 1)
742 return -EFAULT;
743 if (!iwl_is_associated(priv))
744 priv->disable_ht40 = ht40 ? true : false;
745 else {
746 IWL_ERR(priv, "Sta associated with AP - "
747 "Change to 40MHz channel support is not allowed\n");
748 return -EINVAL;
749 }
750
751 return count;
752}
753
754static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
755 char __user *user_buf,
756 size_t count, loff_t *ppos)
757{
758 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
759 char buf[100];
760 int pos = 0;
761 const size_t bufsz = sizeof(buf);
762 ssize_t ret;
763
764 pos += scnprintf(buf + pos, bufsz - pos,
765 "11n 40MHz Mode: %s\n",
766 priv->disable_ht40 ? "Disabled" : "Enabled");
767 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
768 return ret;
769}
770
Johannes Berge312c242009-08-07 15:41:51 -0700771static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
772 const char __user *user_buf,
773 size_t count, loff_t *ppos)
774{
775 struct iwl_priv *priv = file->private_data;
776 char buf[8];
777 int buf_size;
778 int value;
779
780 memset(buf, 0, sizeof(buf));
781 buf_size = min(count, sizeof(buf) - 1);
782 if (copy_from_user(buf, user_buf, buf_size))
783 return -EFAULT;
784
785 if (sscanf(buf, "%d", &value) != 1)
786 return -EINVAL;
787
788 /*
789 * Our users expect 0 to be "CAM", but 0 isn't actually
790 * valid here. However, let's not confuse them and present
791 * IWL_POWER_INDEX_1 as "1", not "0".
792 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700793 if (value == 0)
794 return -EINVAL;
795 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700796 value -= 1;
797
798 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
799 return -EINVAL;
800
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700801 if (!iwl_is_ready_rf(priv))
802 return -EAGAIN;
803
Johannes Berge312c242009-08-07 15:41:51 -0700804 priv->power_data.debug_sleep_level_override = value;
805
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700806 iwl_power_update_mode(priv, true);
Johannes Berge312c242009-08-07 15:41:51 -0700807
808 return count;
809}
810
811static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
812 char __user *user_buf,
813 size_t count, loff_t *ppos)
814{
815 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
816 char buf[10];
817 int pos, value;
818 const size_t bufsz = sizeof(buf);
819
820 /* see the write function */
821 value = priv->power_data.debug_sleep_level_override;
822 if (value >= 0)
823 value += 1;
824
825 pos = scnprintf(buf, bufsz, "%d\n", value);
826 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
827}
828
829static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
830 char __user *user_buf,
831 size_t count, loff_t *ppos)
832{
833 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
834 char buf[200];
835 int pos = 0, i;
836 const size_t bufsz = sizeof(buf);
837 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
838
839 pos += scnprintf(buf + pos, bufsz - pos,
840 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
841 pos += scnprintf(buf + pos, bufsz - pos,
842 "RX/TX timeout: %d/%d usec\n",
843 le32_to_cpu(cmd->rx_data_timeout),
844 le32_to_cpu(cmd->tx_data_timeout));
845 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
846 pos += scnprintf(buf + pos, bufsz - pos,
847 "sleep_interval[%d]: %d\n", i,
848 le32_to_cpu(cmd->sleep_interval[i]));
849
850 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
851}
852
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700853DEBUGFS_READ_WRITE_FILE_OPS(sram);
Ester Kummer189a2b52008-05-15 13:54:18 +0800854DEBUGFS_WRITE_FILE_OPS(log_event);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700855DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700856DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800857DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700858DEBUGFS_READ_FILE_OPS(status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700859DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700860DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700861DEBUGFS_READ_FILE_OPS(led);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700862DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700863DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Johannes Berge312c242009-08-07 15:41:51 -0700864DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
865DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700866
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700867static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
868 char __user *user_buf,
869 size_t count, loff_t *ppos)
870{
871 struct iwl_priv *priv = file->private_data;
872 int pos = 0, ofs = 0;
873 int cnt = 0, entry;
874 struct iwl_tx_queue *txq;
875 struct iwl_queue *q;
876 struct iwl_rx_queue *rxq = &priv->rxq;
877 char *buf;
878 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700879 (priv->cfg->num_of_queues * 32 * 8) + 400;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700880 const u8 *ptr;
881 ssize_t ret;
882
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700883 if (!priv->txq) {
884 IWL_ERR(priv, "txq not ready\n");
885 return -EAGAIN;
886 }
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700887 buf = kzalloc(bufsz, GFP_KERNEL);
888 if (!buf) {
889 IWL_ERR(priv, "Can not allocate buffer\n");
890 return -ENOMEM;
891 }
892 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
893 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
894 txq = &priv->txq[cnt];
895 q = &txq->q;
896 pos += scnprintf(buf + pos, bufsz - pos,
897 "q[%d]: read_ptr: %u, write_ptr: %u\n",
898 cnt, q->read_ptr, q->write_ptr);
899 }
900 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
901 ptr = priv->tx_traffic;
902 pos += scnprintf(buf + pos, bufsz - pos,
903 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
904 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
905 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
906 entry++, ofs += 16) {
907 pos += scnprintf(buf + pos, bufsz - pos,
908 "0x%.4x ", ofs);
909 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
910 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700911 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700912 if (bufsz - pos > 0)
913 buf[pos++] = '\n';
914 }
915 }
916 }
917
918 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
919 pos += scnprintf(buf + pos, bufsz - pos,
920 "read: %u, write: %u\n",
921 rxq->read, rxq->write);
922
923 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
924 ptr = priv->rx_traffic;
925 pos += scnprintf(buf + pos, bufsz - pos,
926 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
927 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
928 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
929 entry++, ofs += 16) {
930 pos += scnprintf(buf + pos, bufsz - pos,
931 "0x%.4x ", ofs);
932 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
933 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700934 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700935 if (bufsz - pos > 0)
936 buf[pos++] = '\n';
937 }
938 }
939 }
940
941 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
942 kfree(buf);
943 return ret;
944}
945
946static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
947 const char __user *user_buf,
948 size_t count, loff_t *ppos)
949{
950 struct iwl_priv *priv = file->private_data;
951 char buf[8];
952 int buf_size;
953 int traffic_log;
954
955 memset(buf, 0, sizeof(buf));
956 buf_size = min(count, sizeof(buf) - 1);
957 if (copy_from_user(buf, user_buf, buf_size))
958 return -EFAULT;
959 if (sscanf(buf, "%d", &traffic_log) != 1)
960 return -EFAULT;
961 if (traffic_log == 0)
962 iwl_reset_traffic_log(priv);
963
964 return count;
965}
966
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700967static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
968 char __user *user_buf,
969 size_t count, loff_t *ppos) {
970
971 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
972 struct iwl_tx_queue *txq;
973 struct iwl_queue *q;
974 char *buf;
975 int pos = 0;
976 int cnt;
977 int ret;
Wey-Yi Guyd23db552009-11-20 12:04:59 -0800978 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700979
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700980 if (!priv->txq) {
981 IWL_ERR(priv, "txq not ready\n");
982 return -EAGAIN;
983 }
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700984 buf = kzalloc(bufsz, GFP_KERNEL);
985 if (!buf)
986 return -ENOMEM;
987
988 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
989 txq = &priv->txq[cnt];
990 q = &txq->q;
991 pos += scnprintf(buf + pos, bufsz - pos,
992 "hwq %.2d: read=%u write=%u stop=%d"
993 " swq_id=%#.2x (ac %d/hwq %d)\n",
994 cnt, q->read_ptr, q->write_ptr,
995 !!test_bit(cnt, priv->queue_stopped),
996 txq->swq_id,
997 txq->swq_id & 0x80 ? txq->swq_id & 3 :
998 txq->swq_id,
999 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
1000 0x1f : txq->swq_id);
1001 if (cnt >= 4)
1002 continue;
1003 /* for the ACs, display the stop count too */
1004 pos += scnprintf(buf + pos, bufsz - pos,
1005 " stop-count: %d\n",
1006 atomic_read(&priv->queue_stop_count[cnt]));
1007 }
1008 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1009 kfree(buf);
1010 return ret;
1011}
1012
1013static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1014 char __user *user_buf,
1015 size_t count, loff_t *ppos) {
1016
1017 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1018 struct iwl_rx_queue *rxq = &priv->rxq;
1019 char buf[256];
1020 int pos = 0;
1021 const size_t bufsz = sizeof(buf);
1022
1023 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1024 rxq->read);
1025 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1026 rxq->write);
1027 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1028 rxq->free_count);
1029 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1030 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1031 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1032}
1033
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001034static int iwl_dbgfs_statistics_flag(struct iwl_priv *priv, char *buf,
1035 int bufsz)
1036{
1037 int p = 0;
1038
1039 p += scnprintf(buf + p, bufsz - p,
1040 "Statistics Flag(0x%X):\n",
1041 le32_to_cpu(priv->statistics.flag));
1042 if (le32_to_cpu(priv->statistics.flag) & UCODE_STATISTICS_CLEAR_MSK)
1043 p += scnprintf(buf + p, bufsz - p,
1044 "\tStatistics have been cleared\n");
1045 p += scnprintf(buf + p, bufsz - p,
1046 "\tOperational Frequency: %s\n",
1047 (le32_to_cpu(priv->statistics.flag) &
1048 UCODE_STATISTICS_FREQUENCY_MSK)
1049 ? "2.4 GHz" : "5.2 GHz");
1050 p += scnprintf(buf + p, bufsz - p,
1051 "\tTGj Narrow Band: %s\n",
1052 (le32_to_cpu(priv->statistics.flag) &
1053 UCODE_STATISTICS_NARROW_BAND_MSK)
1054 ? "enabled" : "disabled");
1055 return p;
1056}
1057
1058
1059static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1060 char __user *user_buf,
1061 size_t count, loff_t *ppos)
1062{
1063 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1064 int pos = 0;
1065 char *buf;
1066 int bufsz = sizeof(struct statistics_rx_phy) * 20 +
1067 sizeof(struct statistics_rx_non_phy) * 20 +
1068 sizeof(struct statistics_rx_ht_phy) * 20 + 400;
1069 ssize_t ret;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001070 struct statistics_rx_phy *ofdm, *accum_ofdm;
1071 struct statistics_rx_phy *cck, *accum_cck;
1072 struct statistics_rx_non_phy *general, *accum_general;
1073 struct statistics_rx_ht_phy *ht, *accum_ht;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001074
1075 if (!iwl_is_alive(priv))
1076 return -EAGAIN;
1077
1078 /* make request to uCode to retrieve statistics information */
1079 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001080 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001081 mutex_unlock(&priv->mutex);
1082
1083 if (ret) {
1084 IWL_ERR(priv,
1085 "Error sending statistics request: %zd\n", ret);
1086 return -EAGAIN;
1087 }
1088 buf = kzalloc(bufsz, GFP_KERNEL);
1089 if (!buf) {
1090 IWL_ERR(priv, "Can not allocate Buffer\n");
1091 return -ENOMEM;
1092 }
1093
1094 /* the statistic information display here is based on
1095 * the last statistics notification from uCode
1096 * might not reflect the current uCode activity
1097 */
1098 ofdm = &priv->statistics.rx.ofdm;
1099 cck = &priv->statistics.rx.cck;
1100 general = &priv->statistics.rx.general;
1101 ht = &priv->statistics.rx.ofdm_ht;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001102 accum_ofdm = &priv->accum_statistics.rx.ofdm;
1103 accum_cck = &priv->accum_statistics.rx.cck;
1104 accum_general = &priv->accum_statistics.rx.general;
1105 accum_ht = &priv->accum_statistics.rx.ofdm_ht;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001106 pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
1107 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM:\n");
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001108 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001109 "\t\t\tcurrent\t\t\taccumulative\n");
1110 pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
1111 le32_to_cpu(ofdm->ina_cnt), accum_ofdm->ina_cnt);
1112 pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
1113 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt);
1114 pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
1115 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err);
1116 pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
1117 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err);
1118 pos += scnprintf(buf + pos, bufsz - pos,
1119 "overrun_err:\t\t%u\t\t\t%u\n",
1120 le32_to_cpu(ofdm->overrun_err),
1121 accum_ofdm->overrun_err);
1122 pos += scnprintf(buf + pos, bufsz - pos,
1123 "early_overrun_err:\t%u\t\t\t%u\n",
1124 le32_to_cpu(ofdm->early_overrun_err),
1125 accum_ofdm->early_overrun_err);
1126 pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
1127 le32_to_cpu(ofdm->crc32_good),
1128 accum_ofdm->crc32_good);
1129 pos += scnprintf(buf + pos, bufsz - pos,
1130 "false_alarm_cnt:\t%u\t\t\t%u\n",
1131 le32_to_cpu(ofdm->false_alarm_cnt),
1132 accum_ofdm->false_alarm_cnt);
1133 pos += scnprintf(buf + pos, bufsz - pos,
1134 "fina_sync_err_cnt:\t%u\t\t\t%u\n",
1135 le32_to_cpu(ofdm->fina_sync_err_cnt),
1136 accum_ofdm->fina_sync_err_cnt);
1137 pos += scnprintf(buf + pos, bufsz - pos,
1138 "sfd_timeout:\t\t%u\t\t\t%u\n",
1139 le32_to_cpu(ofdm->sfd_timeout),
1140 accum_ofdm->sfd_timeout);
1141 pos += scnprintf(buf + pos, bufsz - pos,
1142 "fina_timeout:\t\t%u\t\t\t%u\n",
1143 le32_to_cpu(ofdm->fina_timeout),
1144 accum_ofdm->fina_timeout);
1145 pos += scnprintf(buf + pos, bufsz - pos,
1146 "unresponded_rts:\t%u\t\t\t%u\n",
1147 le32_to_cpu(ofdm->unresponded_rts),
1148 accum_ofdm->unresponded_rts);
1149 pos += scnprintf(buf + pos, bufsz - pos,
1150 "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
1151 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1152 accum_ofdm->rxe_frame_limit_overrun);
1153 pos += scnprintf(buf + pos, bufsz - pos,
1154 "sent_ack_cnt:\t\t%u\t\t\t%u\n",
1155 le32_to_cpu(ofdm->sent_ack_cnt),
1156 accum_ofdm->sent_ack_cnt);
1157 pos += scnprintf(buf + pos, bufsz - pos,
1158 "sent_cts_cnt:\t\t%u\t\t\t%u\n",
1159 le32_to_cpu(ofdm->sent_cts_cnt),
1160 accum_ofdm->sent_cts_cnt);
1161 pos += scnprintf(buf + pos, bufsz - pos,
1162 "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
1163 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1164 accum_ofdm->sent_ba_rsp_cnt);
1165 pos += scnprintf(buf + pos, bufsz - pos,
1166 "dsp_self_kill:\t\t%u\t\t\t%u\n",
1167 le32_to_cpu(ofdm->dsp_self_kill),
1168 accum_ofdm->dsp_self_kill);
1169 pos += scnprintf(buf + pos, bufsz - pos,
1170 "mh_format_err:\t\t%u\t\t\t%u\n",
1171 le32_to_cpu(ofdm->mh_format_err),
1172 accum_ofdm->mh_format_err);
1173 pos += scnprintf(buf + pos, bufsz - pos,
1174 "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
1175 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1176 accum_ofdm->re_acq_main_rssi_sum);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001177
1178 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - CCK:\n");
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001179 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001180 "\t\t\tcurrent\t\t\taccumulative\n");
1181 pos += scnprintf(buf + pos, bufsz - pos, "ina_cnt:\t\t%u\t\t\t%u\n",
1182 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt);
1183 pos += scnprintf(buf + pos, bufsz - pos, "fina_cnt:\t\t%u\t\t\t%u\n",
1184 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt);
1185 pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
1186 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err);
1187 pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
1188 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err);
1189 pos += scnprintf(buf + pos, bufsz - pos,
1190 "overrun_err:\t\t%u\t\t\t%u\n",
1191 le32_to_cpu(cck->overrun_err),
1192 accum_cck->overrun_err);
1193 pos += scnprintf(buf + pos, bufsz - pos,
1194 "early_overrun_err:\t%u\t\t\t%u\n",
1195 le32_to_cpu(cck->early_overrun_err),
1196 accum_cck->early_overrun_err);
1197 pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
1198 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good);
1199 pos += scnprintf(buf + pos, bufsz - pos,
1200 "false_alarm_cnt:\t%u\t\t\t%u\n",
1201 le32_to_cpu(cck->false_alarm_cnt),
1202 accum_cck->false_alarm_cnt);
1203 pos += scnprintf(buf + pos, bufsz - pos,
1204 "fina_sync_err_cnt:\t%u\t\t\t%u\n",
1205 le32_to_cpu(cck->fina_sync_err_cnt),
1206 accum_cck->fina_sync_err_cnt);
1207 pos += scnprintf(buf + pos, bufsz - pos,
1208 "sfd_timeout:\t\t%u\t\t\t%u\n",
1209 le32_to_cpu(cck->sfd_timeout),
1210 accum_cck->sfd_timeout);
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 "fina_timeout:\t\t%u\t\t\t%u\n",
1213 le32_to_cpu(cck->fina_timeout),
1214 accum_cck->fina_timeout);
1215 pos += scnprintf(buf + pos, bufsz - pos,
1216 "unresponded_rts:\t%u\t\t\t%u\n",
1217 le32_to_cpu(cck->unresponded_rts),
1218 accum_cck->unresponded_rts);
1219 pos += scnprintf(buf + pos, bufsz - pos,
1220 "rxe_frame_lmt_ovrun:\t%u\t\t\t%u\n",
1221 le32_to_cpu(cck->rxe_frame_limit_overrun),
1222 accum_cck->rxe_frame_limit_overrun);
1223 pos += scnprintf(buf + pos, bufsz - pos,
1224 "sent_ack_cnt:\t\t%u\t\t\t%u\n",
1225 le32_to_cpu(cck->sent_ack_cnt),
1226 accum_cck->sent_ack_cnt);
1227 pos += scnprintf(buf + pos, bufsz - pos,
1228 "sent_cts_cnt:\t\t%u\t\t\t%u\n",
1229 le32_to_cpu(cck->sent_cts_cnt),
1230 accum_cck->sent_cts_cnt);
1231 pos += scnprintf(buf + pos, bufsz - pos,
1232 "sent_ba_rsp_cnt:\t%u\t\t\t%u\n",
1233 le32_to_cpu(cck->sent_ba_rsp_cnt),
1234 accum_cck->sent_ba_rsp_cnt);
1235 pos += scnprintf(buf + pos, bufsz - pos,
1236 "dsp_self_kill:\t\t%u\t\t\t%u\n",
1237 le32_to_cpu(cck->dsp_self_kill),
1238 accum_cck->dsp_self_kill);
1239 pos += scnprintf(buf + pos, bufsz - pos,
1240 "mh_format_err:\t\t%u\t\t\t%u\n",
1241 le32_to_cpu(cck->mh_format_err),
1242 accum_cck->mh_format_err);
1243 pos += scnprintf(buf + pos, bufsz - pos,
1244 "re_acq_main_rssi_sum:\t%u\t\t\t%u\n",
1245 le32_to_cpu(cck->re_acq_main_rssi_sum),
1246 accum_cck->re_acq_main_rssi_sum);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001247
1248 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - GENERAL:\n");
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001249 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001250 "\t\t\tcurrent\t\t\taccumulative\n");
1251 pos += scnprintf(buf + pos, bufsz - pos, "bogus_cts:\t\t%u\t\t\t%u\n",
1252 le32_to_cpu(general->bogus_cts),
1253 accum_general->bogus_cts);
1254 pos += scnprintf(buf + pos, bufsz - pos, "bogus_ack:\t\t%u\t\t\t%u\n",
1255 le32_to_cpu(general->bogus_ack),
1256 accum_general->bogus_ack);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001257 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001258 "non_bssid_frames:\t%u\t\t\t%u\n",
1259 le32_to_cpu(general->non_bssid_frames),
1260 accum_general->non_bssid_frames);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001261 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001262 "filtered_frames:\t%u\t\t\t%u\n",
1263 le32_to_cpu(general->filtered_frames),
1264 accum_general->filtered_frames);
1265 pos += scnprintf(buf + pos, bufsz - pos,
1266 "non_channel_beacons:\t%u\t\t\t%u\n",
1267 le32_to_cpu(general->non_channel_beacons),
1268 accum_general->non_channel_beacons);
1269 pos += scnprintf(buf + pos, bufsz - pos,
1270 "channel_beacons:\t%u\t\t\t%u\n",
1271 le32_to_cpu(general->channel_beacons),
1272 accum_general->channel_beacons);
1273 pos += scnprintf(buf + pos, bufsz - pos,
1274 "num_missed_bcon:\t%u\t\t\t%u\n",
1275 le32_to_cpu(general->num_missed_bcon),
1276 accum_general->num_missed_bcon);
1277 pos += scnprintf(buf + pos, bufsz - pos,
1278 "adc_rx_saturation_time:\t%u\t\t\t%u\n",
1279 le32_to_cpu(general->adc_rx_saturation_time),
1280 accum_general->adc_rx_saturation_time);
1281 pos += scnprintf(buf + pos, bufsz - pos,
1282 "ina_detect_search_tm:\t%u\t\t\t%u\n",
1283 le32_to_cpu(general->ina_detection_search_time),
1284 accum_general->ina_detection_search_time);
1285 pos += scnprintf(buf + pos, bufsz - pos,
1286 "beacon_silence_rssi_a:\t%u\t\t\t%u\n",
1287 le32_to_cpu(general->beacon_silence_rssi_a),
1288 accum_general->beacon_silence_rssi_a);
1289 pos += scnprintf(buf + pos, bufsz - pos,
1290 "beacon_silence_rssi_b:\t%u\t\t\t%u\n",
1291 le32_to_cpu(general->beacon_silence_rssi_b),
1292 accum_general->beacon_silence_rssi_b);
1293 pos += scnprintf(buf + pos, bufsz - pos,
1294 "beacon_silence_rssi_c:\t%u\t\t\t%u\n",
1295 le32_to_cpu(general->beacon_silence_rssi_c),
1296 accum_general->beacon_silence_rssi_c);
1297 pos += scnprintf(buf + pos, bufsz - pos,
1298 "interference_data_flag:\t%u\t\t\t%u\n",
1299 le32_to_cpu(general->interference_data_flag),
1300 accum_general->interference_data_flag);
1301 pos += scnprintf(buf + pos, bufsz - pos,
1302 "channel_load:\t\t%u\t\t\t%u\n",
1303 le32_to_cpu(general->channel_load),
1304 accum_general->channel_load);
1305 pos += scnprintf(buf + pos, bufsz - pos,
1306 "dsp_false_alarms:\t%u\t\t\t%u\n",
1307 le32_to_cpu(general->dsp_false_alarms),
1308 accum_general->dsp_false_alarms);
1309 pos += scnprintf(buf + pos, bufsz - pos,
1310 "beacon_rssi_a:\t\t%u\t\t\t%u\n",
1311 le32_to_cpu(general->beacon_rssi_a),
1312 accum_general->beacon_rssi_a);
1313 pos += scnprintf(buf + pos, bufsz - pos,
1314 "beacon_rssi_b:\t\t%u\t\t\t%u\n",
1315 le32_to_cpu(general->beacon_rssi_b),
1316 accum_general->beacon_rssi_b);
1317 pos += scnprintf(buf + pos, bufsz - pos,
1318 "beacon_rssi_c:\t\t%u\t\t\t%u\n",
1319 le32_to_cpu(general->beacon_rssi_c),
1320 accum_general->beacon_rssi_c);
1321 pos += scnprintf(buf + pos, bufsz - pos,
1322 "beacon_energy_a:\t%u\t\t\t%u\n",
1323 le32_to_cpu(general->beacon_energy_a),
1324 accum_general->beacon_energy_a);
1325 pos += scnprintf(buf + pos, bufsz - pos,
1326 "beacon_energy_b:\t%u\t\t\t%u\n",
1327 le32_to_cpu(general->beacon_energy_b),
1328 accum_general->beacon_energy_b);
1329 pos += scnprintf(buf + pos, bufsz - pos,
1330 "beacon_energy_c:\t%u\t\t\t%u\n",
1331 le32_to_cpu(general->beacon_energy_c),
1332 accum_general->beacon_energy_c);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001333
1334 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Rx - OFDM_HT:\n");
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001335 pos += scnprintf(buf + pos, bufsz - pos,
1336 "\t\t\tcurrent\t\t\taccumulative\n");
1337 pos += scnprintf(buf + pos, bufsz - pos, "plcp_err:\t\t%u\t\t\t%u\n",
1338 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err);
1339 pos += scnprintf(buf + pos, bufsz - pos,
1340 "overrun_err:\t\t%u\t\t\t%u\n",
1341 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err);
1342 pos += scnprintf(buf + pos, bufsz - pos,
1343 "early_overrun_err:\t%u\t\t\t%u\n",
1344 le32_to_cpu(ht->early_overrun_err),
1345 accum_ht->early_overrun_err);
1346 pos += scnprintf(buf + pos, bufsz - pos, "crc32_good:\t\t%u\t\t\t%u\n",
1347 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good);
1348 pos += scnprintf(buf + pos, bufsz - pos, "crc32_err:\t\t%u\t\t\t%u\n",
1349 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err);
1350 pos += scnprintf(buf + pos, bufsz - pos,
1351 "mh_format_err:\t\t%u\t\t\t%u\n",
1352 le32_to_cpu(ht->mh_format_err),
1353 accum_ht->mh_format_err);
1354 pos += scnprintf(buf + pos, bufsz - pos,
1355 "agg_crc32_good:\t\t%u\t\t\t%u\n",
1356 le32_to_cpu(ht->agg_crc32_good),
1357 accum_ht->agg_crc32_good);
1358 pos += scnprintf(buf + pos, bufsz - pos,
1359 "agg_mpdu_cnt:\t\t%u\t\t\t%u\n",
1360 le32_to_cpu(ht->agg_mpdu_cnt),
1361 accum_ht->agg_mpdu_cnt);
1362 pos += scnprintf(buf + pos, bufsz - pos, "agg_cnt:\t\t%u\t\t\t%u\n",
1363 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001364
1365 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1366 kfree(buf);
1367 return ret;
1368}
1369
1370static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1371 char __user *user_buf,
1372 size_t count, loff_t *ppos)
1373{
1374 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1375 int pos = 0;
1376 char *buf;
1377 int bufsz = (sizeof(struct statistics_tx) * 24) + 250;
1378 ssize_t ret;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001379 struct statistics_tx *tx, *accum_tx;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001380
1381 if (!iwl_is_alive(priv))
1382 return -EAGAIN;
1383
1384 /* make request to uCode to retrieve statistics information */
1385 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001386 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001387 mutex_unlock(&priv->mutex);
1388
1389 if (ret) {
1390 IWL_ERR(priv,
1391 "Error sending statistics request: %zd\n", ret);
1392 return -EAGAIN;
1393 }
1394 buf = kzalloc(bufsz, GFP_KERNEL);
1395 if (!buf) {
1396 IWL_ERR(priv, "Can not allocate Buffer\n");
1397 return -ENOMEM;
1398 }
1399
1400 /* the statistic information display here is based on
1401 * the last statistics notification from uCode
1402 * might not reflect the current uCode activity
1403 */
1404 tx = &priv->statistics.tx;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001405 accum_tx = &priv->accum_statistics.tx;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001406 pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
1407 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_Tx:\n");
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001408 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001409 "\t\t\tcurrent\t\t\taccumulative\n");
1410 pos += scnprintf(buf + pos, bufsz - pos, "preamble:\t\t\t%u\t\t\t%u\n",
1411 le32_to_cpu(tx->preamble_cnt),
1412 accum_tx->preamble_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001413 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001414 "rx_detected_cnt:\t\t%u\t\t\t%u\n",
1415 le32_to_cpu(tx->rx_detected_cnt),
1416 accum_tx->rx_detected_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001417 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001418 "bt_prio_defer_cnt:\t\t%u\t\t\t%u\n",
1419 le32_to_cpu(tx->bt_prio_defer_cnt),
1420 accum_tx->bt_prio_defer_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001421 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001422 "bt_prio_kill_cnt:\t\t%u\t\t\t%u\n",
1423 le32_to_cpu(tx->bt_prio_kill_cnt),
1424 accum_tx->bt_prio_kill_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001425 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001426 "few_bytes_cnt:\t\t\t%u\t\t\t%u\n",
1427 le32_to_cpu(tx->few_bytes_cnt),
1428 accum_tx->few_bytes_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001429 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001430 "cts_timeout:\t\t\t%u\t\t\t%u\n",
1431 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout);
1432 pos += scnprintf(buf + pos, bufsz - pos,
1433 "ack_timeout:\t\t\t%u\t\t\t%u\n",
1434 le32_to_cpu(tx->ack_timeout),
1435 accum_tx->ack_timeout);
1436 pos += scnprintf(buf + pos, bufsz - pos,
1437 "expected_ack_cnt:\t\t%u\t\t\t%u\n",
1438 le32_to_cpu(tx->expected_ack_cnt),
1439 accum_tx->expected_ack_cnt);
1440 pos += scnprintf(buf + pos, bufsz - pos,
1441 "actual_ack_cnt:\t\t\t%u\t\t\t%u\n",
1442 le32_to_cpu(tx->actual_ack_cnt),
1443 accum_tx->actual_ack_cnt);
1444 pos += scnprintf(buf + pos, bufsz - pos,
1445 "dump_msdu_cnt:\t\t\t%u\t\t\t%u\n",
1446 le32_to_cpu(tx->dump_msdu_cnt),
1447 accum_tx->dump_msdu_cnt);
1448 pos += scnprintf(buf + pos, bufsz - pos,
1449 "abort_nxt_frame_mismatch:"
1450 "\t%u\t\t\t%u\n",
1451 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1452 accum_tx->burst_abort_next_frame_mismatch_cnt);
1453 pos += scnprintf(buf + pos, bufsz - pos,
1454 "abort_missing_nxt_frame:"
1455 "\t%u\t\t\t%u\n",
1456 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1457 accum_tx->burst_abort_missing_next_frame_cnt);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 "cts_timeout_collision:\t\t%u\t\t\t%u\n",
1460 le32_to_cpu(tx->cts_timeout_collision),
1461 accum_tx->cts_timeout_collision);
1462 pos += scnprintf(buf + pos, bufsz - pos,
1463 "ack_ba_timeout_collision:\t%u\t\t\t%u\n",
1464 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1465 accum_tx->ack_or_ba_timeout_collision);
1466 pos += scnprintf(buf + pos, bufsz - pos,
1467 "agg ba_timeout:\t\t\t%u\t\t\t%u\n",
1468 le32_to_cpu(tx->agg.ba_timeout),
1469 accum_tx->agg.ba_timeout);
1470 pos += scnprintf(buf + pos, bufsz - pos,
1471 "agg ba_resched_frames:\t\t%u\t\t\t%u\n",
1472 le32_to_cpu(tx->agg.ba_reschedule_frames),
1473 accum_tx->agg.ba_reschedule_frames);
1474 pos += scnprintf(buf + pos, bufsz - pos,
1475 "agg scd_query_agg_frame:\t%u\t\t\t%u\n",
1476 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1477 accum_tx->agg.scd_query_agg_frame_cnt);
1478 pos += scnprintf(buf + pos, bufsz - pos,
1479 "agg scd_query_no_agg:\t\t%u\t\t\t%u\n",
1480 le32_to_cpu(tx->agg.scd_query_no_agg),
1481 accum_tx->agg.scd_query_no_agg);
1482 pos += scnprintf(buf + pos, bufsz - pos,
1483 "agg scd_query_agg:\t\t%u\t\t\t%u\n",
1484 le32_to_cpu(tx->agg.scd_query_agg),
1485 accum_tx->agg.scd_query_agg);
1486 pos += scnprintf(buf + pos, bufsz - pos,
1487 "agg scd_query_mismatch:\t\t%u\t\t\t%u\n",
1488 le32_to_cpu(tx->agg.scd_query_mismatch),
1489 accum_tx->agg.scd_query_mismatch);
1490 pos += scnprintf(buf + pos, bufsz - pos,
1491 "agg frame_not_ready:\t\t%u\t\t\t%u\n",
1492 le32_to_cpu(tx->agg.frame_not_ready),
1493 accum_tx->agg.frame_not_ready);
1494 pos += scnprintf(buf + pos, bufsz - pos,
1495 "agg underrun:\t\t\t%u\t\t\t%u\n",
1496 le32_to_cpu(tx->agg.underrun),
1497 accum_tx->agg.underrun);
1498 pos += scnprintf(buf + pos, bufsz - pos,
1499 "agg bt_prio_kill:\t\t%u\t\t\t%u\n",
1500 le32_to_cpu(tx->agg.bt_prio_kill),
1501 accum_tx->agg.bt_prio_kill);
1502 pos += scnprintf(buf + pos, bufsz - pos,
1503 "agg rx_ba_rsp_cnt:\t\t%u\t\t\t%u\n",
1504 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1505 accum_tx->agg.rx_ba_rsp_cnt);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001506
1507 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1508 kfree(buf);
1509 return ret;
1510}
1511
1512static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1513 char __user *user_buf,
1514 size_t count, loff_t *ppos)
1515{
1516 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1517 int pos = 0;
1518 char *buf;
1519 int bufsz = sizeof(struct statistics_general) * 4 + 250;
1520 ssize_t ret;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001521 struct statistics_general *general, *accum_general;
1522 struct statistics_dbg *dbg, *accum_dbg;
1523 struct statistics_div *div, *accum_div;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001524
1525 if (!iwl_is_alive(priv))
1526 return -EAGAIN;
1527
1528 /* make request to uCode to retrieve statistics information */
1529 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001530 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001531 mutex_unlock(&priv->mutex);
1532
1533 if (ret) {
1534 IWL_ERR(priv,
1535 "Error sending statistics request: %zd\n", ret);
1536 return -EAGAIN;
1537 }
1538 buf = kzalloc(bufsz, GFP_KERNEL);
1539 if (!buf) {
1540 IWL_ERR(priv, "Can not allocate Buffer\n");
1541 return -ENOMEM;
1542 }
1543
1544 /* the statistic information display here is based on
1545 * the last statistics notification from uCode
1546 * might not reflect the current uCode activity
1547 */
1548 general = &priv->statistics.general;
1549 dbg = &priv->statistics.general.dbg;
1550 div = &priv->statistics.general.div;
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001551 accum_general = &priv->accum_statistics.general;
1552 accum_dbg = &priv->accum_statistics.general.dbg;
1553 accum_div = &priv->accum_statistics.general.div;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001554 pos += iwl_dbgfs_statistics_flag(priv, buf, bufsz);
1555 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_General:\n");
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001556 pos += scnprintf(buf + pos, bufsz - pos,
1557 "\t\t\tcurrent\t\t\taccumulative\n");
1558 pos += scnprintf(buf + pos, bufsz - pos, "temperature:\t\t\t%u\n",
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001559 le32_to_cpu(general->temperature));
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001560 pos += scnprintf(buf + pos, bufsz - pos, "temperature_m:\t\t\t%u\n",
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001561 le32_to_cpu(general->temperature_m));
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001562 pos += scnprintf(buf + pos, bufsz - pos,
1563 "burst_check:\t\t\t%u\t\t\t%u\n",
1564 le32_to_cpu(dbg->burst_check),
1565 accum_dbg->burst_check);
1566 pos += scnprintf(buf + pos, bufsz - pos,
1567 "burst_count:\t\t\t%u\t\t\t%u\n",
1568 le32_to_cpu(dbg->burst_count),
1569 accum_dbg->burst_count);
1570 pos += scnprintf(buf + pos, bufsz - pos,
1571 "sleep_time:\t\t\t%u\t\t\t%u\n",
1572 le32_to_cpu(general->sleep_time),
1573 accum_general->sleep_time);
1574 pos += scnprintf(buf + pos, bufsz - pos,
1575 "slots_out:\t\t\t%u\t\t\t%u\n",
1576 le32_to_cpu(general->slots_out),
1577 accum_general->slots_out);
1578 pos += scnprintf(buf + pos, bufsz - pos,
1579 "slots_idle:\t\t\t%u\t\t\t%u\n",
1580 le32_to_cpu(general->slots_idle),
1581 accum_general->slots_idle);
1582 pos += scnprintf(buf + pos, bufsz - pos, "ttl_timestamp:\t\t\t%u\n",
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001583 le32_to_cpu(general->ttl_timestamp));
Wey-Yi Guy92a35bd2009-10-09 13:20:29 -07001584 pos += scnprintf(buf + pos, bufsz - pos, "tx_on_a:\t\t\t%u\t\t\t%u\n",
1585 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a);
1586 pos += scnprintf(buf + pos, bufsz - pos, "tx_on_b:\t\t\t%u\t\t\t%u\n",
1587 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b);
1588 pos += scnprintf(buf + pos, bufsz - pos,
1589 "exec_time:\t\t\t%u\t\t\t%u\n",
1590 le32_to_cpu(div->exec_time), accum_div->exec_time);
1591 pos += scnprintf(buf + pos, bufsz - pos,
1592 "probe_time:\t\t\t%u\t\t\t%u\n",
1593 le32_to_cpu(div->probe_time), accum_div->probe_time);
1594 pos += scnprintf(buf + pos, bufsz - pos,
1595 "rx_enable_counter:\t\t%u\t\t\t%u\n",
1596 le32_to_cpu(general->rx_enable_counter),
1597 accum_general->rx_enable_counter);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001598 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1599 kfree(buf);
1600 return ret;
1601}
1602
Wey-Yi Guy52259352009-08-07 15:41:43 -07001603static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1604 char __user *user_buf,
1605 size_t count, loff_t *ppos) {
1606
1607 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1608 int pos = 0;
1609 int cnt = 0;
1610 char *buf;
1611 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1612 ssize_t ret;
1613 struct iwl_sensitivity_data *data;
1614
1615 data = &priv->sensitivity_data;
1616 buf = kzalloc(bufsz, GFP_KERNEL);
1617 if (!buf) {
1618 IWL_ERR(priv, "Can not allocate Buffer\n");
1619 return -ENOMEM;
1620 }
1621
1622 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1623 data->auto_corr_ofdm);
1624 pos += scnprintf(buf + pos, bufsz - pos,
1625 "auto_corr_ofdm_mrc:\t\t %u\n",
1626 data->auto_corr_ofdm_mrc);
1627 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1628 data->auto_corr_ofdm_x1);
1629 pos += scnprintf(buf + pos, bufsz - pos,
1630 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1631 data->auto_corr_ofdm_mrc_x1);
1632 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1633 data->auto_corr_cck);
1634 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1635 data->auto_corr_cck_mrc);
1636 pos += scnprintf(buf + pos, bufsz - pos,
1637 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1638 data->last_bad_plcp_cnt_ofdm);
1639 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1640 data->last_fa_cnt_ofdm);
1641 pos += scnprintf(buf + pos, bufsz - pos,
1642 "last_bad_plcp_cnt_cck:\t\t %u\n",
1643 data->last_bad_plcp_cnt_cck);
1644 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1645 data->last_fa_cnt_cck);
1646 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1647 data->nrg_curr_state);
1648 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1649 data->nrg_prev_state);
1650 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1651 for (cnt = 0; cnt < 10; cnt++) {
1652 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1653 data->nrg_value[cnt]);
1654 }
1655 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1656 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1657 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1658 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1659 data->nrg_silence_rssi[cnt]);
1660 }
1661 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1662 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1663 data->nrg_silence_ref);
1664 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1665 data->nrg_energy_idx);
1666 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1667 data->nrg_silence_idx);
1668 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1669 data->nrg_th_cck);
1670 pos += scnprintf(buf + pos, bufsz - pos,
1671 "nrg_auto_corr_silence_diff:\t %u\n",
1672 data->nrg_auto_corr_silence_diff);
1673 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1674 data->num_in_cck_no_fa);
1675 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1676 data->nrg_th_ofdm);
1677
1678 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1679 kfree(buf);
1680 return ret;
1681}
1682
1683
1684static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1685 char __user *user_buf,
1686 size_t count, loff_t *ppos) {
1687
1688 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1689 int pos = 0;
1690 int cnt = 0;
1691 char *buf;
1692 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1693 ssize_t ret;
1694 struct iwl_chain_noise_data *data;
1695
1696 data = &priv->chain_noise_data;
1697 buf = kzalloc(bufsz, GFP_KERNEL);
1698 if (!buf) {
1699 IWL_ERR(priv, "Can not allocate Buffer\n");
1700 return -ENOMEM;
1701 }
1702
1703 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1704 data->active_chains);
1705 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1706 data->chain_noise_a);
1707 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1708 data->chain_noise_b);
1709 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1710 data->chain_noise_c);
1711 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1712 data->chain_signal_a);
1713 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1714 data->chain_signal_b);
1715 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1716 data->chain_signal_c);
1717 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1718 data->beacon_count);
1719
1720 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1721 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1722 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1723 data->disconn_array[cnt]);
1724 }
1725 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1726 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1727 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1728 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1729 data->delta_gain_code[cnt]);
1730 }
1731 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1732 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1733 data->radio_write);
1734 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1735 data->state);
1736
1737 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1738 kfree(buf);
1739 return ret;
1740}
1741
Wey-Yi Guyf204b242009-08-21 13:34:19 -07001742static ssize_t iwl_dbgfs_tx_power_read(struct file *file,
1743 char __user *user_buf,
1744 size_t count, loff_t *ppos) {
1745
1746 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1747 char buf[128];
1748 int pos = 0;
1749 ssize_t ret;
1750 const size_t bufsz = sizeof(buf);
1751 struct statistics_tx *tx;
1752
1753 if (!iwl_is_alive(priv))
1754 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1755 else {
1756 /* make request to uCode to retrieve statistics information */
1757 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001758 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Wey-Yi Guyf204b242009-08-21 13:34:19 -07001759 mutex_unlock(&priv->mutex);
1760
1761 if (ret) {
1762 IWL_ERR(priv, "Error sending statistics request: %zd\n",
1763 ret);
1764 return -EAGAIN;
1765 }
1766 tx = &priv->statistics.tx;
1767 if (tx->tx_power.ant_a ||
1768 tx->tx_power.ant_b ||
1769 tx->tx_power.ant_c) {
1770 pos += scnprintf(buf + pos, bufsz - pos,
1771 "tx power: (1/2 dB step)\n");
1772 if ((priv->cfg->valid_tx_ant & ANT_A) &&
1773 tx->tx_power.ant_a)
1774 pos += scnprintf(buf + pos, bufsz - pos,
1775 "\tantenna A: 0x%X\n",
1776 tx->tx_power.ant_a);
1777 if ((priv->cfg->valid_tx_ant & ANT_B) &&
1778 tx->tx_power.ant_b)
1779 pos += scnprintf(buf + pos, bufsz - pos,
1780 "\tantenna B: 0x%X\n",
1781 tx->tx_power.ant_b);
1782 if ((priv->cfg->valid_tx_ant & ANT_C) &&
1783 tx->tx_power.ant_c)
1784 pos += scnprintf(buf + pos, bufsz - pos,
1785 "\tantenna C: 0x%X\n",
1786 tx->tx_power.ant_c);
1787 } else
1788 pos += scnprintf(buf + pos, bufsz - pos, "N/A\n");
1789 }
1790 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1791}
1792
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001793static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1794 char __user *user_buf,
1795 size_t count, loff_t *ppos)
1796{
1797 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1798 char buf[60];
1799 int pos = 0;
1800 const size_t bufsz = sizeof(buf);
1801 u32 pwrsave_status;
1802
1803 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1804 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1805
1806 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1807 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1808 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1809 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1810 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1811 "error");
1812
1813 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1814}
1815
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001816static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001817 const char __user *user_buf,
1818 size_t count, loff_t *ppos)
1819{
1820 struct iwl_priv *priv = file->private_data;
1821 char buf[8];
1822 int buf_size;
1823 int clear;
1824
1825 memset(buf, 0, sizeof(buf));
1826 buf_size = min(count, sizeof(buf) - 1);
1827 if (copy_from_user(buf, user_buf, buf_size))
1828 return -EFAULT;
1829 if (sscanf(buf, "%d", &clear) != 1)
1830 return -EFAULT;
1831
1832 /* make request to uCode to retrieve statistics information */
1833 mutex_lock(&priv->mutex);
1834 iwl_send_statistics_request(priv, CMD_SYNC, true);
1835 mutex_unlock(&priv->mutex);
1836
1837 return count;
1838}
1839
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001840DEBUGFS_READ_FILE_OPS(rx_statistics);
1841DEBUGFS_READ_FILE_OPS(tx_statistics);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001842DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001843DEBUGFS_READ_FILE_OPS(rx_queue);
1844DEBUGFS_READ_FILE_OPS(tx_queue);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001845DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1846DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1847DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07001848DEBUGFS_READ_FILE_OPS(sensitivity);
1849DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyf204b242009-08-21 13:34:19 -07001850DEBUGFS_READ_FILE_OPS(tx_power);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001851DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001852DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1853DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001854
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001855/*
1856 * Create the debugfs files and directories
1857 *
1858 */
1859int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1860{
1861 struct iwl_debugfs *dbgfs;
Zhu Yi95b1a822008-05-29 16:34:50 +08001862 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001863 int ret = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001864
1865 dbgfs = kzalloc(sizeof(struct iwl_debugfs), GFP_KERNEL);
1866 if (!dbgfs) {
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001867 ret = -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001868 goto err;
1869 }
1870
1871 priv->dbgfs = dbgfs;
1872 dbgfs->name = name;
Zhu Yi95b1a822008-05-29 16:34:50 +08001873 dbgfs->dir_drv = debugfs_create_dir(name, phyd);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001874 if (!dbgfs->dir_drv || IS_ERR(dbgfs->dir_drv)) {
1875 ret = -ENOENT;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001876 goto err;
1877 }
1878
1879 DEBUGFS_ADD_DIR(data, dbgfs->dir_drv);
Tomas Winkler445c2df2008-05-15 13:54:16 +08001880 DEBUGFS_ADD_DIR(rf, dbgfs->dir_drv);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001881 DEBUGFS_ADD_DIR(debug, dbgfs->dir_drv);
Wey-Yi Guy43e85112009-11-20 12:04:58 -08001882 DEBUGFS_ADD_FILE(nvm, data, S_IRUSR);
1883 DEBUGFS_ADD_FILE(sram, data, S_IWUSR | S_IRUSR);
1884 DEBUGFS_ADD_FILE(log_event, data, S_IWUSR);
1885 DEBUGFS_ADD_FILE(stations, data, S_IRUSR);
1886 DEBUGFS_ADD_FILE(channels, data, S_IRUSR);
1887 DEBUGFS_ADD_FILE(status, data, S_IRUSR);
1888 DEBUGFS_ADD_FILE(interrupt, data, S_IWUSR | S_IRUSR);
1889 DEBUGFS_ADD_FILE(qos, data, S_IRUSR);
1890 DEBUGFS_ADD_FILE(led, data, S_IRUSR);
1891 DEBUGFS_ADD_FILE(sleep_level_override, data, S_IWUSR | S_IRUSR);
1892 DEBUGFS_ADD_FILE(current_sleep_command, data, S_IRUSR);
1893 DEBUGFS_ADD_FILE(thermal_throttling, data, S_IRUSR);
1894 DEBUGFS_ADD_FILE(disable_ht40, data, S_IWUSR | S_IRUSR);
1895 DEBUGFS_ADD_FILE(rx_statistics, debug, S_IRUSR);
1896 DEBUGFS_ADD_FILE(tx_statistics, debug, S_IRUSR);
1897 DEBUGFS_ADD_FILE(traffic_log, debug, S_IWUSR | S_IRUSR);
1898 DEBUGFS_ADD_FILE(rx_queue, debug, S_IRUSR);
1899 DEBUGFS_ADD_FILE(tx_queue, debug, S_IRUSR);
1900 DEBUGFS_ADD_FILE(tx_power, debug, S_IRUSR);
1901 DEBUGFS_ADD_FILE(power_save_status, debug, S_IRUSR);
1902 DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR);
1903 DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001904 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
Wey-Yi Guy43e85112009-11-20 12:04:58 -08001905 DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR);
1906 DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR);
1907 DEBUGFS_ADD_FILE(ucode_general_stats, debug, S_IRUSR);
1908 DEBUGFS_ADD_FILE(sensitivity, debug, S_IRUSR);
1909 DEBUGFS_ADD_FILE(chain_noise, debug, S_IRUSR);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001910 }
Tomas Winkler445c2df2008-05-15 13:54:16 +08001911 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
1912 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
1913 &priv->disable_chain_noise_cal);
Wey-Yi Guy030b8652009-06-12 13:22:55 -07001914 if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
1915 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
1916 DEBUGFS_ADD_BOOL(disable_tx_power, rf,
1917 &priv->disable_tx_power_cal);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001918 return 0;
1919
1920err:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001921 IWL_ERR(priv, "Can't open the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001922 iwl_dbgfs_unregister(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001923 return ret;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001924}
1925EXPORT_SYMBOL(iwl_dbgfs_register);
1926
1927/**
1928 * Remove the debugfs files and directories
1929 *
1930 */
1931void iwl_dbgfs_unregister(struct iwl_priv *priv)
1932{
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001933 if (!priv->dbgfs)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001934 return;
1935
Johannes Berge312c242009-08-07 15:41:51 -07001936 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sleep_level_override);
1937 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_current_sleep_command);
Wey-Yi Guy0848e292009-05-22 11:01:46 -07001938 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001939 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_sram);
Ester Kummer189a2b52008-05-15 13:54:18 +08001940 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_log_event);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001941 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -08001942 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -07001943 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001944 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -07001945 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_qos);
Wey-Yi Guya283c012009-07-17 09:30:19 -07001946 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_led);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -07001947 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -07001948 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_disable_ht40);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001949 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -07001950 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_statistics);
1951 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_statistics);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001952 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_traffic_log);
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001953 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_rx_queue);
1954 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_queue);
Wey-Yi Guyf204b242009-08-21 13:34:19 -07001955 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_tx_power);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001956 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001957 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1958 file_clear_ucode_statistics);
1959 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1960 file_clear_traffic_statistics);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001961 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) {
1962 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1963 file_ucode_rx_stats);
1964 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1965 file_ucode_tx_stats);
1966 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1967 file_ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07001968 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1969 file_sensitivity);
1970 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.
1971 file_chain_noise);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001972 }
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001973 DEBUGFS_REMOVE(priv->dbgfs->dir_debug);
Tomas Winkler445c2df2008-05-15 13:54:16 +08001974 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
1975 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
Wey-Yi Guy030b8652009-06-12 13:22:55 -07001976 if (((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965) ||
1977 ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_3945))
1978 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_tx_power);
Tomas Winkler445c2df2008-05-15 13:54:16 +08001979 DEBUGFS_REMOVE(priv->dbgfs->dir_rf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001980 DEBUGFS_REMOVE(priv->dbgfs->dir_drv);
1981 kfree(priv->dbgfs);
1982 priv->dbgfs = NULL;
1983}
1984EXPORT_SYMBOL(iwl_dbgfs_unregister);
1985
1986
Tomas Winkler445c2df2008-05-15 13:54:16 +08001987