blob: bf2a678970a9a08ada4efe209a53d491fece370b [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07005 * Copyright(c) 2008 - 2011 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
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h>
35#include <net/mac80211.h>
36
37
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070039#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070040#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070041#include "iwl-io.h"
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -070042#include "iwl-agn.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070043
44/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080045#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
46 if (!debugfs_create_file(#name, mode, parent, priv, \
47 &iwl_dbgfs_##name##_ops)) \
48 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070049} while (0)
50
Johannes Berg4c84a8f2010-01-22 14:22:54 -080051#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
52 struct dentry *__tmp; \
53 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
54 parent, ptr); \
55 if (IS_ERR(__tmp) || !__tmp) \
56 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070057} while (0)
58
Johannes Berg4c84a8f2010-01-22 14:22:54 -080059#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
60 struct dentry *__tmp; \
61 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
62 parent, ptr); \
63 if (IS_ERR(__tmp) || !__tmp) \
64 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080065} while (0)
66
Johannes Bergca934b62011-09-15 11:46:48 -070067#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
68 struct dentry *__tmp; \
69 __tmp = debugfs_create_u32(#name, mode, \
70 parent, ptr); \
71 if (IS_ERR(__tmp) || !__tmp) \
72 goto err; \
73} while (0)
74
Tomas Winkler712b6cf2008-03-12 16:58:52 -070075/* file operation */
76#define DEBUGFS_READ_FUNC(name) \
77static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
78 char __user *user_buf, \
79 size_t count, loff_t *ppos);
80
81#define DEBUGFS_WRITE_FUNC(name) \
82static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
83 const char __user *user_buf, \
84 size_t count, loff_t *ppos);
85
86
87static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
88{
89 file->private_data = inode->i_private;
90 return 0;
91}
92
93#define DEBUGFS_READ_FILE_OPS(name) \
94 DEBUGFS_READ_FUNC(name); \
95static const struct file_operations iwl_dbgfs_##name##_ops = { \
96 .read = iwl_dbgfs_##name##_read, \
97 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020098 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070099};
100
Ester Kummer189a2b52008-05-15 13:54:18 +0800101#define DEBUGFS_WRITE_FILE_OPS(name) \
102 DEBUGFS_WRITE_FUNC(name); \
103static const struct file_operations iwl_dbgfs_##name##_ops = { \
104 .write = iwl_dbgfs_##name##_write, \
105 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200106 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800107};
108
109
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700110#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
111 DEBUGFS_READ_FUNC(name); \
112 DEBUGFS_WRITE_FUNC(name); \
113static const struct file_operations iwl_dbgfs_##name##_ops = { \
114 .write = iwl_dbgfs_##name##_write, \
115 .read = iwl_dbgfs_##name##_read, \
116 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200117 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700118};
119
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
121 char __user *user_buf,
122 size_t count, loff_t *ppos) {
123
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700124 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700125 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700126 int pos = 0;
127
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700128 int cnt;
129 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800130 const size_t bufsz = 100 +
131 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700132 buf = kzalloc(bufsz, GFP_KERNEL);
133 if (!buf)
134 return -ENOMEM;
135 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
136 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
137 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800138 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700139 get_mgmt_string(cnt),
140 priv->tx_stats.mgmt[cnt]);
141 }
142 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
143 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
144 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800145 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700146 get_ctrl_string(cnt),
147 priv->tx_stats.ctrl[cnt]);
148 }
149 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
150 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
151 priv->tx_stats.data_cnt);
152 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
153 priv->tx_stats.data_bytes);
154 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
155 kfree(buf);
156 return ret;
157}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700158
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800159static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700160 const char __user *user_buf,
161 size_t count, loff_t *ppos)
162{
163 struct iwl_priv *priv = file->private_data;
164 u32 clear_flag;
165 char buf[8];
166 int buf_size;
167
168 memset(buf, 0, sizeof(buf));
169 buf_size = min(count, sizeof(buf) - 1);
170 if (copy_from_user(buf, user_buf, buf_size))
171 return -EFAULT;
172 if (sscanf(buf, "%x", &clear_flag) != 1)
173 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800174 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700175
176 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700177}
178
179static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
180 char __user *user_buf,
181 size_t count, loff_t *ppos) {
182
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700183 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700184 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700185 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700186 int cnt;
187 ssize_t ret;
188 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800189 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700190 buf = kzalloc(bufsz, GFP_KERNEL);
191 if (!buf)
192 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700193
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700194 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
195 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
196 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800197 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700198 get_mgmt_string(cnt),
199 priv->rx_stats.mgmt[cnt]);
200 }
201 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
202 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
203 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800204 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700205 get_ctrl_string(cnt),
206 priv->rx_stats.ctrl[cnt]);
207 }
208 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
209 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
210 priv->rx_stats.data_cnt);
211 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
212 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700213
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700214 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
215 kfree(buf);
216 return ret;
217}
218
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700219static ssize_t iwl_dbgfs_sram_read(struct file *file,
220 char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
Jay Sternberg24834d22011-01-11 15:41:00 -0800223 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800224 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700225 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800226 int i = 0;
227 bool device_format = false;
228 int offset = 0;
229 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800231 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700232 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800233 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700234
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800235 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800236 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
237 priv->dbgfs_sram_offset = 0x800000;
Johannes Berg872907b2011-06-06 09:41:15 -0700238 if (priv->ucode_type == IWL_UCODE_INIT)
Johannes Bergdbf28e212011-04-16 08:29:24 -0700239 priv->dbgfs_sram_len = priv->ucode_init.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800240 else
Johannes Bergdbf28e212011-04-16 08:29:24 -0700241 priv->dbgfs_sram_len = priv->ucode_rt.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800242 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800243 len = priv->dbgfs_sram_len;
244
245 if (len == -4) {
246 device_format = true;
247 len = 4;
248 }
249
250 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800251 buf = kmalloc(bufsz, GFP_KERNEL);
252 if (!buf)
253 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800254
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800255 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800256 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800257 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800258 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800259
260 /* adjust sram address since reads are only on even u32 boundaries */
261 offset = priv->dbgfs_sram_offset & 0x3;
262 sram = priv->dbgfs_sram_offset & ~0x3;
263
264 /* read the first u32 from sram */
Emmanuel Grumbach83ed9012011-08-25 23:11:14 -0700265 val = iwl_read_targ_mem(bus(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800266
267 for (; len; len--) {
268 /* put the address at the start of every line */
269 if (i == 0)
270 pos += scnprintf(buf + pos, bufsz - pos,
271 "%08X: ", sram + offset);
272
273 if (device_format)
274 pos += scnprintf(buf + pos, bufsz - pos,
275 "%02x", (val >> (8 * (3 - offset))) & 0xff);
276 else
277 pos += scnprintf(buf + pos, bufsz - pos,
278 "%02x ", (val >> (8 * offset)) & 0xff);
279
280 /* if all bytes processed, read the next u32 from sram */
281 if (++offset == 4) {
282 sram += 4;
283 offset = 0;
Emmanuel Grumbach83ed9012011-08-25 23:11:14 -0700284 val = iwl_read_targ_mem(bus(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700285 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800286
287 /* put in extra spaces and split lines for human readability */
288 if (++i == 16) {
289 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800290 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800291 } else if (!(i & 7)) {
292 pos += scnprintf(buf + pos, bufsz - pos, " ");
293 } else if (!(i & 3)) {
294 pos += scnprintf(buf + pos, bufsz - pos, " ");
295 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700296 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800297 if (i)
298 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700299
300 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800301 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700302 return ret;
303}
304
305static ssize_t iwl_dbgfs_sram_write(struct file *file,
306 const char __user *user_buf,
307 size_t count, loff_t *ppos)
308{
309 struct iwl_priv *priv = file->private_data;
310 char buf[64];
311 int buf_size;
312 u32 offset, len;
313
314 memset(buf, 0, sizeof(buf));
315 buf_size = min(count, sizeof(buf) - 1);
316 if (copy_from_user(buf, user_buf, buf_size))
317 return -EFAULT;
318
319 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800320 priv->dbgfs_sram_offset = offset;
321 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800322 } else if (sscanf(buf, "%x", &offset) == 1) {
323 priv->dbgfs_sram_offset = offset;
324 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700325 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800326 priv->dbgfs_sram_offset = 0;
327 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700328 }
329
330 return count;
331}
332
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700333static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
334 char __user *user_buf,
335 size_t count, loff_t *ppos)
336{
337 struct iwl_priv *priv = file->private_data;
338
339 if (!priv->wowlan_sram)
340 return -ENODATA;
341
342 return simple_read_from_buffer(user_buf, count, ppos,
343 priv->wowlan_sram,
344 priv->ucode_wowlan.data.len);
345}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700346static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
347 size_t count, loff_t *ppos)
348{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700349 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800350 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700351 struct iwl_tid_data *tid_data;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700352 int max_sta = hw_params(priv).max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700353 char *buf;
354 int i, j, pos = 0;
355 ssize_t ret;
356 /* Add 30 for initial string */
357 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700358
359 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300360 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700361 return -ENOMEM;
362
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700363 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700364 priv->num_stations);
365
366 for (i = 0; i < max_sta; i++) {
367 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700368 if (!station->used)
369 continue;
370 pos += scnprintf(buf + pos, bufsz - pos,
371 "station %d - addr: %pM, flags: %#x\n",
372 i, station->sta.sta.addr,
373 station->sta.station_flags_msk);
374 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700375 "TID\tseq_num\ttxq_id\ttfds\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700376
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700377 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
378 tid_data = &priv->shrd->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700379 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700380 "%d:\t%#x\t%#x\t%u\t%#x",
381 j, tid_data->seq_number,
382 tid_data->agg.txq_id,
383 tid_data->tfds_in_queue,
384 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700385
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700386 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700387 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700388 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700389 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700390 }
Johannes Bergda735112010-05-03 01:25:24 -0700391
392 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700393 }
394
395 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
396 kfree(buf);
397 return ret;
398}
399
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700400static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800401 char __user *user_buf,
402 size_t count,
403 loff_t *ppos)
404{
405 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700406 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800407 int pos = 0, ofs = 0, buf_size = 0;
408 const u8 *ptr;
409 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700410 u16 eeprom_ver;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700411 size_t eeprom_len = priv->cfg->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800412 buf_size = 4 * eeprom_len + 256;
413
414 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700415 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800416 return -ENODATA;
417 }
418
Julia Lawallc37457e2009-08-03 11:11:45 +0200419 ptr = priv->eeprom;
420 if (!ptr) {
421 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
422 return -ENOMEM;
423 }
424
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800425 /* 4 characters for byte 0xYY */
426 buf = kzalloc(buf_size, GFP_KERNEL);
427 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800428 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800429 return -ENOMEM;
430 }
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700431 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
432 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
433 "version: 0x%x\n",
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700434 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700435 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800436 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
437 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
438 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
439 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700440 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800441 if (buf_size - pos > 0)
442 buf[pos++] = '\n';
443 }
444
445 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
446 kfree(buf);
447 return ret;
448}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700449
Winkler, Tomasd366df52008-12-02 12:14:01 -0800450static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
451 size_t count, loff_t *ppos)
452{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700453 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800454 struct ieee80211_channel *channels = NULL;
455 const struct ieee80211_supported_band *supp_band = NULL;
456 int pos = 0, i, bufsz = PAGE_SIZE;
457 char *buf;
458 ssize_t ret;
459
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700460 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800461 return -EAGAIN;
462
463 buf = kzalloc(bufsz, GFP_KERNEL);
464 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800465 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800466 return -ENOMEM;
467 }
468
469 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700470 if (supp_band) {
471 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800472
Winkler, Tomasd366df52008-12-02 12:14:01 -0800473 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700474 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
475 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800476
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700477 for (i = 0; i < supp_band->n_channels; i++)
478 pos += scnprintf(buf + pos, bufsz - pos,
479 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700480 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700481 channels[i].max_power,
482 channels[i].flags & IEEE80211_CHAN_RADAR ?
483 " (IEEE 802.11h required)" : "",
484 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
485 || (channels[i].flags &
486 IEEE80211_CHAN_RADAR)) ? "" :
487 ", IBSS",
488 channels[i].flags &
489 IEEE80211_CHAN_PASSIVE_SCAN ?
490 "passive only" : "active/passive");
491 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800492 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700493 if (supp_band) {
494 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800495
Winkler, Tomasd366df52008-12-02 12:14:01 -0800496 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700497 "Displaying %d channels in 5.2GHz band (802.11a)\n",
498 supp_band->n_channels);
499
500 for (i = 0; i < supp_band->n_channels; i++)
501 pos += scnprintf(buf + pos, bufsz - pos,
502 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700503 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700504 channels[i].max_power,
505 channels[i].flags & IEEE80211_CHAN_RADAR ?
506 " (IEEE 802.11h required)" : "",
507 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
508 || (channels[i].flags &
509 IEEE80211_CHAN_RADAR)) ? "" :
510 ", IBSS",
511 channels[i].flags &
512 IEEE80211_CHAN_PASSIVE_SCAN ?
513 "passive only" : "active/passive");
514 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800515 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
516 kfree(buf);
517 return ret;
518}
519
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700520static ssize_t iwl_dbgfs_status_read(struct file *file,
521 char __user *user_buf,
522 size_t count, loff_t *ppos) {
523
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700524 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700525 char buf[512];
526 int pos = 0;
527 const size_t bufsz = sizeof(buf);
528
529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700530 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700532 test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700534 test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700536 test_bit(STATUS_CT_KILL, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700538 test_bit(STATUS_INIT, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700540 test_bit(STATUS_ALIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700542 test_bit(STATUS_READY, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700544 test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700546 test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700548 test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700550 test_bit(STATUS_STATISTICS, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700552 test_bit(STATUS_SCANNING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700553 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700554 test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700555 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700556 test_bit(STATUS_SCAN_HW, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700557 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700558 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700559 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700560 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700561 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
562}
563
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700564static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700565 char __user *user_buf,
566 size_t count, loff_t *ppos) {
567
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700568 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700569
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700570 int pos = 0;
571 int cnt = 0;
572 char *buf;
573 int bufsz = 24 * 64; /* 24 items * 64 char per item */
574 ssize_t ret;
575
576 buf = kzalloc(bufsz, GFP_KERNEL);
577 if (!buf) {
578 IWL_ERR(priv, "Can not allocate Buffer\n");
579 return -ENOMEM;
580 }
581
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700582 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700583 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700584 pos += scnprintf(buf + pos, bufsz - pos,
585 "\tRx handler[%36s]:\t\t %u\n",
586 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700587 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700588 }
589
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700590 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
591 kfree(buf);
592 return ret;
593}
594
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700595static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700596 const char __user *user_buf,
597 size_t count, loff_t *ppos)
598{
599 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700600
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700601 char buf[8];
602 int buf_size;
603 u32 reset_flag;
604
605 memset(buf, 0, sizeof(buf));
606 buf_size = min(count, sizeof(buf) - 1);
607 if (copy_from_user(buf, user_buf, buf_size))
608 return -EFAULT;
609 if (sscanf(buf, "%x", &reset_flag) != 1)
610 return -EFAULT;
611 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700612 memset(&priv->rx_handlers_stats[0], 0,
613 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700614
615 return count;
616}
617
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700618static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
619 size_t count, loff_t *ppos)
620{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700621 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200622 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700623 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200624 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700625 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700626
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200627 for_each_context(priv, ctx) {
628 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
629 ctx->ctxid);
630 for (i = 0; i < AC_NUM; i++) {
631 pos += scnprintf(buf + pos, bufsz - pos,
632 "\tcw_min\tcw_max\taifsn\ttxop\n");
633 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700634 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200635 ctx->qos_data.def_qos_parm.ac[i].cw_min,
636 ctx->qos_data.def_qos_parm.ac[i].cw_max,
637 ctx->qos_data.def_qos_parm.ac[i].aifsn,
638 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
639 }
640 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700641 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800642 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700643}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700644
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700645static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
646 char __user *user_buf,
647 size_t count, loff_t *ppos)
648{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700649 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700650 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700651 struct iwl_tt_restriction *restriction;
652 char buf[100];
653 int pos = 0;
654 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700655
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700658 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700659 pos += scnprintf(buf + pos, bufsz - pos,
660 "Thermal Throttling State: %d\n",
661 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700662 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700663 restriction = tt->restriction + tt->state;
664 pos += scnprintf(buf + pos, bufsz - pos,
665 "Tx mode: %d\n",
666 restriction->tx_stream);
667 pos += scnprintf(buf + pos, bufsz - pos,
668 "Rx mode: %d\n",
669 restriction->rx_stream);
670 pos += scnprintf(buf + pos, bufsz - pos,
671 "HT mode: %d\n",
672 restriction->is_ht);
673 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800674 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700675}
676
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700677static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
678 const char __user *user_buf,
679 size_t count, loff_t *ppos)
680{
681 struct iwl_priv *priv = file->private_data;
682 char buf[8];
683 int buf_size;
684 int ht40;
685
686 memset(buf, 0, sizeof(buf));
687 buf_size = min(count, sizeof(buf) - 1);
688 if (copy_from_user(buf, user_buf, buf_size))
689 return -EFAULT;
690 if (sscanf(buf, "%d", &ht40) != 1)
691 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200692 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700693 priv->disable_ht40 = ht40 ? true : false;
694 else {
695 IWL_ERR(priv, "Sta associated with AP - "
696 "Change to 40MHz channel support is not allowed\n");
697 return -EINVAL;
698 }
699
700 return count;
701}
702
703static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
704 char __user *user_buf,
705 size_t count, loff_t *ppos)
706{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700707 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700708 char buf[100];
709 int pos = 0;
710 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700711
712 pos += scnprintf(buf + pos, bufsz - pos,
713 "11n 40MHz Mode: %s\n",
714 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800715 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700716}
717
Johannes Berge312c242009-08-07 15:41:51 -0700718static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
719 const char __user *user_buf,
720 size_t count, loff_t *ppos)
721{
722 struct iwl_priv *priv = file->private_data;
723 char buf[8];
724 int buf_size;
725 int value;
726
727 memset(buf, 0, sizeof(buf));
728 buf_size = min(count, sizeof(buf) - 1);
729 if (copy_from_user(buf, user_buf, buf_size))
730 return -EFAULT;
731
732 if (sscanf(buf, "%d", &value) != 1)
733 return -EINVAL;
734
735 /*
736 * Our users expect 0 to be "CAM", but 0 isn't actually
737 * valid here. However, let's not confuse them and present
738 * IWL_POWER_INDEX_1 as "1", not "0".
739 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700740 if (value == 0)
741 return -EINVAL;
742 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700743 value -= 1;
744
745 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
746 return -EINVAL;
747
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700748 if (!iwl_is_ready_rf(priv->shrd))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700749 return -EAGAIN;
750
Johannes Berge312c242009-08-07 15:41:51 -0700751 priv->power_data.debug_sleep_level_override = value;
752
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700753 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700754 iwl_power_update_mode(priv, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700755 mutex_unlock(&priv->shrd->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700756
757 return count;
758}
759
760static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
761 char __user *user_buf,
762 size_t count, loff_t *ppos)
763{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700764 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700765 char buf[10];
766 int pos, value;
767 const size_t bufsz = sizeof(buf);
768
769 /* see the write function */
770 value = priv->power_data.debug_sleep_level_override;
771 if (value >= 0)
772 value += 1;
773
774 pos = scnprintf(buf, bufsz, "%d\n", value);
775 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
776}
777
778static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
779 char __user *user_buf,
780 size_t count, loff_t *ppos)
781{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700782 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700783 char buf[200];
784 int pos = 0, i;
785 const size_t bufsz = sizeof(buf);
786 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
787
788 pos += scnprintf(buf + pos, bufsz - pos,
789 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
790 pos += scnprintf(buf + pos, bufsz - pos,
791 "RX/TX timeout: %d/%d usec\n",
792 le32_to_cpu(cmd->rx_data_timeout),
793 le32_to_cpu(cmd->tx_data_timeout));
794 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
795 pos += scnprintf(buf + pos, bufsz - pos,
796 "sleep_interval[%d]: %d\n", i,
797 le32_to_cpu(cmd->sleep_interval[i]));
798
799 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
800}
801
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700802DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700803DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700804DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700805DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800806DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700807DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700808DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700809DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700810DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700811DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Johannes Berge312c242009-08-07 15:41:51 -0700812DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
813DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700814
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700815static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
816 char __user *user_buf,
817 size_t count, loff_t *ppos)
818{
819 struct iwl_priv *priv = file->private_data;
820 int pos = 0, ofs = 0;
821 int cnt = 0, entry;
822
823 char *buf;
824 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
825 (hw_params(priv).max_txq_num * 32 * 8) + 400;
826 const u8 *ptr;
827 ssize_t ret;
828
829 buf = kzalloc(bufsz, GFP_KERNEL);
830 if (!buf) {
831 IWL_ERR(priv, "Can not allocate buffer\n");
832 return -ENOMEM;
833 }
834 if (priv->tx_traffic &&
835 (iwl_get_debug_level(priv->shrd) & IWL_DL_TX)) {
836 ptr = priv->tx_traffic;
837 pos += scnprintf(buf + pos, bufsz - pos,
838 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
839 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
840 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
841 entry++, ofs += 16) {
842 pos += scnprintf(buf + pos, bufsz - pos,
843 "0x%.4x ", ofs);
844 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
845 buf + pos, bufsz - pos, 0);
846 pos += strlen(buf + pos);
847 if (bufsz - pos > 0)
848 buf[pos++] = '\n';
849 }
850 }
851 }
852
853 if (priv->rx_traffic &&
854 (iwl_get_debug_level(priv->shrd) & IWL_DL_RX)) {
855 ptr = priv->rx_traffic;
856 pos += scnprintf(buf + pos, bufsz - pos,
857 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
858 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
859 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
860 entry++, ofs += 16) {
861 pos += scnprintf(buf + pos, bufsz - pos,
862 "0x%.4x ", ofs);
863 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
864 buf + pos, bufsz - pos, 0);
865 pos += strlen(buf + pos);
866 if (bufsz - pos > 0)
867 buf[pos++] = '\n';
868 }
869 }
870 }
871
872 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
873 kfree(buf);
874 return ret;
875}
876
877static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
878 const char __user *user_buf,
879 size_t count, loff_t *ppos)
880{
881 struct iwl_priv *priv = file->private_data;
882 char buf[8];
883 int buf_size;
884 int traffic_log;
885
886 memset(buf, 0, sizeof(buf));
887 buf_size = min(count, sizeof(buf) - 1);
888 if (copy_from_user(buf, user_buf, buf_size))
889 return -EFAULT;
890 if (sscanf(buf, "%d", &traffic_log) != 1)
891 return -EFAULT;
892 if (traffic_log == 0)
893 iwl_reset_traffic_log(priv);
894
895 return count;
896}
897
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700898static const char *fmt_value = " %-30s %10u\n";
899static const char *fmt_hex = " %-30s 0x%02X\n";
900static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
901static const char *fmt_header =
902 "%-32s current cumulative delta max\n";
903
904static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
905{
906 int p = 0;
907 u32 flag;
908
909 flag = le32_to_cpu(priv->statistics.flag);
910
911 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
912 if (flag & UCODE_STATISTICS_CLEAR_MSK)
913 p += scnprintf(buf + p, bufsz - p,
914 "\tStatistics have been cleared\n");
915 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
916 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
917 ? "2.4 GHz" : "5.2 GHz");
918 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
919 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
920 ? "enabled" : "disabled");
921
922 return p;
923}
924
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700925static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
926 char __user *user_buf,
927 size_t count, loff_t *ppos)
928{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700929 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700930 int pos = 0;
931 char *buf;
932 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
933 sizeof(struct statistics_rx_non_phy) * 40 +
934 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
935 ssize_t ret;
936 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
937 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
938 struct statistics_rx_non_phy *general, *accum_general;
939 struct statistics_rx_non_phy *delta_general, *max_general;
940 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
941
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700942 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700943 return -EAGAIN;
944
945 buf = kzalloc(bufsz, GFP_KERNEL);
946 if (!buf) {
947 IWL_ERR(priv, "Can not allocate Buffer\n");
948 return -ENOMEM;
949 }
950
951 /*
952 * the statistic information display here is based on
953 * the last statistics notification from uCode
954 * might not reflect the current uCode activity
955 */
956 ofdm = &priv->statistics.rx_ofdm;
957 cck = &priv->statistics.rx_cck;
958 general = &priv->statistics.rx_non_phy;
959 ht = &priv->statistics.rx_ofdm_ht;
960 accum_ofdm = &priv->accum_stats.rx_ofdm;
961 accum_cck = &priv->accum_stats.rx_cck;
962 accum_general = &priv->accum_stats.rx_non_phy;
963 accum_ht = &priv->accum_stats.rx_ofdm_ht;
964 delta_ofdm = &priv->delta_stats.rx_ofdm;
965 delta_cck = &priv->delta_stats.rx_cck;
966 delta_general = &priv->delta_stats.rx_non_phy;
967 delta_ht = &priv->delta_stats.rx_ofdm_ht;
968 max_ofdm = &priv->max_delta_stats.rx_ofdm;
969 max_cck = &priv->max_delta_stats.rx_cck;
970 max_general = &priv->max_delta_stats.rx_non_phy;
971 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
972
973 pos += iwl_statistics_flag(priv, buf, bufsz);
974 pos += scnprintf(buf + pos, bufsz - pos,
975 fmt_header, "Statistics_Rx - OFDM:");
976 pos += scnprintf(buf + pos, bufsz - pos,
977 fmt_table, "ina_cnt:",
978 le32_to_cpu(ofdm->ina_cnt),
979 accum_ofdm->ina_cnt,
980 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
981 pos += scnprintf(buf + pos, bufsz - pos,
982 fmt_table, "fina_cnt:",
983 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
984 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
985 pos += scnprintf(buf + pos, bufsz - pos,
986 fmt_table, "plcp_err:",
987 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
988 delta_ofdm->plcp_err, max_ofdm->plcp_err);
989 pos += scnprintf(buf + pos, bufsz - pos,
990 fmt_table, "crc32_err:",
991 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
992 delta_ofdm->crc32_err, max_ofdm->crc32_err);
993 pos += scnprintf(buf + pos, bufsz - pos,
994 fmt_table, "overrun_err:",
995 le32_to_cpu(ofdm->overrun_err),
996 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
997 max_ofdm->overrun_err);
998 pos += scnprintf(buf + pos, bufsz - pos,
999 fmt_table, "early_overrun_err:",
1000 le32_to_cpu(ofdm->early_overrun_err),
1001 accum_ofdm->early_overrun_err,
1002 delta_ofdm->early_overrun_err,
1003 max_ofdm->early_overrun_err);
1004 pos += scnprintf(buf + pos, bufsz - pos,
1005 fmt_table, "crc32_good:",
1006 le32_to_cpu(ofdm->crc32_good),
1007 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1008 max_ofdm->crc32_good);
1009 pos += scnprintf(buf + pos, bufsz - pos,
1010 fmt_table, "false_alarm_cnt:",
1011 le32_to_cpu(ofdm->false_alarm_cnt),
1012 accum_ofdm->false_alarm_cnt,
1013 delta_ofdm->false_alarm_cnt,
1014 max_ofdm->false_alarm_cnt);
1015 pos += scnprintf(buf + pos, bufsz - pos,
1016 fmt_table, "fina_sync_err_cnt:",
1017 le32_to_cpu(ofdm->fina_sync_err_cnt),
1018 accum_ofdm->fina_sync_err_cnt,
1019 delta_ofdm->fina_sync_err_cnt,
1020 max_ofdm->fina_sync_err_cnt);
1021 pos += scnprintf(buf + pos, bufsz - pos,
1022 fmt_table, "sfd_timeout:",
1023 le32_to_cpu(ofdm->sfd_timeout),
1024 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1025 max_ofdm->sfd_timeout);
1026 pos += scnprintf(buf + pos, bufsz - pos,
1027 fmt_table, "fina_timeout:",
1028 le32_to_cpu(ofdm->fina_timeout),
1029 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1030 max_ofdm->fina_timeout);
1031 pos += scnprintf(buf + pos, bufsz - pos,
1032 fmt_table, "unresponded_rts:",
1033 le32_to_cpu(ofdm->unresponded_rts),
1034 accum_ofdm->unresponded_rts,
1035 delta_ofdm->unresponded_rts,
1036 max_ofdm->unresponded_rts);
1037 pos += scnprintf(buf + pos, bufsz - pos,
1038 fmt_table, "rxe_frame_lmt_ovrun:",
1039 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1040 accum_ofdm->rxe_frame_limit_overrun,
1041 delta_ofdm->rxe_frame_limit_overrun,
1042 max_ofdm->rxe_frame_limit_overrun);
1043 pos += scnprintf(buf + pos, bufsz - pos,
1044 fmt_table, "sent_ack_cnt:",
1045 le32_to_cpu(ofdm->sent_ack_cnt),
1046 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1047 max_ofdm->sent_ack_cnt);
1048 pos += scnprintf(buf + pos, bufsz - pos,
1049 fmt_table, "sent_cts_cnt:",
1050 le32_to_cpu(ofdm->sent_cts_cnt),
1051 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1052 max_ofdm->sent_cts_cnt);
1053 pos += scnprintf(buf + pos, bufsz - pos,
1054 fmt_table, "sent_ba_rsp_cnt:",
1055 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1056 accum_ofdm->sent_ba_rsp_cnt,
1057 delta_ofdm->sent_ba_rsp_cnt,
1058 max_ofdm->sent_ba_rsp_cnt);
1059 pos += scnprintf(buf + pos, bufsz - pos,
1060 fmt_table, "dsp_self_kill:",
1061 le32_to_cpu(ofdm->dsp_self_kill),
1062 accum_ofdm->dsp_self_kill,
1063 delta_ofdm->dsp_self_kill,
1064 max_ofdm->dsp_self_kill);
1065 pos += scnprintf(buf + pos, bufsz - pos,
1066 fmt_table, "mh_format_err:",
1067 le32_to_cpu(ofdm->mh_format_err),
1068 accum_ofdm->mh_format_err,
1069 delta_ofdm->mh_format_err,
1070 max_ofdm->mh_format_err);
1071 pos += scnprintf(buf + pos, bufsz - pos,
1072 fmt_table, "re_acq_main_rssi_sum:",
1073 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1074 accum_ofdm->re_acq_main_rssi_sum,
1075 delta_ofdm->re_acq_main_rssi_sum,
1076 max_ofdm->re_acq_main_rssi_sum);
1077
1078 pos += scnprintf(buf + pos, bufsz - pos,
1079 fmt_header, "Statistics_Rx - CCK:");
1080 pos += scnprintf(buf + pos, bufsz - pos,
1081 fmt_table, "ina_cnt:",
1082 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1083 delta_cck->ina_cnt, max_cck->ina_cnt);
1084 pos += scnprintf(buf + pos, bufsz - pos,
1085 fmt_table, "fina_cnt:",
1086 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1087 delta_cck->fina_cnt, max_cck->fina_cnt);
1088 pos += scnprintf(buf + pos, bufsz - pos,
1089 fmt_table, "plcp_err:",
1090 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1091 delta_cck->plcp_err, max_cck->plcp_err);
1092 pos += scnprintf(buf + pos, bufsz - pos,
1093 fmt_table, "crc32_err:",
1094 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1095 delta_cck->crc32_err, max_cck->crc32_err);
1096 pos += scnprintf(buf + pos, bufsz - pos,
1097 fmt_table, "overrun_err:",
1098 le32_to_cpu(cck->overrun_err),
1099 accum_cck->overrun_err, delta_cck->overrun_err,
1100 max_cck->overrun_err);
1101 pos += scnprintf(buf + pos, bufsz - pos,
1102 fmt_table, "early_overrun_err:",
1103 le32_to_cpu(cck->early_overrun_err),
1104 accum_cck->early_overrun_err,
1105 delta_cck->early_overrun_err,
1106 max_cck->early_overrun_err);
1107 pos += scnprintf(buf + pos, bufsz - pos,
1108 fmt_table, "crc32_good:",
1109 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1110 delta_cck->crc32_good, max_cck->crc32_good);
1111 pos += scnprintf(buf + pos, bufsz - pos,
1112 fmt_table, "false_alarm_cnt:",
1113 le32_to_cpu(cck->false_alarm_cnt),
1114 accum_cck->false_alarm_cnt,
1115 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1116 pos += scnprintf(buf + pos, bufsz - pos,
1117 fmt_table, "fina_sync_err_cnt:",
1118 le32_to_cpu(cck->fina_sync_err_cnt),
1119 accum_cck->fina_sync_err_cnt,
1120 delta_cck->fina_sync_err_cnt,
1121 max_cck->fina_sync_err_cnt);
1122 pos += scnprintf(buf + pos, bufsz - pos,
1123 fmt_table, "sfd_timeout:",
1124 le32_to_cpu(cck->sfd_timeout),
1125 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1126 max_cck->sfd_timeout);
1127 pos += scnprintf(buf + pos, bufsz - pos,
1128 fmt_table, "fina_timeout:",
1129 le32_to_cpu(cck->fina_timeout),
1130 accum_cck->fina_timeout, delta_cck->fina_timeout,
1131 max_cck->fina_timeout);
1132 pos += scnprintf(buf + pos, bufsz - pos,
1133 fmt_table, "unresponded_rts:",
1134 le32_to_cpu(cck->unresponded_rts),
1135 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1136 max_cck->unresponded_rts);
1137 pos += scnprintf(buf + pos, bufsz - pos,
1138 fmt_table, "rxe_frame_lmt_ovrun:",
1139 le32_to_cpu(cck->rxe_frame_limit_overrun),
1140 accum_cck->rxe_frame_limit_overrun,
1141 delta_cck->rxe_frame_limit_overrun,
1142 max_cck->rxe_frame_limit_overrun);
1143 pos += scnprintf(buf + pos, bufsz - pos,
1144 fmt_table, "sent_ack_cnt:",
1145 le32_to_cpu(cck->sent_ack_cnt),
1146 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1147 max_cck->sent_ack_cnt);
1148 pos += scnprintf(buf + pos, bufsz - pos,
1149 fmt_table, "sent_cts_cnt:",
1150 le32_to_cpu(cck->sent_cts_cnt),
1151 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1152 max_cck->sent_cts_cnt);
1153 pos += scnprintf(buf + pos, bufsz - pos,
1154 fmt_table, "sent_ba_rsp_cnt:",
1155 le32_to_cpu(cck->sent_ba_rsp_cnt),
1156 accum_cck->sent_ba_rsp_cnt,
1157 delta_cck->sent_ba_rsp_cnt,
1158 max_cck->sent_ba_rsp_cnt);
1159 pos += scnprintf(buf + pos, bufsz - pos,
1160 fmt_table, "dsp_self_kill:",
1161 le32_to_cpu(cck->dsp_self_kill),
1162 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1163 max_cck->dsp_self_kill);
1164 pos += scnprintf(buf + pos, bufsz - pos,
1165 fmt_table, "mh_format_err:",
1166 le32_to_cpu(cck->mh_format_err),
1167 accum_cck->mh_format_err, delta_cck->mh_format_err,
1168 max_cck->mh_format_err);
1169 pos += scnprintf(buf + pos, bufsz - pos,
1170 fmt_table, "re_acq_main_rssi_sum:",
1171 le32_to_cpu(cck->re_acq_main_rssi_sum),
1172 accum_cck->re_acq_main_rssi_sum,
1173 delta_cck->re_acq_main_rssi_sum,
1174 max_cck->re_acq_main_rssi_sum);
1175
1176 pos += scnprintf(buf + pos, bufsz - pos,
1177 fmt_header, "Statistics_Rx - GENERAL:");
1178 pos += scnprintf(buf + pos, bufsz - pos,
1179 fmt_table, "bogus_cts:",
1180 le32_to_cpu(general->bogus_cts),
1181 accum_general->bogus_cts, delta_general->bogus_cts,
1182 max_general->bogus_cts);
1183 pos += scnprintf(buf + pos, bufsz - pos,
1184 fmt_table, "bogus_ack:",
1185 le32_to_cpu(general->bogus_ack),
1186 accum_general->bogus_ack, delta_general->bogus_ack,
1187 max_general->bogus_ack);
1188 pos += scnprintf(buf + pos, bufsz - pos,
1189 fmt_table, "non_bssid_frames:",
1190 le32_to_cpu(general->non_bssid_frames),
1191 accum_general->non_bssid_frames,
1192 delta_general->non_bssid_frames,
1193 max_general->non_bssid_frames);
1194 pos += scnprintf(buf + pos, bufsz - pos,
1195 fmt_table, "filtered_frames:",
1196 le32_to_cpu(general->filtered_frames),
1197 accum_general->filtered_frames,
1198 delta_general->filtered_frames,
1199 max_general->filtered_frames);
1200 pos += scnprintf(buf + pos, bufsz - pos,
1201 fmt_table, "non_channel_beacons:",
1202 le32_to_cpu(general->non_channel_beacons),
1203 accum_general->non_channel_beacons,
1204 delta_general->non_channel_beacons,
1205 max_general->non_channel_beacons);
1206 pos += scnprintf(buf + pos, bufsz - pos,
1207 fmt_table, "channel_beacons:",
1208 le32_to_cpu(general->channel_beacons),
1209 accum_general->channel_beacons,
1210 delta_general->channel_beacons,
1211 max_general->channel_beacons);
1212 pos += scnprintf(buf + pos, bufsz - pos,
1213 fmt_table, "num_missed_bcon:",
1214 le32_to_cpu(general->num_missed_bcon),
1215 accum_general->num_missed_bcon,
1216 delta_general->num_missed_bcon,
1217 max_general->num_missed_bcon);
1218 pos += scnprintf(buf + pos, bufsz - pos,
1219 fmt_table, "adc_rx_saturation_time:",
1220 le32_to_cpu(general->adc_rx_saturation_time),
1221 accum_general->adc_rx_saturation_time,
1222 delta_general->adc_rx_saturation_time,
1223 max_general->adc_rx_saturation_time);
1224 pos += scnprintf(buf + pos, bufsz - pos,
1225 fmt_table, "ina_detect_search_tm:",
1226 le32_to_cpu(general->ina_detection_search_time),
1227 accum_general->ina_detection_search_time,
1228 delta_general->ina_detection_search_time,
1229 max_general->ina_detection_search_time);
1230 pos += scnprintf(buf + pos, bufsz - pos,
1231 fmt_table, "beacon_silence_rssi_a:",
1232 le32_to_cpu(general->beacon_silence_rssi_a),
1233 accum_general->beacon_silence_rssi_a,
1234 delta_general->beacon_silence_rssi_a,
1235 max_general->beacon_silence_rssi_a);
1236 pos += scnprintf(buf + pos, bufsz - pos,
1237 fmt_table, "beacon_silence_rssi_b:",
1238 le32_to_cpu(general->beacon_silence_rssi_b),
1239 accum_general->beacon_silence_rssi_b,
1240 delta_general->beacon_silence_rssi_b,
1241 max_general->beacon_silence_rssi_b);
1242 pos += scnprintf(buf + pos, bufsz - pos,
1243 fmt_table, "beacon_silence_rssi_c:",
1244 le32_to_cpu(general->beacon_silence_rssi_c),
1245 accum_general->beacon_silence_rssi_c,
1246 delta_general->beacon_silence_rssi_c,
1247 max_general->beacon_silence_rssi_c);
1248 pos += scnprintf(buf + pos, bufsz - pos,
1249 fmt_table, "interference_data_flag:",
1250 le32_to_cpu(general->interference_data_flag),
1251 accum_general->interference_data_flag,
1252 delta_general->interference_data_flag,
1253 max_general->interference_data_flag);
1254 pos += scnprintf(buf + pos, bufsz - pos,
1255 fmt_table, "channel_load:",
1256 le32_to_cpu(general->channel_load),
1257 accum_general->channel_load,
1258 delta_general->channel_load,
1259 max_general->channel_load);
1260 pos += scnprintf(buf + pos, bufsz - pos,
1261 fmt_table, "dsp_false_alarms:",
1262 le32_to_cpu(general->dsp_false_alarms),
1263 accum_general->dsp_false_alarms,
1264 delta_general->dsp_false_alarms,
1265 max_general->dsp_false_alarms);
1266 pos += scnprintf(buf + pos, bufsz - pos,
1267 fmt_table, "beacon_rssi_a:",
1268 le32_to_cpu(general->beacon_rssi_a),
1269 accum_general->beacon_rssi_a,
1270 delta_general->beacon_rssi_a,
1271 max_general->beacon_rssi_a);
1272 pos += scnprintf(buf + pos, bufsz - pos,
1273 fmt_table, "beacon_rssi_b:",
1274 le32_to_cpu(general->beacon_rssi_b),
1275 accum_general->beacon_rssi_b,
1276 delta_general->beacon_rssi_b,
1277 max_general->beacon_rssi_b);
1278 pos += scnprintf(buf + pos, bufsz - pos,
1279 fmt_table, "beacon_rssi_c:",
1280 le32_to_cpu(general->beacon_rssi_c),
1281 accum_general->beacon_rssi_c,
1282 delta_general->beacon_rssi_c,
1283 max_general->beacon_rssi_c);
1284 pos += scnprintf(buf + pos, bufsz - pos,
1285 fmt_table, "beacon_energy_a:",
1286 le32_to_cpu(general->beacon_energy_a),
1287 accum_general->beacon_energy_a,
1288 delta_general->beacon_energy_a,
1289 max_general->beacon_energy_a);
1290 pos += scnprintf(buf + pos, bufsz - pos,
1291 fmt_table, "beacon_energy_b:",
1292 le32_to_cpu(general->beacon_energy_b),
1293 accum_general->beacon_energy_b,
1294 delta_general->beacon_energy_b,
1295 max_general->beacon_energy_b);
1296 pos += scnprintf(buf + pos, bufsz - pos,
1297 fmt_table, "beacon_energy_c:",
1298 le32_to_cpu(general->beacon_energy_c),
1299 accum_general->beacon_energy_c,
1300 delta_general->beacon_energy_c,
1301 max_general->beacon_energy_c);
1302
1303 pos += scnprintf(buf + pos, bufsz - pos,
1304 fmt_header, "Statistics_Rx - OFDM_HT:");
1305 pos += scnprintf(buf + pos, bufsz - pos,
1306 fmt_table, "plcp_err:",
1307 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1308 delta_ht->plcp_err, max_ht->plcp_err);
1309 pos += scnprintf(buf + pos, bufsz - pos,
1310 fmt_table, "overrun_err:",
1311 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1312 delta_ht->overrun_err, max_ht->overrun_err);
1313 pos += scnprintf(buf + pos, bufsz - pos,
1314 fmt_table, "early_overrun_err:",
1315 le32_to_cpu(ht->early_overrun_err),
1316 accum_ht->early_overrun_err,
1317 delta_ht->early_overrun_err,
1318 max_ht->early_overrun_err);
1319 pos += scnprintf(buf + pos, bufsz - pos,
1320 fmt_table, "crc32_good:",
1321 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1322 delta_ht->crc32_good, max_ht->crc32_good);
1323 pos += scnprintf(buf + pos, bufsz - pos,
1324 fmt_table, "crc32_err:",
1325 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1326 delta_ht->crc32_err, max_ht->crc32_err);
1327 pos += scnprintf(buf + pos, bufsz - pos,
1328 fmt_table, "mh_format_err:",
1329 le32_to_cpu(ht->mh_format_err),
1330 accum_ht->mh_format_err,
1331 delta_ht->mh_format_err, max_ht->mh_format_err);
1332 pos += scnprintf(buf + pos, bufsz - pos,
1333 fmt_table, "agg_crc32_good:",
1334 le32_to_cpu(ht->agg_crc32_good),
1335 accum_ht->agg_crc32_good,
1336 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1337 pos += scnprintf(buf + pos, bufsz - pos,
1338 fmt_table, "agg_mpdu_cnt:",
1339 le32_to_cpu(ht->agg_mpdu_cnt),
1340 accum_ht->agg_mpdu_cnt,
1341 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1342 pos += scnprintf(buf + pos, bufsz - pos,
1343 fmt_table, "agg_cnt:",
1344 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1345 delta_ht->agg_cnt, max_ht->agg_cnt);
1346 pos += scnprintf(buf + pos, bufsz - pos,
1347 fmt_table, "unsupport_mcs:",
1348 le32_to_cpu(ht->unsupport_mcs),
1349 accum_ht->unsupport_mcs,
1350 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1351
1352 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1353 kfree(buf);
1354 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001355}
1356
1357static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1358 char __user *user_buf,
1359 size_t count, loff_t *ppos)
1360{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001361 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001362 int pos = 0;
1363 char *buf;
1364 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1365 ssize_t ret;
1366 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1367
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001368 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001369 return -EAGAIN;
1370
1371 buf = kzalloc(bufsz, GFP_KERNEL);
1372 if (!buf) {
1373 IWL_ERR(priv, "Can not allocate Buffer\n");
1374 return -ENOMEM;
1375 }
1376
1377 /* the statistic information display here is based on
1378 * the last statistics notification from uCode
1379 * might not reflect the current uCode activity
1380 */
1381 tx = &priv->statistics.tx;
1382 accum_tx = &priv->accum_stats.tx;
1383 delta_tx = &priv->delta_stats.tx;
1384 max_tx = &priv->max_delta_stats.tx;
1385
1386 pos += iwl_statistics_flag(priv, buf, bufsz);
1387 pos += scnprintf(buf + pos, bufsz - pos,
1388 fmt_header, "Statistics_Tx:");
1389 pos += scnprintf(buf + pos, bufsz - pos,
1390 fmt_table, "preamble:",
1391 le32_to_cpu(tx->preamble_cnt),
1392 accum_tx->preamble_cnt,
1393 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1394 pos += scnprintf(buf + pos, bufsz - pos,
1395 fmt_table, "rx_detected_cnt:",
1396 le32_to_cpu(tx->rx_detected_cnt),
1397 accum_tx->rx_detected_cnt,
1398 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1399 pos += scnprintf(buf + pos, bufsz - pos,
1400 fmt_table, "bt_prio_defer_cnt:",
1401 le32_to_cpu(tx->bt_prio_defer_cnt),
1402 accum_tx->bt_prio_defer_cnt,
1403 delta_tx->bt_prio_defer_cnt,
1404 max_tx->bt_prio_defer_cnt);
1405 pos += scnprintf(buf + pos, bufsz - pos,
1406 fmt_table, "bt_prio_kill_cnt:",
1407 le32_to_cpu(tx->bt_prio_kill_cnt),
1408 accum_tx->bt_prio_kill_cnt,
1409 delta_tx->bt_prio_kill_cnt,
1410 max_tx->bt_prio_kill_cnt);
1411 pos += scnprintf(buf + pos, bufsz - pos,
1412 fmt_table, "few_bytes_cnt:",
1413 le32_to_cpu(tx->few_bytes_cnt),
1414 accum_tx->few_bytes_cnt,
1415 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1416 pos += scnprintf(buf + pos, bufsz - pos,
1417 fmt_table, "cts_timeout:",
1418 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1419 delta_tx->cts_timeout, max_tx->cts_timeout);
1420 pos += scnprintf(buf + pos, bufsz - pos,
1421 fmt_table, "ack_timeout:",
1422 le32_to_cpu(tx->ack_timeout),
1423 accum_tx->ack_timeout,
1424 delta_tx->ack_timeout, max_tx->ack_timeout);
1425 pos += scnprintf(buf + pos, bufsz - pos,
1426 fmt_table, "expected_ack_cnt:",
1427 le32_to_cpu(tx->expected_ack_cnt),
1428 accum_tx->expected_ack_cnt,
1429 delta_tx->expected_ack_cnt,
1430 max_tx->expected_ack_cnt);
1431 pos += scnprintf(buf + pos, bufsz - pos,
1432 fmt_table, "actual_ack_cnt:",
1433 le32_to_cpu(tx->actual_ack_cnt),
1434 accum_tx->actual_ack_cnt,
1435 delta_tx->actual_ack_cnt,
1436 max_tx->actual_ack_cnt);
1437 pos += scnprintf(buf + pos, bufsz - pos,
1438 fmt_table, "dump_msdu_cnt:",
1439 le32_to_cpu(tx->dump_msdu_cnt),
1440 accum_tx->dump_msdu_cnt,
1441 delta_tx->dump_msdu_cnt,
1442 max_tx->dump_msdu_cnt);
1443 pos += scnprintf(buf + pos, bufsz - pos,
1444 fmt_table, "abort_nxt_frame_mismatch:",
1445 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1446 accum_tx->burst_abort_next_frame_mismatch_cnt,
1447 delta_tx->burst_abort_next_frame_mismatch_cnt,
1448 max_tx->burst_abort_next_frame_mismatch_cnt);
1449 pos += scnprintf(buf + pos, bufsz - pos,
1450 fmt_table, "abort_missing_nxt_frame:",
1451 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1452 accum_tx->burst_abort_missing_next_frame_cnt,
1453 delta_tx->burst_abort_missing_next_frame_cnt,
1454 max_tx->burst_abort_missing_next_frame_cnt);
1455 pos += scnprintf(buf + pos, bufsz - pos,
1456 fmt_table, "cts_timeout_collision:",
1457 le32_to_cpu(tx->cts_timeout_collision),
1458 accum_tx->cts_timeout_collision,
1459 delta_tx->cts_timeout_collision,
1460 max_tx->cts_timeout_collision);
1461 pos += scnprintf(buf + pos, bufsz - pos,
1462 fmt_table, "ack_ba_timeout_collision:",
1463 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1464 accum_tx->ack_or_ba_timeout_collision,
1465 delta_tx->ack_or_ba_timeout_collision,
1466 max_tx->ack_or_ba_timeout_collision);
1467 pos += scnprintf(buf + pos, bufsz - pos,
1468 fmt_table, "agg ba_timeout:",
1469 le32_to_cpu(tx->agg.ba_timeout),
1470 accum_tx->agg.ba_timeout,
1471 delta_tx->agg.ba_timeout,
1472 max_tx->agg.ba_timeout);
1473 pos += scnprintf(buf + pos, bufsz - pos,
1474 fmt_table, "agg ba_resched_frames:",
1475 le32_to_cpu(tx->agg.ba_reschedule_frames),
1476 accum_tx->agg.ba_reschedule_frames,
1477 delta_tx->agg.ba_reschedule_frames,
1478 max_tx->agg.ba_reschedule_frames);
1479 pos += scnprintf(buf + pos, bufsz - pos,
1480 fmt_table, "agg scd_query_agg_frame:",
1481 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1482 accum_tx->agg.scd_query_agg_frame_cnt,
1483 delta_tx->agg.scd_query_agg_frame_cnt,
1484 max_tx->agg.scd_query_agg_frame_cnt);
1485 pos += scnprintf(buf + pos, bufsz - pos,
1486 fmt_table, "agg scd_query_no_agg:",
1487 le32_to_cpu(tx->agg.scd_query_no_agg),
1488 accum_tx->agg.scd_query_no_agg,
1489 delta_tx->agg.scd_query_no_agg,
1490 max_tx->agg.scd_query_no_agg);
1491 pos += scnprintf(buf + pos, bufsz - pos,
1492 fmt_table, "agg scd_query_agg:",
1493 le32_to_cpu(tx->agg.scd_query_agg),
1494 accum_tx->agg.scd_query_agg,
1495 delta_tx->agg.scd_query_agg,
1496 max_tx->agg.scd_query_agg);
1497 pos += scnprintf(buf + pos, bufsz - pos,
1498 fmt_table, "agg scd_query_mismatch:",
1499 le32_to_cpu(tx->agg.scd_query_mismatch),
1500 accum_tx->agg.scd_query_mismatch,
1501 delta_tx->agg.scd_query_mismatch,
1502 max_tx->agg.scd_query_mismatch);
1503 pos += scnprintf(buf + pos, bufsz - pos,
1504 fmt_table, "agg frame_not_ready:",
1505 le32_to_cpu(tx->agg.frame_not_ready),
1506 accum_tx->agg.frame_not_ready,
1507 delta_tx->agg.frame_not_ready,
1508 max_tx->agg.frame_not_ready);
1509 pos += scnprintf(buf + pos, bufsz - pos,
1510 fmt_table, "agg underrun:",
1511 le32_to_cpu(tx->agg.underrun),
1512 accum_tx->agg.underrun,
1513 delta_tx->agg.underrun, max_tx->agg.underrun);
1514 pos += scnprintf(buf + pos, bufsz - pos,
1515 fmt_table, "agg bt_prio_kill:",
1516 le32_to_cpu(tx->agg.bt_prio_kill),
1517 accum_tx->agg.bt_prio_kill,
1518 delta_tx->agg.bt_prio_kill,
1519 max_tx->agg.bt_prio_kill);
1520 pos += scnprintf(buf + pos, bufsz - pos,
1521 fmt_table, "agg rx_ba_rsp_cnt:",
1522 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1523 accum_tx->agg.rx_ba_rsp_cnt,
1524 delta_tx->agg.rx_ba_rsp_cnt,
1525 max_tx->agg.rx_ba_rsp_cnt);
1526
1527 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1528 pos += scnprintf(buf + pos, bufsz - pos,
1529 "tx power: (1/2 dB step)\n");
1530 if ((priv->cfg->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
1531 pos += scnprintf(buf + pos, bufsz - pos,
1532 fmt_hex, "antenna A:",
1533 tx->tx_power.ant_a);
1534 if ((priv->cfg->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
1535 pos += scnprintf(buf + pos, bufsz - pos,
1536 fmt_hex, "antenna B:",
1537 tx->tx_power.ant_b);
1538 if ((priv->cfg->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
1539 pos += scnprintf(buf + pos, bufsz - pos,
1540 fmt_hex, "antenna C:",
1541 tx->tx_power.ant_c);
1542 }
1543 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1544 kfree(buf);
1545 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001546}
1547
1548static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1549 char __user *user_buf,
1550 size_t count, loff_t *ppos)
1551{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001552 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001553 int pos = 0;
1554 char *buf;
1555 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1556 ssize_t ret;
1557 struct statistics_general_common *general, *accum_general;
1558 struct statistics_general_common *delta_general, *max_general;
1559 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1560 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1561
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001562 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001563 return -EAGAIN;
1564
1565 buf = kzalloc(bufsz, GFP_KERNEL);
1566 if (!buf) {
1567 IWL_ERR(priv, "Can not allocate Buffer\n");
1568 return -ENOMEM;
1569 }
1570
1571 /* the statistic information display here is based on
1572 * the last statistics notification from uCode
1573 * might not reflect the current uCode activity
1574 */
1575 general = &priv->statistics.common;
1576 dbg = &priv->statistics.common.dbg;
1577 div = &priv->statistics.common.div;
1578 accum_general = &priv->accum_stats.common;
1579 accum_dbg = &priv->accum_stats.common.dbg;
1580 accum_div = &priv->accum_stats.common.div;
1581 delta_general = &priv->delta_stats.common;
1582 max_general = &priv->max_delta_stats.common;
1583 delta_dbg = &priv->delta_stats.common.dbg;
1584 max_dbg = &priv->max_delta_stats.common.dbg;
1585 delta_div = &priv->delta_stats.common.div;
1586 max_div = &priv->max_delta_stats.common.div;
1587
1588 pos += iwl_statistics_flag(priv, buf, bufsz);
1589 pos += scnprintf(buf + pos, bufsz - pos,
1590 fmt_header, "Statistics_General:");
1591 pos += scnprintf(buf + pos, bufsz - pos,
1592 fmt_value, "temperature:",
1593 le32_to_cpu(general->temperature));
1594 pos += scnprintf(buf + pos, bufsz - pos,
1595 fmt_value, "temperature_m:",
1596 le32_to_cpu(general->temperature_m));
1597 pos += scnprintf(buf + pos, bufsz - pos,
1598 fmt_value, "ttl_timestamp:",
1599 le32_to_cpu(general->ttl_timestamp));
1600 pos += scnprintf(buf + pos, bufsz - pos,
1601 fmt_table, "burst_check:",
1602 le32_to_cpu(dbg->burst_check),
1603 accum_dbg->burst_check,
1604 delta_dbg->burst_check, max_dbg->burst_check);
1605 pos += scnprintf(buf + pos, bufsz - pos,
1606 fmt_table, "burst_count:",
1607 le32_to_cpu(dbg->burst_count),
1608 accum_dbg->burst_count,
1609 delta_dbg->burst_count, max_dbg->burst_count);
1610 pos += scnprintf(buf + pos, bufsz - pos,
1611 fmt_table, "wait_for_silence_timeout_count:",
1612 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1613 accum_dbg->wait_for_silence_timeout_cnt,
1614 delta_dbg->wait_for_silence_timeout_cnt,
1615 max_dbg->wait_for_silence_timeout_cnt);
1616 pos += scnprintf(buf + pos, bufsz - pos,
1617 fmt_table, "sleep_time:",
1618 le32_to_cpu(general->sleep_time),
1619 accum_general->sleep_time,
1620 delta_general->sleep_time, max_general->sleep_time);
1621 pos += scnprintf(buf + pos, bufsz - pos,
1622 fmt_table, "slots_out:",
1623 le32_to_cpu(general->slots_out),
1624 accum_general->slots_out,
1625 delta_general->slots_out, max_general->slots_out);
1626 pos += scnprintf(buf + pos, bufsz - pos,
1627 fmt_table, "slots_idle:",
1628 le32_to_cpu(general->slots_idle),
1629 accum_general->slots_idle,
1630 delta_general->slots_idle, max_general->slots_idle);
1631 pos += scnprintf(buf + pos, bufsz - pos,
1632 fmt_table, "tx_on_a:",
1633 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1634 delta_div->tx_on_a, max_div->tx_on_a);
1635 pos += scnprintf(buf + pos, bufsz - pos,
1636 fmt_table, "tx_on_b:",
1637 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1638 delta_div->tx_on_b, max_div->tx_on_b);
1639 pos += scnprintf(buf + pos, bufsz - pos,
1640 fmt_table, "exec_time:",
1641 le32_to_cpu(div->exec_time), accum_div->exec_time,
1642 delta_div->exec_time, max_div->exec_time);
1643 pos += scnprintf(buf + pos, bufsz - pos,
1644 fmt_table, "probe_time:",
1645 le32_to_cpu(div->probe_time), accum_div->probe_time,
1646 delta_div->probe_time, max_div->probe_time);
1647 pos += scnprintf(buf + pos, bufsz - pos,
1648 fmt_table, "rx_enable_counter:",
1649 le32_to_cpu(general->rx_enable_counter),
1650 accum_general->rx_enable_counter,
1651 delta_general->rx_enable_counter,
1652 max_general->rx_enable_counter);
1653 pos += scnprintf(buf + pos, bufsz - pos,
1654 fmt_table, "num_of_sos_states:",
1655 le32_to_cpu(general->num_of_sos_states),
1656 accum_general->num_of_sos_states,
1657 delta_general->num_of_sos_states,
1658 max_general->num_of_sos_states);
1659 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1660 kfree(buf);
1661 return ret;
1662}
1663
1664static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1665 char __user *user_buf,
1666 size_t count, loff_t *ppos)
1667{
1668 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1669 int pos = 0;
1670 char *buf;
1671 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1672 ssize_t ret;
1673 struct statistics_bt_activity *bt, *accum_bt;
1674
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001675 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001676 return -EAGAIN;
1677
1678 if (!priv->bt_enable_flag)
1679 return -EINVAL;
1680
1681 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001682 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001683 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001684 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001685
1686 if (ret) {
1687 IWL_ERR(priv,
1688 "Error sending statistics request: %zd\n", ret);
1689 return -EAGAIN;
1690 }
1691 buf = kzalloc(bufsz, GFP_KERNEL);
1692 if (!buf) {
1693 IWL_ERR(priv, "Can not allocate Buffer\n");
1694 return -ENOMEM;
1695 }
1696
1697 /*
1698 * the statistic information display here is based on
1699 * the last statistics notification from uCode
1700 * might not reflect the current uCode activity
1701 */
1702 bt = &priv->statistics.bt_activity;
1703 accum_bt = &priv->accum_stats.bt_activity;
1704
1705 pos += iwl_statistics_flag(priv, buf, bufsz);
1706 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1707 pos += scnprintf(buf + pos, bufsz - pos,
1708 "\t\t\tcurrent\t\t\taccumulative\n");
1709 pos += scnprintf(buf + pos, bufsz - pos,
1710 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1711 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1712 accum_bt->hi_priority_tx_req_cnt);
1713 pos += scnprintf(buf + pos, bufsz - pos,
1714 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1715 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1716 accum_bt->hi_priority_tx_denied_cnt);
1717 pos += scnprintf(buf + pos, bufsz - pos,
1718 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1719 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1720 accum_bt->lo_priority_tx_req_cnt);
1721 pos += scnprintf(buf + pos, bufsz - pos,
1722 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1723 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1724 accum_bt->lo_priority_tx_denied_cnt);
1725 pos += scnprintf(buf + pos, bufsz - pos,
1726 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1727 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1728 accum_bt->hi_priority_rx_req_cnt);
1729 pos += scnprintf(buf + pos, bufsz - pos,
1730 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1731 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1732 accum_bt->hi_priority_rx_denied_cnt);
1733 pos += scnprintf(buf + pos, bufsz - pos,
1734 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1735 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1736 accum_bt->lo_priority_rx_req_cnt);
1737 pos += scnprintf(buf + pos, bufsz - pos,
1738 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1739 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1740 accum_bt->lo_priority_rx_denied_cnt);
1741
1742 pos += scnprintf(buf + pos, bufsz - pos,
1743 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1744 le32_to_cpu(priv->statistics.num_bt_kills),
1745 priv->statistics.accum_num_bt_kills);
1746
1747 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1748 kfree(buf);
1749 return ret;
1750}
1751
1752static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1753 char __user *user_buf,
1754 size_t count, loff_t *ppos)
1755{
1756 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1757 int pos = 0;
1758 char *buf;
1759 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1760 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1761 ssize_t ret;
1762
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001763 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001764 return -EAGAIN;
1765
1766 buf = kzalloc(bufsz, GFP_KERNEL);
1767 if (!buf) {
1768 IWL_ERR(priv, "Can not allocate Buffer\n");
1769 return -ENOMEM;
1770 }
1771
1772 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1773 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1774 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001775 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001776 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1777 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001778 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001779 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1780 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001781 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001782 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1783 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001784 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001785 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1786 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001787 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001788 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1789 iwl_get_tx_fail_reason(
1790 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001791 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001792 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1793 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001794 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001795 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1796 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001797 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001798 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1799 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001800 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001801 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1802 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001803 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001804 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1805 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001806 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001807 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1808 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001809 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001810 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1811 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001812 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001813 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1814 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001815 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001816 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1817 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001818 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001819 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1820 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001821 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001822 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1823 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001824 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001825 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1826 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001827 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001828 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1829 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001830 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001831 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1832 iwl_get_tx_fail_reason(
1833 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001834 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001835 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1836 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001837 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001838 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1839 iwl_get_tx_fail_reason(
1840 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001841 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001842 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001843 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001844
1845 pos += scnprintf(buf + pos, bufsz - pos,
1846 "\nStatistics_Agg_TX_Error:\n");
1847
1848 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1849 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001851 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1852 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001853 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001854 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1855 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001856 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001857 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1858 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001859 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001860 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1861 iwl_get_agg_tx_fail_reason(
1862 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001863 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001864 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1865 iwl_get_agg_tx_fail_reason(
1866 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001867 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001868 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1869 iwl_get_agg_tx_fail_reason(
1870 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001871 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001872 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1873 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001874 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001875 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1876 iwl_get_agg_tx_fail_reason(
1877 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001878 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001879 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1880 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001881 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001882 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1883 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001884 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001885 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1886 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001887 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001888 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001889 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001890
1891 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1892 kfree(buf);
1893 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001894}
1895
Wey-Yi Guy52259352009-08-07 15:41:43 -07001896static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1897 char __user *user_buf,
1898 size_t count, loff_t *ppos) {
1899
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001900 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001901 int pos = 0;
1902 int cnt = 0;
1903 char *buf;
1904 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1905 ssize_t ret;
1906 struct iwl_sensitivity_data *data;
1907
1908 data = &priv->sensitivity_data;
1909 buf = kzalloc(bufsz, GFP_KERNEL);
1910 if (!buf) {
1911 IWL_ERR(priv, "Can not allocate Buffer\n");
1912 return -ENOMEM;
1913 }
1914
1915 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1916 data->auto_corr_ofdm);
1917 pos += scnprintf(buf + pos, bufsz - pos,
1918 "auto_corr_ofdm_mrc:\t\t %u\n",
1919 data->auto_corr_ofdm_mrc);
1920 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1921 data->auto_corr_ofdm_x1);
1922 pos += scnprintf(buf + pos, bufsz - pos,
1923 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1924 data->auto_corr_ofdm_mrc_x1);
1925 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1926 data->auto_corr_cck);
1927 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1928 data->auto_corr_cck_mrc);
1929 pos += scnprintf(buf + pos, bufsz - pos,
1930 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1931 data->last_bad_plcp_cnt_ofdm);
1932 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1933 data->last_fa_cnt_ofdm);
1934 pos += scnprintf(buf + pos, bufsz - pos,
1935 "last_bad_plcp_cnt_cck:\t\t %u\n",
1936 data->last_bad_plcp_cnt_cck);
1937 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1938 data->last_fa_cnt_cck);
1939 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1940 data->nrg_curr_state);
1941 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1942 data->nrg_prev_state);
1943 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1944 for (cnt = 0; cnt < 10; cnt++) {
1945 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1946 data->nrg_value[cnt]);
1947 }
1948 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1949 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1950 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1951 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1952 data->nrg_silence_rssi[cnt]);
1953 }
1954 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1955 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1956 data->nrg_silence_ref);
1957 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1958 data->nrg_energy_idx);
1959 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1960 data->nrg_silence_idx);
1961 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1962 data->nrg_th_cck);
1963 pos += scnprintf(buf + pos, bufsz - pos,
1964 "nrg_auto_corr_silence_diff:\t %u\n",
1965 data->nrg_auto_corr_silence_diff);
1966 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1967 data->num_in_cck_no_fa);
1968 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1969 data->nrg_th_ofdm);
1970
1971 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1972 kfree(buf);
1973 return ret;
1974}
1975
1976
1977static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1978 char __user *user_buf,
1979 size_t count, loff_t *ppos) {
1980
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001981 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001982 int pos = 0;
1983 int cnt = 0;
1984 char *buf;
1985 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1986 ssize_t ret;
1987 struct iwl_chain_noise_data *data;
1988
1989 data = &priv->chain_noise_data;
1990 buf = kzalloc(bufsz, GFP_KERNEL);
1991 if (!buf) {
1992 IWL_ERR(priv, "Can not allocate Buffer\n");
1993 return -ENOMEM;
1994 }
1995
1996 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1997 data->active_chains);
1998 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1999 data->chain_noise_a);
2000 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2001 data->chain_noise_b);
2002 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2003 data->chain_noise_c);
2004 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2005 data->chain_signal_a);
2006 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2007 data->chain_signal_b);
2008 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2009 data->chain_signal_c);
2010 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2011 data->beacon_count);
2012
2013 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2014 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2015 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2016 data->disconn_array[cnt]);
2017 }
2018 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2019 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2020 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2021 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2022 data->delta_gain_code[cnt]);
2023 }
2024 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2025 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2026 data->radio_write);
2027 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2028 data->state);
2029
2030 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2031 kfree(buf);
2032 return ret;
2033}
2034
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002035static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2036 char __user *user_buf,
2037 size_t count, loff_t *ppos)
2038{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002039 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002040 char buf[60];
2041 int pos = 0;
2042 const size_t bufsz = sizeof(buf);
2043 u32 pwrsave_status;
2044
Emmanuel Grumbach83ed9012011-08-25 23:11:14 -07002045 pwrsave_status = iwl_read32(bus(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002046 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2047
2048 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2049 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2050 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2051 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2052 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2053 "error");
2054
2055 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2056}
2057
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002058static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002059 const char __user *user_buf,
2060 size_t count, loff_t *ppos)
2061{
2062 struct iwl_priv *priv = file->private_data;
2063 char buf[8];
2064 int buf_size;
2065 int clear;
2066
2067 memset(buf, 0, sizeof(buf));
2068 buf_size = min(count, sizeof(buf) - 1);
2069 if (copy_from_user(buf, user_buf, buf_size))
2070 return -EFAULT;
2071 if (sscanf(buf, "%d", &clear) != 1)
2072 return -EFAULT;
2073
2074 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002075 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002076 iwl_send_statistics_request(priv, CMD_SYNC, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002077 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002078
2079 return count;
2080}
2081
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002082static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2083 char __user *user_buf,
2084 size_t count, loff_t *ppos) {
2085
Joe Perches57674302010-07-12 13:50:06 -07002086 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002087 int pos = 0;
2088 char buf[128];
2089 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002090
2091 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2092 priv->event_log.ucode_trace ? "On" : "Off");
2093 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2094 priv->event_log.non_wraps_count);
2095 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2096 priv->event_log.wraps_once_count);
2097 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2098 priv->event_log.wraps_more_count);
2099
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002100 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002101}
2102
2103static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2104 const char __user *user_buf,
2105 size_t count, loff_t *ppos)
2106{
2107 struct iwl_priv *priv = file->private_data;
2108 char buf[8];
2109 int buf_size;
2110 int trace;
2111
2112 memset(buf, 0, sizeof(buf));
2113 buf_size = min(count, sizeof(buf) - 1);
2114 if (copy_from_user(buf, user_buf, buf_size))
2115 return -EFAULT;
2116 if (sscanf(buf, "%d", &trace) != 1)
2117 return -EFAULT;
2118
2119 if (trace) {
2120 priv->event_log.ucode_trace = true;
2121 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
2122 mod_timer(&priv->ucode_trace,
2123 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
2124 } else {
2125 priv->event_log.ucode_trace = false;
2126 del_timer_sync(&priv->ucode_trace);
2127 }
2128
2129 return count;
2130}
2131
Johannes Berg60987202010-02-18 00:36:07 -08002132static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2133 char __user *user_buf,
2134 size_t count, loff_t *ppos) {
2135
Joe Perches57674302010-07-12 13:50:06 -07002136 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002137 int len = 0;
2138 char buf[20];
2139
Johannes Berg246ed352010-08-23 10:46:32 +02002140 len = sprintf(buf, "0x%04X\n",
2141 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002142 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2143}
2144
2145static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2146 char __user *user_buf,
2147 size_t count, loff_t *ppos) {
2148
Joe Perches57674302010-07-12 13:50:06 -07002149 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002150 int len = 0;
2151 char buf[20];
2152
2153 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002154 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002155 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2156}
2157
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002158static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2159 char __user *user_buf,
2160 size_t count, loff_t *ppos) {
2161
2162 struct iwl_priv *priv = file->private_data;
2163 int pos = 0;
2164 char buf[12];
2165 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002166
2167 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2168 priv->missed_beacon_threshold);
2169
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002170 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002171}
2172
2173static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2174 const char __user *user_buf,
2175 size_t count, loff_t *ppos)
2176{
2177 struct iwl_priv *priv = file->private_data;
2178 char buf[8];
2179 int buf_size;
2180 int missed;
2181
2182 memset(buf, 0, sizeof(buf));
2183 buf_size = min(count, sizeof(buf) - 1);
2184 if (copy_from_user(buf, user_buf, buf_size))
2185 return -EFAULT;
2186 if (sscanf(buf, "%d", &missed) != 1)
2187 return -EINVAL;
2188
2189 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2190 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2191 priv->missed_beacon_threshold =
2192 IWL_MISSED_BEACON_THRESHOLD_DEF;
2193 else
2194 priv->missed_beacon_threshold = missed;
2195
2196 return count;
2197}
2198
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002199static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2200 char __user *user_buf,
2201 size_t count, loff_t *ppos) {
2202
Joe Perches57674302010-07-12 13:50:06 -07002203 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002204 int pos = 0;
2205 char buf[12];
2206 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002207
2208 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002209 priv->cfg->base_params->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002210
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002211 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002212}
2213
2214static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2215 const char __user *user_buf,
2216 size_t count, loff_t *ppos) {
2217
2218 struct iwl_priv *priv = file->private_data;
2219 char buf[8];
2220 int buf_size;
2221 int plcp;
2222
2223 memset(buf, 0, sizeof(buf));
2224 buf_size = min(count, sizeof(buf) - 1);
2225 if (copy_from_user(buf, user_buf, buf_size))
2226 return -EFAULT;
2227 if (sscanf(buf, "%d", &plcp) != 1)
2228 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002229 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002230 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002231 priv->cfg->base_params->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002232 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002233 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002234 priv->cfg->base_params->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002235 return count;
2236}
2237
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002238static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2239 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002240 size_t count, loff_t *ppos)
2241{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002242 struct iwl_priv *priv = file->private_data;
2243 int i, pos = 0;
2244 char buf[300];
2245 const size_t bufsz = sizeof(buf);
2246 struct iwl_force_reset *force_reset;
2247
2248 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2249 force_reset = &priv->force_reset[i];
2250 pos += scnprintf(buf + pos, bufsz - pos,
2251 "Force reset method %d\n", i);
2252 pos += scnprintf(buf + pos, bufsz - pos,
2253 "\tnumber of reset request: %d\n",
2254 force_reset->reset_request_count);
2255 pos += scnprintf(buf + pos, bufsz - pos,
2256 "\tnumber of reset request success: %d\n",
2257 force_reset->reset_success_count);
2258 pos += scnprintf(buf + pos, bufsz - pos,
2259 "\tnumber of reset request reject: %d\n",
2260 force_reset->reset_reject_count);
2261 pos += scnprintf(buf + pos, bufsz - pos,
2262 "\treset duration: %lu\n",
2263 force_reset->reset_duration);
2264 }
2265 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2266}
2267
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002268static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2269 const char __user *user_buf,
2270 size_t count, loff_t *ppos) {
2271
2272 struct iwl_priv *priv = file->private_data;
2273 char buf[8];
2274 int buf_size;
2275 int reset, ret;
2276
2277 memset(buf, 0, sizeof(buf));
2278 buf_size = min(count, sizeof(buf) - 1);
2279 if (copy_from_user(buf, user_buf, buf_size))
2280 return -EFAULT;
2281 if (sscanf(buf, "%d", &reset) != 1)
2282 return -EINVAL;
2283 switch (reset) {
2284 case IWL_RF_RESET:
2285 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002286 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002287 break;
2288 default:
2289 return -EINVAL;
2290 }
2291 return ret ? ret : count;
2292}
2293
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002294static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2295 const char __user *user_buf,
2296 size_t count, loff_t *ppos) {
2297
2298 struct iwl_priv *priv = file->private_data;
2299 char buf[8];
2300 int buf_size;
2301 int flush;
2302
2303 memset(buf, 0, sizeof(buf));
2304 buf_size = min(count, sizeof(buf) - 1);
2305 if (copy_from_user(buf, user_buf, buf_size))
2306 return -EFAULT;
2307 if (sscanf(buf, "%d", &flush) != 1)
2308 return -EINVAL;
2309
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07002310 if (iwl_is_rfkill(priv->shrd))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002311 return -EFAULT;
2312
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002313 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002314
2315 return count;
2316}
2317
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002318static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002319 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002320 size_t count, loff_t *ppos)
2321{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002322 struct iwl_priv *priv = file->private_data;
2323 char buf[8];
2324 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002325 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002326
2327 memset(buf, 0, sizeof(buf));
2328 buf_size = min(count, sizeof(buf) - 1);
2329 if (copy_from_user(buf, user_buf, buf_size))
2330 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002331 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002332 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002333 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2334 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002335
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002336 priv->cfg->base_params->wd_timeout = timeout;
2337 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002338 return count;
2339}
2340
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002341static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2342 char __user *user_buf,
2343 size_t count, loff_t *ppos) {
2344
2345 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2346 int pos = 0;
2347 char buf[200];
2348 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002349
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002350 if (!priv->bt_enable_flag) {
2351 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002352 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002353 }
2354 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2355 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002356 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2357 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2358 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2359 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002360 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002361 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002362 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2363 priv->bt_ch_announce, priv->kill_ack_mask,
2364 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002365
2366 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2367 switch (priv->bt_traffic_load) {
2368 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2369 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2370 break;
2371 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2372 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2373 break;
2374 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2375 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2376 break;
2377 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2378 default:
2379 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2380 break;
2381 }
2382
Johannes Berg08960de2011-04-05 09:41:53 -07002383 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002384}
2385
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002386static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2387 char __user *user_buf,
2388 size_t count, loff_t *ppos)
2389{
2390 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2391
2392 int pos = 0;
2393 char buf[40];
2394 const size_t bufsz = sizeof(buf);
2395
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002396 if (priv->cfg->ht_params)
2397 pos += scnprintf(buf + pos, bufsz - pos,
2398 "use %s for aggregation\n",
2399 (priv->cfg->ht_params->use_rts_for_aggregation) ?
2400 "rts/cts" : "cts-to-self");
2401 else
2402 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2403
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002404 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2405}
2406
2407static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2408 const char __user *user_buf,
2409 size_t count, loff_t *ppos) {
2410
2411 struct iwl_priv *priv = file->private_data;
2412 char buf[8];
2413 int buf_size;
2414 int rts;
2415
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002416 if (!priv->cfg->ht_params)
2417 return -EINVAL;
2418
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002419 memset(buf, 0, sizeof(buf));
2420 buf_size = min(count, sizeof(buf) - 1);
2421 if (copy_from_user(buf, user_buf, buf_size))
2422 return -EFAULT;
2423 if (sscanf(buf, "%d", &rts) != 1)
2424 return -EINVAL;
2425 if (rts)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002426 priv->cfg->ht_params->use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002427 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002428 priv->cfg->ht_params->use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002429 return count;
2430}
2431
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002432DEBUGFS_READ_FILE_OPS(rx_statistics);
2433DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002434DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002435DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2436DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2437DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002438DEBUGFS_READ_FILE_OPS(sensitivity);
2439DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002440DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002441DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2442DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002443DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002444DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002445DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002446DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002447DEBUGFS_READ_FILE_OPS(rxon_flags);
2448DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002449DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002450DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002451DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002452DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002453DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002454DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002455
Johannes Bergca934b62011-09-15 11:46:48 -07002456#ifdef CONFIG_IWLWIFI_DEBUG
2457static ssize_t iwl_dbgfs_debug_level_read(struct file *file,
2458 char __user *user_buf,
2459 size_t count, loff_t *ppos)
2460{
2461 struct iwl_priv *priv = file->private_data;
2462 struct iwl_shared *shrd = priv->shrd;
2463 char buf[11];
2464 int len;
2465
2466 len = scnprintf(buf, sizeof(buf), "0x%.8x",
2467 iwl_get_debug_level(shrd));
2468
2469 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2470}
2471
2472static ssize_t iwl_dbgfs_debug_level_write(struct file *file,
2473 const char __user *user_buf,
2474 size_t count, loff_t *ppos)
2475{
2476 struct iwl_priv *priv = file->private_data;
2477 struct iwl_shared *shrd = priv->shrd;
2478 char buf[11];
2479 unsigned long val;
2480 int ret;
2481
2482 if (count > sizeof(buf))
2483 return -EINVAL;
2484
2485 memset(buf, 0, sizeof(buf));
2486 if (copy_from_user(buf, user_buf, count))
2487 return -EFAULT;
2488
2489 ret = strict_strtoul(buf, 0, &val);
2490 if (ret)
2491 return ret;
2492
2493 shrd->dbg_level_dev = val;
2494 if (iwl_alloc_traffic_mem(priv))
2495 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
2496
2497 return count;
2498}
2499DEBUGFS_READ_WRITE_FILE_OPS(debug_level);
2500#endif /* CONFIG_IWLWIFI_DEBUG */
2501
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002502/*
2503 * Create the debugfs files and directories
2504 *
2505 */
2506int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2507{
Zhu Yi95b1a822008-05-29 16:34:50 +08002508 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002509 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002510
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002511 dir_drv = debugfs_create_dir(name, phyd);
2512 if (!dir_drv)
2513 return -ENOMEM;
2514
2515 priv->debugfs_dir = dir_drv;
2516
2517 dir_data = debugfs_create_dir("data", dir_drv);
2518 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002519 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002520 dir_rf = debugfs_create_dir("rf", dir_drv);
2521 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002522 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002523 dir_debug = debugfs_create_dir("debug", dir_drv);
2524 if (!dir_debug)
2525 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002526
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002527 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2528 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002529 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002530 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2531 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2532 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002533 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002534 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002535 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2536 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002537 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2538 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002539 DEBUGFS_ADD_U32(temperature, dir_data, &priv->temperature, S_IRUSR);
2540
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002541 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2542 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002543 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002544 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2545 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2546 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002547 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002548 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002549 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002550 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2551 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2552 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002553 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002554 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002555 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2556 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002557 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002558 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002559 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002560 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2561 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002562 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002563 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002564 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002565#ifdef CONFIG_IWLWIFI_DEBUG
2566 DEBUGFS_ADD_FILE(debug_level, dir_debug, S_IRUSR | S_IWUSR);
2567#endif
2568
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002569 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2570 &priv->disable_sens_cal);
2571 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2572 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002573
2574 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2575 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002576 return 0;
2577
2578err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002579 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002580 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002581 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002582}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002583
2584/**
2585 * Remove the debugfs files and directories
2586 *
2587 */
2588void iwl_dbgfs_unregister(struct iwl_priv *priv)
2589{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002590 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002591 return;
2592
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002593 debugfs_remove_recursive(priv->debugfs_dir);
2594 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002595}