blob: d3223214a80121022ee0d072549b41b5e8bb79e9 [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
Tomas Winkler712b6cf2008-03-12 16:58:52 -070067/* file operation */
68#define DEBUGFS_READ_FUNC(name) \
69static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
70 char __user *user_buf, \
71 size_t count, loff_t *ppos);
72
73#define DEBUGFS_WRITE_FUNC(name) \
74static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
75 const char __user *user_buf, \
76 size_t count, loff_t *ppos);
77
78
79static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
80{
81 file->private_data = inode->i_private;
82 return 0;
83}
84
85#define DEBUGFS_READ_FILE_OPS(name) \
86 DEBUGFS_READ_FUNC(name); \
87static const struct file_operations iwl_dbgfs_##name##_ops = { \
88 .read = iwl_dbgfs_##name##_read, \
89 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020090 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070091};
92
Ester Kummer189a2b52008-05-15 13:54:18 +080093#define DEBUGFS_WRITE_FILE_OPS(name) \
94 DEBUGFS_WRITE_FUNC(name); \
95static const struct file_operations iwl_dbgfs_##name##_ops = { \
96 .write = iwl_dbgfs_##name##_write, \
97 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020098 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +080099};
100
101
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700102#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
103 DEBUGFS_READ_FUNC(name); \
104 DEBUGFS_WRITE_FUNC(name); \
105static const struct file_operations iwl_dbgfs_##name##_ops = { \
106 .write = iwl_dbgfs_##name##_write, \
107 .read = iwl_dbgfs_##name##_read, \
108 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200109 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700110};
111
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700112static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
113 char __user *user_buf,
114 size_t count, loff_t *ppos) {
115
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700116 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700117 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700118 int pos = 0;
119
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700120 int cnt;
121 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800122 const size_t bufsz = 100 +
123 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700124 buf = kzalloc(bufsz, GFP_KERNEL);
125 if (!buf)
126 return -ENOMEM;
127 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
128 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
129 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800130 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700131 get_mgmt_string(cnt),
132 priv->tx_stats.mgmt[cnt]);
133 }
134 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
135 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
136 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800137 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700138 get_ctrl_string(cnt),
139 priv->tx_stats.ctrl[cnt]);
140 }
141 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
142 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
143 priv->tx_stats.data_cnt);
144 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
145 priv->tx_stats.data_bytes);
146 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
147 kfree(buf);
148 return ret;
149}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700150
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800151static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700152 const char __user *user_buf,
153 size_t count, loff_t *ppos)
154{
155 struct iwl_priv *priv = file->private_data;
156 u32 clear_flag;
157 char buf[8];
158 int buf_size;
159
160 memset(buf, 0, sizeof(buf));
161 buf_size = min(count, sizeof(buf) - 1);
162 if (copy_from_user(buf, user_buf, buf_size))
163 return -EFAULT;
164 if (sscanf(buf, "%x", &clear_flag) != 1)
165 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800166 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700167
168 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700169}
170
171static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
172 char __user *user_buf,
173 size_t count, loff_t *ppos) {
174
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700175 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700176 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700177 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700178 int cnt;
179 ssize_t ret;
180 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800181 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700182 buf = kzalloc(bufsz, GFP_KERNEL);
183 if (!buf)
184 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700185
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700186 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
187 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
188 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800189 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700190 get_mgmt_string(cnt),
191 priv->rx_stats.mgmt[cnt]);
192 }
193 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
194 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
195 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800196 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700197 get_ctrl_string(cnt),
198 priv->rx_stats.ctrl[cnt]);
199 }
200 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
201 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
202 priv->rx_stats.data_cnt);
203 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
204 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700205
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700206 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
207 kfree(buf);
208 return ret;
209}
210
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700211static ssize_t iwl_dbgfs_sram_read(struct file *file,
212 char __user *user_buf,
213 size_t count, loff_t *ppos)
214{
Jay Sternberg24834d22011-01-11 15:41:00 -0800215 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800216 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700217 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800218 int i = 0;
219 bool device_format = false;
220 int offset = 0;
221 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700222 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800223 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700224 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800225 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700226
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800227 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800228 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
229 priv->dbgfs_sram_offset = 0x800000;
Johannes Berg872907b2011-06-06 09:41:15 -0700230 if (priv->ucode_type == IWL_UCODE_INIT)
Johannes Bergdbf28e212011-04-16 08:29:24 -0700231 priv->dbgfs_sram_len = priv->ucode_init.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800232 else
Johannes Bergdbf28e212011-04-16 08:29:24 -0700233 priv->dbgfs_sram_len = priv->ucode_rt.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800234 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800235 len = priv->dbgfs_sram_len;
236
237 if (len == -4) {
238 device_format = true;
239 len = 4;
240 }
241
242 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800243 buf = kmalloc(bufsz, GFP_KERNEL);
244 if (!buf)
245 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800246
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800247 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800248 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800249 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800250 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800251
252 /* adjust sram address since reads are only on even u32 boundaries */
253 offset = priv->dbgfs_sram_offset & 0x3;
254 sram = priv->dbgfs_sram_offset & ~0x3;
255
256 /* read the first u32 from sram */
257 val = iwl_read_targ_mem(priv, sram);
258
259 for (; len; len--) {
260 /* put the address at the start of every line */
261 if (i == 0)
262 pos += scnprintf(buf + pos, bufsz - pos,
263 "%08X: ", sram + offset);
264
265 if (device_format)
266 pos += scnprintf(buf + pos, bufsz - pos,
267 "%02x", (val >> (8 * (3 - offset))) & 0xff);
268 else
269 pos += scnprintf(buf + pos, bufsz - pos,
270 "%02x ", (val >> (8 * offset)) & 0xff);
271
272 /* if all bytes processed, read the next u32 from sram */
273 if (++offset == 4) {
274 sram += 4;
275 offset = 0;
276 val = iwl_read_targ_mem(priv, sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700277 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800278
279 /* put in extra spaces and split lines for human readability */
280 if (++i == 16) {
281 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800282 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800283 } else if (!(i & 7)) {
284 pos += scnprintf(buf + pos, bufsz - pos, " ");
285 } else if (!(i & 3)) {
286 pos += scnprintf(buf + pos, bufsz - pos, " ");
287 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700288 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800289 if (i)
290 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700291
292 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800293 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700294 return ret;
295}
296
297static ssize_t iwl_dbgfs_sram_write(struct file *file,
298 const char __user *user_buf,
299 size_t count, loff_t *ppos)
300{
301 struct iwl_priv *priv = file->private_data;
302 char buf[64];
303 int buf_size;
304 u32 offset, len;
305
306 memset(buf, 0, sizeof(buf));
307 buf_size = min(count, sizeof(buf) - 1);
308 if (copy_from_user(buf, user_buf, buf_size))
309 return -EFAULT;
310
311 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800312 priv->dbgfs_sram_offset = offset;
313 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800314 } else if (sscanf(buf, "%x", &offset) == 1) {
315 priv->dbgfs_sram_offset = offset;
316 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700317 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800318 priv->dbgfs_sram_offset = 0;
319 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700320 }
321
322 return count;
323}
324
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700325static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
326 char __user *user_buf,
327 size_t count, loff_t *ppos)
328{
329 struct iwl_priv *priv = file->private_data;
330
331 if (!priv->wowlan_sram)
332 return -ENODATA;
333
334 return simple_read_from_buffer(user_buf, count, ppos,
335 priv->wowlan_sram,
336 priv->ucode_wowlan.data.len);
337}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700338static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
339 size_t count, loff_t *ppos)
340{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700341 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800342 struct iwl_station_entry *station;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700343 int max_sta = hw_params(priv).max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700344 char *buf;
345 int i, j, pos = 0;
346 ssize_t ret;
347 /* Add 30 for initial string */
348 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700349
350 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300351 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700352 return -ENOMEM;
353
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700354 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700355 priv->num_stations);
356
357 for (i = 0; i < max_sta; i++) {
358 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700359 if (!station->used)
360 continue;
361 pos += scnprintf(buf + pos, bufsz - pos,
362 "station %d - addr: %pM, flags: %#x\n",
363 i, station->sta.sta.addr,
364 station->sta.station_flags_msk);
365 pos += scnprintf(buf + pos, bufsz - pos,
366 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
367 pos += scnprintf(buf + pos, bufsz - pos,
368 "start_idx\tbitmap\t\t\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700369
Johannes Bergda735112010-05-03 01:25:24 -0700370 for (j = 0; j < MAX_TID_COUNT; j++) {
371 pos += scnprintf(buf + pos, bufsz - pos,
372 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
373 j, station->tid[j].seq_number,
374 station->tid[j].agg.txq_id,
375 station->tid[j].agg.frame_count,
376 station->tid[j].tfds_in_queue,
377 station->tid[j].agg.start_idx,
378 station->tid[j].agg.bitmap,
379 station->tid[j].agg.rate_n_flags);
380
381 if (station->tid[j].agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700382 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700383 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700384 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700385 }
Johannes Bergda735112010-05-03 01:25:24 -0700386
387 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700388 }
389
390 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
391 kfree(buf);
392 return ret;
393}
394
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700395static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800396 char __user *user_buf,
397 size_t count,
398 loff_t *ppos)
399{
400 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700401 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800402 int pos = 0, ofs = 0, buf_size = 0;
403 const u8 *ptr;
404 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700405 u16 eeprom_ver;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -0700406 size_t eeprom_len = priv->cfg->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800407 buf_size = 4 * eeprom_len + 256;
408
409 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700410 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800411 return -ENODATA;
412 }
413
Julia Lawallc37457e2009-08-03 11:11:45 +0200414 ptr = priv->eeprom;
415 if (!ptr) {
416 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
417 return -ENOMEM;
418 }
419
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800420 /* 4 characters for byte 0xYY */
421 buf = kzalloc(buf_size, GFP_KERNEL);
422 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800423 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800424 return -ENOMEM;
425 }
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700426 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
427 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
428 "version: 0x%x\n",
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700429 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700430 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800431 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
432 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
433 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
434 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700435 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800436 if (buf_size - pos > 0)
437 buf[pos++] = '\n';
438 }
439
440 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
441 kfree(buf);
442 return ret;
443}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700444
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800445static ssize_t iwl_dbgfs_log_event_read(struct file *file,
446 char __user *user_buf,
447 size_t count, loff_t *ppos)
448{
449 struct iwl_priv *priv = file->private_data;
450 char *buf;
451 int pos = 0;
452 ssize_t ret = -ENOMEM;
453
Wey-Yi Guy3ecccbc2011-03-29 17:53:15 -0700454 ret = pos = iwl_dump_nic_event_log(priv, true, &buf, true);
Wey-Yi Guy937c3972010-01-15 13:43:36 -0800455 if (buf) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800456 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
457 kfree(buf);
458 }
459 return ret;
460}
461
Ester Kummer189a2b52008-05-15 13:54:18 +0800462static ssize_t iwl_dbgfs_log_event_write(struct file *file,
463 const char __user *user_buf,
464 size_t count, loff_t *ppos)
465{
466 struct iwl_priv *priv = file->private_data;
467 u32 event_log_flag;
468 char buf[8];
469 int buf_size;
470
471 memset(buf, 0, sizeof(buf));
472 buf_size = min(count, sizeof(buf) - 1);
473 if (copy_from_user(buf, user_buf, buf_size))
474 return -EFAULT;
475 if (sscanf(buf, "%d", &event_log_flag) != 1)
476 return -EFAULT;
477 if (event_log_flag == 1)
Wey-Yi Guy3ecccbc2011-03-29 17:53:15 -0700478 iwl_dump_nic_event_log(priv, true, NULL, false);
Ester Kummer189a2b52008-05-15 13:54:18 +0800479
480 return count;
481}
482
Winkler, Tomasd366df52008-12-02 12:14:01 -0800483
484
485static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
486 size_t count, loff_t *ppos)
487{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700488 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800489 struct ieee80211_channel *channels = NULL;
490 const struct ieee80211_supported_band *supp_band = NULL;
491 int pos = 0, i, bufsz = PAGE_SIZE;
492 char *buf;
493 ssize_t ret;
494
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700495 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800496 return -EAGAIN;
497
498 buf = kzalloc(bufsz, GFP_KERNEL);
499 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800500 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800501 return -ENOMEM;
502 }
503
504 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700505 if (supp_band) {
506 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800507
Winkler, Tomasd366df52008-12-02 12:14:01 -0800508 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700509 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
510 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800511
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700512 for (i = 0; i < supp_band->n_channels; i++)
513 pos += scnprintf(buf + pos, bufsz - pos,
514 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700515 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700516 channels[i].max_power,
517 channels[i].flags & IEEE80211_CHAN_RADAR ?
518 " (IEEE 802.11h required)" : "",
519 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
520 || (channels[i].flags &
521 IEEE80211_CHAN_RADAR)) ? "" :
522 ", IBSS",
523 channels[i].flags &
524 IEEE80211_CHAN_PASSIVE_SCAN ?
525 "passive only" : "active/passive");
526 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800527 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700528 if (supp_band) {
529 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800530
Winkler, Tomasd366df52008-12-02 12:14:01 -0800531 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700532 "Displaying %d channels in 5.2GHz band (802.11a)\n",
533 supp_band->n_channels);
534
535 for (i = 0; i < supp_band->n_channels; i++)
536 pos += scnprintf(buf + pos, bufsz - pos,
537 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700538 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700539 channels[i].max_power,
540 channels[i].flags & IEEE80211_CHAN_RADAR ?
541 " (IEEE 802.11h required)" : "",
542 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
543 || (channels[i].flags &
544 IEEE80211_CHAN_RADAR)) ? "" :
545 ", IBSS",
546 channels[i].flags &
547 IEEE80211_CHAN_PASSIVE_SCAN ?
548 "passive only" : "active/passive");
549 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800550 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
551 kfree(buf);
552 return ret;
553}
554
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700555static ssize_t iwl_dbgfs_status_read(struct file *file,
556 char __user *user_buf,
557 size_t count, loff_t *ppos) {
558
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700559 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700560 char buf[512];
561 int pos = 0;
562 const size_t bufsz = sizeof(buf);
563
564 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700565 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700566 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700567 test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700568 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700569 test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700570 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700571 test_bit(STATUS_CT_KILL, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700572 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700573 test_bit(STATUS_INIT, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700574 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700575 test_bit(STATUS_ALIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700576 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700577 test_bit(STATUS_READY, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700578 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700579 test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700580 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700581 test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700582 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700583 test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700584 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700585 test_bit(STATUS_STATISTICS, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700586 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700587 test_bit(STATUS_SCANNING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700588 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700589 test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700590 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700591 test_bit(STATUS_SCAN_HW, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700592 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700593 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700594 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700595 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700596 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
597}
598
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700599static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
600 char __user *user_buf,
601 size_t count, loff_t *ppos) {
602
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700603 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700604 int pos = 0;
605 int cnt = 0;
606 char *buf;
607 int bufsz = 24 * 64; /* 24 items * 64 char per item */
608 ssize_t ret;
609
610 buf = kzalloc(bufsz, GFP_KERNEL);
611 if (!buf) {
612 IWL_ERR(priv, "Can not allocate Buffer\n");
613 return -ENOMEM;
614 }
615
616 pos += scnprintf(buf + pos, bufsz - pos,
617 "Interrupt Statistics Report:\n");
618
619 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
620 priv->isr_stats.hw);
621 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
622 priv->isr_stats.sw);
Wey-Yi Guy6e6ebf42010-08-27 10:41:37 -0700623 if (priv->isr_stats.sw || priv->isr_stats.hw) {
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700624 pos += scnprintf(buf + pos, bufsz - pos,
625 "\tLast Restarting Code: 0x%X\n",
Wey-Yi Guy6e6ebf42010-08-27 10:41:37 -0700626 priv->isr_stats.err_code);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700627 }
628#ifdef CONFIG_IWLWIFI_DEBUG
629 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
630 priv->isr_stats.sch);
631 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
632 priv->isr_stats.alive);
633#endif
634 pos += scnprintf(buf + pos, bufsz - pos,
635 "HW RF KILL switch toggled:\t %u\n",
636 priv->isr_stats.rfkill);
637
638 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
639 priv->isr_stats.ctkill);
640
641 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
642 priv->isr_stats.wakeup);
643
644 pos += scnprintf(buf + pos, bufsz - pos,
645 "Rx command responses:\t\t %u\n",
646 priv->isr_stats.rx);
647 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
648 if (priv->isr_stats.rx_handlers[cnt] > 0)
649 pos += scnprintf(buf + pos, bufsz - pos,
650 "\tRx handler[%36s]:\t\t %u\n",
651 get_cmd_string(cnt),
652 priv->isr_stats.rx_handlers[cnt]);
653 }
654
655 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
656 priv->isr_stats.tx);
657
658 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
659 priv->isr_stats.unhandled);
660
661 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
662 kfree(buf);
663 return ret;
664}
665
666static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
667 const char __user *user_buf,
668 size_t count, loff_t *ppos)
669{
670 struct iwl_priv *priv = file->private_data;
671 char buf[8];
672 int buf_size;
673 u32 reset_flag;
674
675 memset(buf, 0, sizeof(buf));
676 buf_size = min(count, sizeof(buf) - 1);
677 if (copy_from_user(buf, user_buf, buf_size))
678 return -EFAULT;
679 if (sscanf(buf, "%x", &reset_flag) != 1)
680 return -EFAULT;
681 if (reset_flag == 0)
682 iwl_clear_isr_stats(priv);
683
684 return count;
685}
686
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700687static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
688 size_t count, loff_t *ppos)
689{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700690 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200691 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700692 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200693 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700694 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700695
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200696 for_each_context(priv, ctx) {
697 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
698 ctx->ctxid);
699 for (i = 0; i < AC_NUM; i++) {
700 pos += scnprintf(buf + pos, bufsz - pos,
701 "\tcw_min\tcw_max\taifsn\ttxop\n");
702 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700703 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200704 ctx->qos_data.def_qos_parm.ac[i].cw_min,
705 ctx->qos_data.def_qos_parm.ac[i].cw_max,
706 ctx->qos_data.def_qos_parm.ac[i].aifsn,
707 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
708 }
709 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700710 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800711 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700712}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700713
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700714static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
715 char __user *user_buf,
716 size_t count, loff_t *ppos)
717{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700718 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700719 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700720 struct iwl_tt_restriction *restriction;
721 char buf[100];
722 int pos = 0;
723 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700724
725 pos += scnprintf(buf + pos, bufsz - pos,
726 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700727 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700728 pos += scnprintf(buf + pos, bufsz - pos,
729 "Thermal Throttling State: %d\n",
730 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700731 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700732 restriction = tt->restriction + tt->state;
733 pos += scnprintf(buf + pos, bufsz - pos,
734 "Tx mode: %d\n",
735 restriction->tx_stream);
736 pos += scnprintf(buf + pos, bufsz - pos,
737 "Rx mode: %d\n",
738 restriction->rx_stream);
739 pos += scnprintf(buf + pos, bufsz - pos,
740 "HT mode: %d\n",
741 restriction->is_ht);
742 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800743 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700744}
745
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700746static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
747 const char __user *user_buf,
748 size_t count, loff_t *ppos)
749{
750 struct iwl_priv *priv = file->private_data;
751 char buf[8];
752 int buf_size;
753 int ht40;
754
755 memset(buf, 0, sizeof(buf));
756 buf_size = min(count, sizeof(buf) - 1);
757 if (copy_from_user(buf, user_buf, buf_size))
758 return -EFAULT;
759 if (sscanf(buf, "%d", &ht40) != 1)
760 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200761 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700762 priv->disable_ht40 = ht40 ? true : false;
763 else {
764 IWL_ERR(priv, "Sta associated with AP - "
765 "Change to 40MHz channel support is not allowed\n");
766 return -EINVAL;
767 }
768
769 return count;
770}
771
772static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
773 char __user *user_buf,
774 size_t count, loff_t *ppos)
775{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700776 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700777 char buf[100];
778 int pos = 0;
779 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700780
781 pos += scnprintf(buf + pos, bufsz - pos,
782 "11n 40MHz Mode: %s\n",
783 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800784 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700785}
786
Johannes Berge312c242009-08-07 15:41:51 -0700787static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
788 const char __user *user_buf,
789 size_t count, loff_t *ppos)
790{
791 struct iwl_priv *priv = file->private_data;
792 char buf[8];
793 int buf_size;
794 int value;
795
796 memset(buf, 0, sizeof(buf));
797 buf_size = min(count, sizeof(buf) - 1);
798 if (copy_from_user(buf, user_buf, buf_size))
799 return -EFAULT;
800
801 if (sscanf(buf, "%d", &value) != 1)
802 return -EINVAL;
803
804 /*
805 * Our users expect 0 to be "CAM", but 0 isn't actually
806 * valid here. However, let's not confuse them and present
807 * IWL_POWER_INDEX_1 as "1", not "0".
808 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700809 if (value == 0)
810 return -EINVAL;
811 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700812 value -= 1;
813
814 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
815 return -EINVAL;
816
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700817 if (!iwl_is_ready_rf(priv))
818 return -EAGAIN;
819
Johannes Berge312c242009-08-07 15:41:51 -0700820 priv->power_data.debug_sleep_level_override = value;
821
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700822 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700823 iwl_power_update_mode(priv, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700824 mutex_unlock(&priv->shrd->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700825
826 return count;
827}
828
829static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
830 char __user *user_buf,
831 size_t count, loff_t *ppos)
832{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700833 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700834 char buf[10];
835 int pos, value;
836 const size_t bufsz = sizeof(buf);
837
838 /* see the write function */
839 value = priv->power_data.debug_sleep_level_override;
840 if (value >= 0)
841 value += 1;
842
843 pos = scnprintf(buf, bufsz, "%d\n", value);
844 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
845}
846
847static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
848 char __user *user_buf,
849 size_t count, loff_t *ppos)
850{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700851 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700852 char buf[200];
853 int pos = 0, i;
854 const size_t bufsz = sizeof(buf);
855 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
856
857 pos += scnprintf(buf + pos, bufsz - pos,
858 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
859 pos += scnprintf(buf + pos, bufsz - pos,
860 "RX/TX timeout: %d/%d usec\n",
861 le32_to_cpu(cmd->rx_data_timeout),
862 le32_to_cpu(cmd->tx_data_timeout));
863 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
864 pos += scnprintf(buf + pos, bufsz - pos,
865 "sleep_interval[%d]: %d\n", i,
866 le32_to_cpu(cmd->sleep_interval[i]));
867
868 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
869}
870
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700871DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700872DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800873DEBUGFS_READ_WRITE_FILE_OPS(log_event);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700874DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700875DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800876DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700877DEBUGFS_READ_FILE_OPS(status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700878DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700879DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700880DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700881DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Johannes Berge312c242009-08-07 15:41:51 -0700882DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
883DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700884
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700885static const char *fmt_value = " %-30s %10u\n";
886static const char *fmt_hex = " %-30s 0x%02X\n";
887static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
888static const char *fmt_header =
889 "%-32s current cumulative delta max\n";
890
891static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
892{
893 int p = 0;
894 u32 flag;
895
896 flag = le32_to_cpu(priv->statistics.flag);
897
898 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
899 if (flag & UCODE_STATISTICS_CLEAR_MSK)
900 p += scnprintf(buf + p, bufsz - p,
901 "\tStatistics have been cleared\n");
902 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
903 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
904 ? "2.4 GHz" : "5.2 GHz");
905 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
906 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
907 ? "enabled" : "disabled");
908
909 return p;
910}
911
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700912static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
913 char __user *user_buf,
914 size_t count, loff_t *ppos)
915{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700916 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700917 int pos = 0;
918 char *buf;
919 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
920 sizeof(struct statistics_rx_non_phy) * 40 +
921 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
922 ssize_t ret;
923 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
924 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
925 struct statistics_rx_non_phy *general, *accum_general;
926 struct statistics_rx_non_phy *delta_general, *max_general;
927 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
928
929 if (!iwl_is_alive(priv))
930 return -EAGAIN;
931
932 buf = kzalloc(bufsz, GFP_KERNEL);
933 if (!buf) {
934 IWL_ERR(priv, "Can not allocate Buffer\n");
935 return -ENOMEM;
936 }
937
938 /*
939 * the statistic information display here is based on
940 * the last statistics notification from uCode
941 * might not reflect the current uCode activity
942 */
943 ofdm = &priv->statistics.rx_ofdm;
944 cck = &priv->statistics.rx_cck;
945 general = &priv->statistics.rx_non_phy;
946 ht = &priv->statistics.rx_ofdm_ht;
947 accum_ofdm = &priv->accum_stats.rx_ofdm;
948 accum_cck = &priv->accum_stats.rx_cck;
949 accum_general = &priv->accum_stats.rx_non_phy;
950 accum_ht = &priv->accum_stats.rx_ofdm_ht;
951 delta_ofdm = &priv->delta_stats.rx_ofdm;
952 delta_cck = &priv->delta_stats.rx_cck;
953 delta_general = &priv->delta_stats.rx_non_phy;
954 delta_ht = &priv->delta_stats.rx_ofdm_ht;
955 max_ofdm = &priv->max_delta_stats.rx_ofdm;
956 max_cck = &priv->max_delta_stats.rx_cck;
957 max_general = &priv->max_delta_stats.rx_non_phy;
958 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
959
960 pos += iwl_statistics_flag(priv, buf, bufsz);
961 pos += scnprintf(buf + pos, bufsz - pos,
962 fmt_header, "Statistics_Rx - OFDM:");
963 pos += scnprintf(buf + pos, bufsz - pos,
964 fmt_table, "ina_cnt:",
965 le32_to_cpu(ofdm->ina_cnt),
966 accum_ofdm->ina_cnt,
967 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
968 pos += scnprintf(buf + pos, bufsz - pos,
969 fmt_table, "fina_cnt:",
970 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
971 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
972 pos += scnprintf(buf + pos, bufsz - pos,
973 fmt_table, "plcp_err:",
974 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
975 delta_ofdm->plcp_err, max_ofdm->plcp_err);
976 pos += scnprintf(buf + pos, bufsz - pos,
977 fmt_table, "crc32_err:",
978 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
979 delta_ofdm->crc32_err, max_ofdm->crc32_err);
980 pos += scnprintf(buf + pos, bufsz - pos,
981 fmt_table, "overrun_err:",
982 le32_to_cpu(ofdm->overrun_err),
983 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
984 max_ofdm->overrun_err);
985 pos += scnprintf(buf + pos, bufsz - pos,
986 fmt_table, "early_overrun_err:",
987 le32_to_cpu(ofdm->early_overrun_err),
988 accum_ofdm->early_overrun_err,
989 delta_ofdm->early_overrun_err,
990 max_ofdm->early_overrun_err);
991 pos += scnprintf(buf + pos, bufsz - pos,
992 fmt_table, "crc32_good:",
993 le32_to_cpu(ofdm->crc32_good),
994 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
995 max_ofdm->crc32_good);
996 pos += scnprintf(buf + pos, bufsz - pos,
997 fmt_table, "false_alarm_cnt:",
998 le32_to_cpu(ofdm->false_alarm_cnt),
999 accum_ofdm->false_alarm_cnt,
1000 delta_ofdm->false_alarm_cnt,
1001 max_ofdm->false_alarm_cnt);
1002 pos += scnprintf(buf + pos, bufsz - pos,
1003 fmt_table, "fina_sync_err_cnt:",
1004 le32_to_cpu(ofdm->fina_sync_err_cnt),
1005 accum_ofdm->fina_sync_err_cnt,
1006 delta_ofdm->fina_sync_err_cnt,
1007 max_ofdm->fina_sync_err_cnt);
1008 pos += scnprintf(buf + pos, bufsz - pos,
1009 fmt_table, "sfd_timeout:",
1010 le32_to_cpu(ofdm->sfd_timeout),
1011 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1012 max_ofdm->sfd_timeout);
1013 pos += scnprintf(buf + pos, bufsz - pos,
1014 fmt_table, "fina_timeout:",
1015 le32_to_cpu(ofdm->fina_timeout),
1016 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1017 max_ofdm->fina_timeout);
1018 pos += scnprintf(buf + pos, bufsz - pos,
1019 fmt_table, "unresponded_rts:",
1020 le32_to_cpu(ofdm->unresponded_rts),
1021 accum_ofdm->unresponded_rts,
1022 delta_ofdm->unresponded_rts,
1023 max_ofdm->unresponded_rts);
1024 pos += scnprintf(buf + pos, bufsz - pos,
1025 fmt_table, "rxe_frame_lmt_ovrun:",
1026 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1027 accum_ofdm->rxe_frame_limit_overrun,
1028 delta_ofdm->rxe_frame_limit_overrun,
1029 max_ofdm->rxe_frame_limit_overrun);
1030 pos += scnprintf(buf + pos, bufsz - pos,
1031 fmt_table, "sent_ack_cnt:",
1032 le32_to_cpu(ofdm->sent_ack_cnt),
1033 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1034 max_ofdm->sent_ack_cnt);
1035 pos += scnprintf(buf + pos, bufsz - pos,
1036 fmt_table, "sent_cts_cnt:",
1037 le32_to_cpu(ofdm->sent_cts_cnt),
1038 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1039 max_ofdm->sent_cts_cnt);
1040 pos += scnprintf(buf + pos, bufsz - pos,
1041 fmt_table, "sent_ba_rsp_cnt:",
1042 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1043 accum_ofdm->sent_ba_rsp_cnt,
1044 delta_ofdm->sent_ba_rsp_cnt,
1045 max_ofdm->sent_ba_rsp_cnt);
1046 pos += scnprintf(buf + pos, bufsz - pos,
1047 fmt_table, "dsp_self_kill:",
1048 le32_to_cpu(ofdm->dsp_self_kill),
1049 accum_ofdm->dsp_self_kill,
1050 delta_ofdm->dsp_self_kill,
1051 max_ofdm->dsp_self_kill);
1052 pos += scnprintf(buf + pos, bufsz - pos,
1053 fmt_table, "mh_format_err:",
1054 le32_to_cpu(ofdm->mh_format_err),
1055 accum_ofdm->mh_format_err,
1056 delta_ofdm->mh_format_err,
1057 max_ofdm->mh_format_err);
1058 pos += scnprintf(buf + pos, bufsz - pos,
1059 fmt_table, "re_acq_main_rssi_sum:",
1060 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1061 accum_ofdm->re_acq_main_rssi_sum,
1062 delta_ofdm->re_acq_main_rssi_sum,
1063 max_ofdm->re_acq_main_rssi_sum);
1064
1065 pos += scnprintf(buf + pos, bufsz - pos,
1066 fmt_header, "Statistics_Rx - CCK:");
1067 pos += scnprintf(buf + pos, bufsz - pos,
1068 fmt_table, "ina_cnt:",
1069 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1070 delta_cck->ina_cnt, max_cck->ina_cnt);
1071 pos += scnprintf(buf + pos, bufsz - pos,
1072 fmt_table, "fina_cnt:",
1073 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1074 delta_cck->fina_cnt, max_cck->fina_cnt);
1075 pos += scnprintf(buf + pos, bufsz - pos,
1076 fmt_table, "plcp_err:",
1077 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1078 delta_cck->plcp_err, max_cck->plcp_err);
1079 pos += scnprintf(buf + pos, bufsz - pos,
1080 fmt_table, "crc32_err:",
1081 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1082 delta_cck->crc32_err, max_cck->crc32_err);
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 fmt_table, "overrun_err:",
1085 le32_to_cpu(cck->overrun_err),
1086 accum_cck->overrun_err, delta_cck->overrun_err,
1087 max_cck->overrun_err);
1088 pos += scnprintf(buf + pos, bufsz - pos,
1089 fmt_table, "early_overrun_err:",
1090 le32_to_cpu(cck->early_overrun_err),
1091 accum_cck->early_overrun_err,
1092 delta_cck->early_overrun_err,
1093 max_cck->early_overrun_err);
1094 pos += scnprintf(buf + pos, bufsz - pos,
1095 fmt_table, "crc32_good:",
1096 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1097 delta_cck->crc32_good, max_cck->crc32_good);
1098 pos += scnprintf(buf + pos, bufsz - pos,
1099 fmt_table, "false_alarm_cnt:",
1100 le32_to_cpu(cck->false_alarm_cnt),
1101 accum_cck->false_alarm_cnt,
1102 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1103 pos += scnprintf(buf + pos, bufsz - pos,
1104 fmt_table, "fina_sync_err_cnt:",
1105 le32_to_cpu(cck->fina_sync_err_cnt),
1106 accum_cck->fina_sync_err_cnt,
1107 delta_cck->fina_sync_err_cnt,
1108 max_cck->fina_sync_err_cnt);
1109 pos += scnprintf(buf + pos, bufsz - pos,
1110 fmt_table, "sfd_timeout:",
1111 le32_to_cpu(cck->sfd_timeout),
1112 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1113 max_cck->sfd_timeout);
1114 pos += scnprintf(buf + pos, bufsz - pos,
1115 fmt_table, "fina_timeout:",
1116 le32_to_cpu(cck->fina_timeout),
1117 accum_cck->fina_timeout, delta_cck->fina_timeout,
1118 max_cck->fina_timeout);
1119 pos += scnprintf(buf + pos, bufsz - pos,
1120 fmt_table, "unresponded_rts:",
1121 le32_to_cpu(cck->unresponded_rts),
1122 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1123 max_cck->unresponded_rts);
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 fmt_table, "rxe_frame_lmt_ovrun:",
1126 le32_to_cpu(cck->rxe_frame_limit_overrun),
1127 accum_cck->rxe_frame_limit_overrun,
1128 delta_cck->rxe_frame_limit_overrun,
1129 max_cck->rxe_frame_limit_overrun);
1130 pos += scnprintf(buf + pos, bufsz - pos,
1131 fmt_table, "sent_ack_cnt:",
1132 le32_to_cpu(cck->sent_ack_cnt),
1133 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1134 max_cck->sent_ack_cnt);
1135 pos += scnprintf(buf + pos, bufsz - pos,
1136 fmt_table, "sent_cts_cnt:",
1137 le32_to_cpu(cck->sent_cts_cnt),
1138 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1139 max_cck->sent_cts_cnt);
1140 pos += scnprintf(buf + pos, bufsz - pos,
1141 fmt_table, "sent_ba_rsp_cnt:",
1142 le32_to_cpu(cck->sent_ba_rsp_cnt),
1143 accum_cck->sent_ba_rsp_cnt,
1144 delta_cck->sent_ba_rsp_cnt,
1145 max_cck->sent_ba_rsp_cnt);
1146 pos += scnprintf(buf + pos, bufsz - pos,
1147 fmt_table, "dsp_self_kill:",
1148 le32_to_cpu(cck->dsp_self_kill),
1149 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1150 max_cck->dsp_self_kill);
1151 pos += scnprintf(buf + pos, bufsz - pos,
1152 fmt_table, "mh_format_err:",
1153 le32_to_cpu(cck->mh_format_err),
1154 accum_cck->mh_format_err, delta_cck->mh_format_err,
1155 max_cck->mh_format_err);
1156 pos += scnprintf(buf + pos, bufsz - pos,
1157 fmt_table, "re_acq_main_rssi_sum:",
1158 le32_to_cpu(cck->re_acq_main_rssi_sum),
1159 accum_cck->re_acq_main_rssi_sum,
1160 delta_cck->re_acq_main_rssi_sum,
1161 max_cck->re_acq_main_rssi_sum);
1162
1163 pos += scnprintf(buf + pos, bufsz - pos,
1164 fmt_header, "Statistics_Rx - GENERAL:");
1165 pos += scnprintf(buf + pos, bufsz - pos,
1166 fmt_table, "bogus_cts:",
1167 le32_to_cpu(general->bogus_cts),
1168 accum_general->bogus_cts, delta_general->bogus_cts,
1169 max_general->bogus_cts);
1170 pos += scnprintf(buf + pos, bufsz - pos,
1171 fmt_table, "bogus_ack:",
1172 le32_to_cpu(general->bogus_ack),
1173 accum_general->bogus_ack, delta_general->bogus_ack,
1174 max_general->bogus_ack);
1175 pos += scnprintf(buf + pos, bufsz - pos,
1176 fmt_table, "non_bssid_frames:",
1177 le32_to_cpu(general->non_bssid_frames),
1178 accum_general->non_bssid_frames,
1179 delta_general->non_bssid_frames,
1180 max_general->non_bssid_frames);
1181 pos += scnprintf(buf + pos, bufsz - pos,
1182 fmt_table, "filtered_frames:",
1183 le32_to_cpu(general->filtered_frames),
1184 accum_general->filtered_frames,
1185 delta_general->filtered_frames,
1186 max_general->filtered_frames);
1187 pos += scnprintf(buf + pos, bufsz - pos,
1188 fmt_table, "non_channel_beacons:",
1189 le32_to_cpu(general->non_channel_beacons),
1190 accum_general->non_channel_beacons,
1191 delta_general->non_channel_beacons,
1192 max_general->non_channel_beacons);
1193 pos += scnprintf(buf + pos, bufsz - pos,
1194 fmt_table, "channel_beacons:",
1195 le32_to_cpu(general->channel_beacons),
1196 accum_general->channel_beacons,
1197 delta_general->channel_beacons,
1198 max_general->channel_beacons);
1199 pos += scnprintf(buf + pos, bufsz - pos,
1200 fmt_table, "num_missed_bcon:",
1201 le32_to_cpu(general->num_missed_bcon),
1202 accum_general->num_missed_bcon,
1203 delta_general->num_missed_bcon,
1204 max_general->num_missed_bcon);
1205 pos += scnprintf(buf + pos, bufsz - pos,
1206 fmt_table, "adc_rx_saturation_time:",
1207 le32_to_cpu(general->adc_rx_saturation_time),
1208 accum_general->adc_rx_saturation_time,
1209 delta_general->adc_rx_saturation_time,
1210 max_general->adc_rx_saturation_time);
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 fmt_table, "ina_detect_search_tm:",
1213 le32_to_cpu(general->ina_detection_search_time),
1214 accum_general->ina_detection_search_time,
1215 delta_general->ina_detection_search_time,
1216 max_general->ina_detection_search_time);
1217 pos += scnprintf(buf + pos, bufsz - pos,
1218 fmt_table, "beacon_silence_rssi_a:",
1219 le32_to_cpu(general->beacon_silence_rssi_a),
1220 accum_general->beacon_silence_rssi_a,
1221 delta_general->beacon_silence_rssi_a,
1222 max_general->beacon_silence_rssi_a);
1223 pos += scnprintf(buf + pos, bufsz - pos,
1224 fmt_table, "beacon_silence_rssi_b:",
1225 le32_to_cpu(general->beacon_silence_rssi_b),
1226 accum_general->beacon_silence_rssi_b,
1227 delta_general->beacon_silence_rssi_b,
1228 max_general->beacon_silence_rssi_b);
1229 pos += scnprintf(buf + pos, bufsz - pos,
1230 fmt_table, "beacon_silence_rssi_c:",
1231 le32_to_cpu(general->beacon_silence_rssi_c),
1232 accum_general->beacon_silence_rssi_c,
1233 delta_general->beacon_silence_rssi_c,
1234 max_general->beacon_silence_rssi_c);
1235 pos += scnprintf(buf + pos, bufsz - pos,
1236 fmt_table, "interference_data_flag:",
1237 le32_to_cpu(general->interference_data_flag),
1238 accum_general->interference_data_flag,
1239 delta_general->interference_data_flag,
1240 max_general->interference_data_flag);
1241 pos += scnprintf(buf + pos, bufsz - pos,
1242 fmt_table, "channel_load:",
1243 le32_to_cpu(general->channel_load),
1244 accum_general->channel_load,
1245 delta_general->channel_load,
1246 max_general->channel_load);
1247 pos += scnprintf(buf + pos, bufsz - pos,
1248 fmt_table, "dsp_false_alarms:",
1249 le32_to_cpu(general->dsp_false_alarms),
1250 accum_general->dsp_false_alarms,
1251 delta_general->dsp_false_alarms,
1252 max_general->dsp_false_alarms);
1253 pos += scnprintf(buf + pos, bufsz - pos,
1254 fmt_table, "beacon_rssi_a:",
1255 le32_to_cpu(general->beacon_rssi_a),
1256 accum_general->beacon_rssi_a,
1257 delta_general->beacon_rssi_a,
1258 max_general->beacon_rssi_a);
1259 pos += scnprintf(buf + pos, bufsz - pos,
1260 fmt_table, "beacon_rssi_b:",
1261 le32_to_cpu(general->beacon_rssi_b),
1262 accum_general->beacon_rssi_b,
1263 delta_general->beacon_rssi_b,
1264 max_general->beacon_rssi_b);
1265 pos += scnprintf(buf + pos, bufsz - pos,
1266 fmt_table, "beacon_rssi_c:",
1267 le32_to_cpu(general->beacon_rssi_c),
1268 accum_general->beacon_rssi_c,
1269 delta_general->beacon_rssi_c,
1270 max_general->beacon_rssi_c);
1271 pos += scnprintf(buf + pos, bufsz - pos,
1272 fmt_table, "beacon_energy_a:",
1273 le32_to_cpu(general->beacon_energy_a),
1274 accum_general->beacon_energy_a,
1275 delta_general->beacon_energy_a,
1276 max_general->beacon_energy_a);
1277 pos += scnprintf(buf + pos, bufsz - pos,
1278 fmt_table, "beacon_energy_b:",
1279 le32_to_cpu(general->beacon_energy_b),
1280 accum_general->beacon_energy_b,
1281 delta_general->beacon_energy_b,
1282 max_general->beacon_energy_b);
1283 pos += scnprintf(buf + pos, bufsz - pos,
1284 fmt_table, "beacon_energy_c:",
1285 le32_to_cpu(general->beacon_energy_c),
1286 accum_general->beacon_energy_c,
1287 delta_general->beacon_energy_c,
1288 max_general->beacon_energy_c);
1289
1290 pos += scnprintf(buf + pos, bufsz - pos,
1291 fmt_header, "Statistics_Rx - OFDM_HT:");
1292 pos += scnprintf(buf + pos, bufsz - pos,
1293 fmt_table, "plcp_err:",
1294 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1295 delta_ht->plcp_err, max_ht->plcp_err);
1296 pos += scnprintf(buf + pos, bufsz - pos,
1297 fmt_table, "overrun_err:",
1298 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1299 delta_ht->overrun_err, max_ht->overrun_err);
1300 pos += scnprintf(buf + pos, bufsz - pos,
1301 fmt_table, "early_overrun_err:",
1302 le32_to_cpu(ht->early_overrun_err),
1303 accum_ht->early_overrun_err,
1304 delta_ht->early_overrun_err,
1305 max_ht->early_overrun_err);
1306 pos += scnprintf(buf + pos, bufsz - pos,
1307 fmt_table, "crc32_good:",
1308 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1309 delta_ht->crc32_good, max_ht->crc32_good);
1310 pos += scnprintf(buf + pos, bufsz - pos,
1311 fmt_table, "crc32_err:",
1312 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1313 delta_ht->crc32_err, max_ht->crc32_err);
1314 pos += scnprintf(buf + pos, bufsz - pos,
1315 fmt_table, "mh_format_err:",
1316 le32_to_cpu(ht->mh_format_err),
1317 accum_ht->mh_format_err,
1318 delta_ht->mh_format_err, max_ht->mh_format_err);
1319 pos += scnprintf(buf + pos, bufsz - pos,
1320 fmt_table, "agg_crc32_good:",
1321 le32_to_cpu(ht->agg_crc32_good),
1322 accum_ht->agg_crc32_good,
1323 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1324 pos += scnprintf(buf + pos, bufsz - pos,
1325 fmt_table, "agg_mpdu_cnt:",
1326 le32_to_cpu(ht->agg_mpdu_cnt),
1327 accum_ht->agg_mpdu_cnt,
1328 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1329 pos += scnprintf(buf + pos, bufsz - pos,
1330 fmt_table, "agg_cnt:",
1331 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1332 delta_ht->agg_cnt, max_ht->agg_cnt);
1333 pos += scnprintf(buf + pos, bufsz - pos,
1334 fmt_table, "unsupport_mcs:",
1335 le32_to_cpu(ht->unsupport_mcs),
1336 accum_ht->unsupport_mcs,
1337 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1338
1339 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1340 kfree(buf);
1341 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001342}
1343
1344static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1345 char __user *user_buf,
1346 size_t count, loff_t *ppos)
1347{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001348 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001349 int pos = 0;
1350 char *buf;
1351 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1352 ssize_t ret;
1353 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1354
1355 if (!iwl_is_alive(priv))
1356 return -EAGAIN;
1357
1358 buf = kzalloc(bufsz, GFP_KERNEL);
1359 if (!buf) {
1360 IWL_ERR(priv, "Can not allocate Buffer\n");
1361 return -ENOMEM;
1362 }
1363
1364 /* the statistic information display here is based on
1365 * the last statistics notification from uCode
1366 * might not reflect the current uCode activity
1367 */
1368 tx = &priv->statistics.tx;
1369 accum_tx = &priv->accum_stats.tx;
1370 delta_tx = &priv->delta_stats.tx;
1371 max_tx = &priv->max_delta_stats.tx;
1372
1373 pos += iwl_statistics_flag(priv, buf, bufsz);
1374 pos += scnprintf(buf + pos, bufsz - pos,
1375 fmt_header, "Statistics_Tx:");
1376 pos += scnprintf(buf + pos, bufsz - pos,
1377 fmt_table, "preamble:",
1378 le32_to_cpu(tx->preamble_cnt),
1379 accum_tx->preamble_cnt,
1380 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1381 pos += scnprintf(buf + pos, bufsz - pos,
1382 fmt_table, "rx_detected_cnt:",
1383 le32_to_cpu(tx->rx_detected_cnt),
1384 accum_tx->rx_detected_cnt,
1385 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1386 pos += scnprintf(buf + pos, bufsz - pos,
1387 fmt_table, "bt_prio_defer_cnt:",
1388 le32_to_cpu(tx->bt_prio_defer_cnt),
1389 accum_tx->bt_prio_defer_cnt,
1390 delta_tx->bt_prio_defer_cnt,
1391 max_tx->bt_prio_defer_cnt);
1392 pos += scnprintf(buf + pos, bufsz - pos,
1393 fmt_table, "bt_prio_kill_cnt:",
1394 le32_to_cpu(tx->bt_prio_kill_cnt),
1395 accum_tx->bt_prio_kill_cnt,
1396 delta_tx->bt_prio_kill_cnt,
1397 max_tx->bt_prio_kill_cnt);
1398 pos += scnprintf(buf + pos, bufsz - pos,
1399 fmt_table, "few_bytes_cnt:",
1400 le32_to_cpu(tx->few_bytes_cnt),
1401 accum_tx->few_bytes_cnt,
1402 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1403 pos += scnprintf(buf + pos, bufsz - pos,
1404 fmt_table, "cts_timeout:",
1405 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1406 delta_tx->cts_timeout, max_tx->cts_timeout);
1407 pos += scnprintf(buf + pos, bufsz - pos,
1408 fmt_table, "ack_timeout:",
1409 le32_to_cpu(tx->ack_timeout),
1410 accum_tx->ack_timeout,
1411 delta_tx->ack_timeout, max_tx->ack_timeout);
1412 pos += scnprintf(buf + pos, bufsz - pos,
1413 fmt_table, "expected_ack_cnt:",
1414 le32_to_cpu(tx->expected_ack_cnt),
1415 accum_tx->expected_ack_cnt,
1416 delta_tx->expected_ack_cnt,
1417 max_tx->expected_ack_cnt);
1418 pos += scnprintf(buf + pos, bufsz - pos,
1419 fmt_table, "actual_ack_cnt:",
1420 le32_to_cpu(tx->actual_ack_cnt),
1421 accum_tx->actual_ack_cnt,
1422 delta_tx->actual_ack_cnt,
1423 max_tx->actual_ack_cnt);
1424 pos += scnprintf(buf + pos, bufsz - pos,
1425 fmt_table, "dump_msdu_cnt:",
1426 le32_to_cpu(tx->dump_msdu_cnt),
1427 accum_tx->dump_msdu_cnt,
1428 delta_tx->dump_msdu_cnt,
1429 max_tx->dump_msdu_cnt);
1430 pos += scnprintf(buf + pos, bufsz - pos,
1431 fmt_table, "abort_nxt_frame_mismatch:",
1432 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1433 accum_tx->burst_abort_next_frame_mismatch_cnt,
1434 delta_tx->burst_abort_next_frame_mismatch_cnt,
1435 max_tx->burst_abort_next_frame_mismatch_cnt);
1436 pos += scnprintf(buf + pos, bufsz - pos,
1437 fmt_table, "abort_missing_nxt_frame:",
1438 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1439 accum_tx->burst_abort_missing_next_frame_cnt,
1440 delta_tx->burst_abort_missing_next_frame_cnt,
1441 max_tx->burst_abort_missing_next_frame_cnt);
1442 pos += scnprintf(buf + pos, bufsz - pos,
1443 fmt_table, "cts_timeout_collision:",
1444 le32_to_cpu(tx->cts_timeout_collision),
1445 accum_tx->cts_timeout_collision,
1446 delta_tx->cts_timeout_collision,
1447 max_tx->cts_timeout_collision);
1448 pos += scnprintf(buf + pos, bufsz - pos,
1449 fmt_table, "ack_ba_timeout_collision:",
1450 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1451 accum_tx->ack_or_ba_timeout_collision,
1452 delta_tx->ack_or_ba_timeout_collision,
1453 max_tx->ack_or_ba_timeout_collision);
1454 pos += scnprintf(buf + pos, bufsz - pos,
1455 fmt_table, "agg ba_timeout:",
1456 le32_to_cpu(tx->agg.ba_timeout),
1457 accum_tx->agg.ba_timeout,
1458 delta_tx->agg.ba_timeout,
1459 max_tx->agg.ba_timeout);
1460 pos += scnprintf(buf + pos, bufsz - pos,
1461 fmt_table, "agg ba_resched_frames:",
1462 le32_to_cpu(tx->agg.ba_reschedule_frames),
1463 accum_tx->agg.ba_reschedule_frames,
1464 delta_tx->agg.ba_reschedule_frames,
1465 max_tx->agg.ba_reschedule_frames);
1466 pos += scnprintf(buf + pos, bufsz - pos,
1467 fmt_table, "agg scd_query_agg_frame:",
1468 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1469 accum_tx->agg.scd_query_agg_frame_cnt,
1470 delta_tx->agg.scd_query_agg_frame_cnt,
1471 max_tx->agg.scd_query_agg_frame_cnt);
1472 pos += scnprintf(buf + pos, bufsz - pos,
1473 fmt_table, "agg scd_query_no_agg:",
1474 le32_to_cpu(tx->agg.scd_query_no_agg),
1475 accum_tx->agg.scd_query_no_agg,
1476 delta_tx->agg.scd_query_no_agg,
1477 max_tx->agg.scd_query_no_agg);
1478 pos += scnprintf(buf + pos, bufsz - pos,
1479 fmt_table, "agg scd_query_agg:",
1480 le32_to_cpu(tx->agg.scd_query_agg),
1481 accum_tx->agg.scd_query_agg,
1482 delta_tx->agg.scd_query_agg,
1483 max_tx->agg.scd_query_agg);
1484 pos += scnprintf(buf + pos, bufsz - pos,
1485 fmt_table, "agg scd_query_mismatch:",
1486 le32_to_cpu(tx->agg.scd_query_mismatch),
1487 accum_tx->agg.scd_query_mismatch,
1488 delta_tx->agg.scd_query_mismatch,
1489 max_tx->agg.scd_query_mismatch);
1490 pos += scnprintf(buf + pos, bufsz - pos,
1491 fmt_table, "agg frame_not_ready:",
1492 le32_to_cpu(tx->agg.frame_not_ready),
1493 accum_tx->agg.frame_not_ready,
1494 delta_tx->agg.frame_not_ready,
1495 max_tx->agg.frame_not_ready);
1496 pos += scnprintf(buf + pos, bufsz - pos,
1497 fmt_table, "agg underrun:",
1498 le32_to_cpu(tx->agg.underrun),
1499 accum_tx->agg.underrun,
1500 delta_tx->agg.underrun, max_tx->agg.underrun);
1501 pos += scnprintf(buf + pos, bufsz - pos,
1502 fmt_table, "agg bt_prio_kill:",
1503 le32_to_cpu(tx->agg.bt_prio_kill),
1504 accum_tx->agg.bt_prio_kill,
1505 delta_tx->agg.bt_prio_kill,
1506 max_tx->agg.bt_prio_kill);
1507 pos += scnprintf(buf + pos, bufsz - pos,
1508 fmt_table, "agg rx_ba_rsp_cnt:",
1509 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1510 accum_tx->agg.rx_ba_rsp_cnt,
1511 delta_tx->agg.rx_ba_rsp_cnt,
1512 max_tx->agg.rx_ba_rsp_cnt);
1513
1514 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1515 pos += scnprintf(buf + pos, bufsz - pos,
1516 "tx power: (1/2 dB step)\n");
1517 if ((priv->cfg->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
1518 pos += scnprintf(buf + pos, bufsz - pos,
1519 fmt_hex, "antenna A:",
1520 tx->tx_power.ant_a);
1521 if ((priv->cfg->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
1522 pos += scnprintf(buf + pos, bufsz - pos,
1523 fmt_hex, "antenna B:",
1524 tx->tx_power.ant_b);
1525 if ((priv->cfg->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
1526 pos += scnprintf(buf + pos, bufsz - pos,
1527 fmt_hex, "antenna C:",
1528 tx->tx_power.ant_c);
1529 }
1530 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1531 kfree(buf);
1532 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001533}
1534
1535static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1536 char __user *user_buf,
1537 size_t count, loff_t *ppos)
1538{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001539 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001540 int pos = 0;
1541 char *buf;
1542 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1543 ssize_t ret;
1544 struct statistics_general_common *general, *accum_general;
1545 struct statistics_general_common *delta_general, *max_general;
1546 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1547 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1548
1549 if (!iwl_is_alive(priv))
1550 return -EAGAIN;
1551
1552 buf = kzalloc(bufsz, GFP_KERNEL);
1553 if (!buf) {
1554 IWL_ERR(priv, "Can not allocate Buffer\n");
1555 return -ENOMEM;
1556 }
1557
1558 /* the statistic information display here is based on
1559 * the last statistics notification from uCode
1560 * might not reflect the current uCode activity
1561 */
1562 general = &priv->statistics.common;
1563 dbg = &priv->statistics.common.dbg;
1564 div = &priv->statistics.common.div;
1565 accum_general = &priv->accum_stats.common;
1566 accum_dbg = &priv->accum_stats.common.dbg;
1567 accum_div = &priv->accum_stats.common.div;
1568 delta_general = &priv->delta_stats.common;
1569 max_general = &priv->max_delta_stats.common;
1570 delta_dbg = &priv->delta_stats.common.dbg;
1571 max_dbg = &priv->max_delta_stats.common.dbg;
1572 delta_div = &priv->delta_stats.common.div;
1573 max_div = &priv->max_delta_stats.common.div;
1574
1575 pos += iwl_statistics_flag(priv, buf, bufsz);
1576 pos += scnprintf(buf + pos, bufsz - pos,
1577 fmt_header, "Statistics_General:");
1578 pos += scnprintf(buf + pos, bufsz - pos,
1579 fmt_value, "temperature:",
1580 le32_to_cpu(general->temperature));
1581 pos += scnprintf(buf + pos, bufsz - pos,
1582 fmt_value, "temperature_m:",
1583 le32_to_cpu(general->temperature_m));
1584 pos += scnprintf(buf + pos, bufsz - pos,
1585 fmt_value, "ttl_timestamp:",
1586 le32_to_cpu(general->ttl_timestamp));
1587 pos += scnprintf(buf + pos, bufsz - pos,
1588 fmt_table, "burst_check:",
1589 le32_to_cpu(dbg->burst_check),
1590 accum_dbg->burst_check,
1591 delta_dbg->burst_check, max_dbg->burst_check);
1592 pos += scnprintf(buf + pos, bufsz - pos,
1593 fmt_table, "burst_count:",
1594 le32_to_cpu(dbg->burst_count),
1595 accum_dbg->burst_count,
1596 delta_dbg->burst_count, max_dbg->burst_count);
1597 pos += scnprintf(buf + pos, bufsz - pos,
1598 fmt_table, "wait_for_silence_timeout_count:",
1599 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1600 accum_dbg->wait_for_silence_timeout_cnt,
1601 delta_dbg->wait_for_silence_timeout_cnt,
1602 max_dbg->wait_for_silence_timeout_cnt);
1603 pos += scnprintf(buf + pos, bufsz - pos,
1604 fmt_table, "sleep_time:",
1605 le32_to_cpu(general->sleep_time),
1606 accum_general->sleep_time,
1607 delta_general->sleep_time, max_general->sleep_time);
1608 pos += scnprintf(buf + pos, bufsz - pos,
1609 fmt_table, "slots_out:",
1610 le32_to_cpu(general->slots_out),
1611 accum_general->slots_out,
1612 delta_general->slots_out, max_general->slots_out);
1613 pos += scnprintf(buf + pos, bufsz - pos,
1614 fmt_table, "slots_idle:",
1615 le32_to_cpu(general->slots_idle),
1616 accum_general->slots_idle,
1617 delta_general->slots_idle, max_general->slots_idle);
1618 pos += scnprintf(buf + pos, bufsz - pos,
1619 fmt_table, "tx_on_a:",
1620 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1621 delta_div->tx_on_a, max_div->tx_on_a);
1622 pos += scnprintf(buf + pos, bufsz - pos,
1623 fmt_table, "tx_on_b:",
1624 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1625 delta_div->tx_on_b, max_div->tx_on_b);
1626 pos += scnprintf(buf + pos, bufsz - pos,
1627 fmt_table, "exec_time:",
1628 le32_to_cpu(div->exec_time), accum_div->exec_time,
1629 delta_div->exec_time, max_div->exec_time);
1630 pos += scnprintf(buf + pos, bufsz - pos,
1631 fmt_table, "probe_time:",
1632 le32_to_cpu(div->probe_time), accum_div->probe_time,
1633 delta_div->probe_time, max_div->probe_time);
1634 pos += scnprintf(buf + pos, bufsz - pos,
1635 fmt_table, "rx_enable_counter:",
1636 le32_to_cpu(general->rx_enable_counter),
1637 accum_general->rx_enable_counter,
1638 delta_general->rx_enable_counter,
1639 max_general->rx_enable_counter);
1640 pos += scnprintf(buf + pos, bufsz - pos,
1641 fmt_table, "num_of_sos_states:",
1642 le32_to_cpu(general->num_of_sos_states),
1643 accum_general->num_of_sos_states,
1644 delta_general->num_of_sos_states,
1645 max_general->num_of_sos_states);
1646 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1647 kfree(buf);
1648 return ret;
1649}
1650
1651static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1652 char __user *user_buf,
1653 size_t count, loff_t *ppos)
1654{
1655 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1656 int pos = 0;
1657 char *buf;
1658 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1659 ssize_t ret;
1660 struct statistics_bt_activity *bt, *accum_bt;
1661
1662 if (!iwl_is_alive(priv))
1663 return -EAGAIN;
1664
1665 if (!priv->bt_enable_flag)
1666 return -EINVAL;
1667
1668 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001669 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001670 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001671 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001672
1673 if (ret) {
1674 IWL_ERR(priv,
1675 "Error sending statistics request: %zd\n", ret);
1676 return -EAGAIN;
1677 }
1678 buf = kzalloc(bufsz, GFP_KERNEL);
1679 if (!buf) {
1680 IWL_ERR(priv, "Can not allocate Buffer\n");
1681 return -ENOMEM;
1682 }
1683
1684 /*
1685 * the statistic information display here is based on
1686 * the last statistics notification from uCode
1687 * might not reflect the current uCode activity
1688 */
1689 bt = &priv->statistics.bt_activity;
1690 accum_bt = &priv->accum_stats.bt_activity;
1691
1692 pos += iwl_statistics_flag(priv, buf, bufsz);
1693 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1694 pos += scnprintf(buf + pos, bufsz - pos,
1695 "\t\t\tcurrent\t\t\taccumulative\n");
1696 pos += scnprintf(buf + pos, bufsz - pos,
1697 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1698 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1699 accum_bt->hi_priority_tx_req_cnt);
1700 pos += scnprintf(buf + pos, bufsz - pos,
1701 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1702 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1703 accum_bt->hi_priority_tx_denied_cnt);
1704 pos += scnprintf(buf + pos, bufsz - pos,
1705 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1706 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1707 accum_bt->lo_priority_tx_req_cnt);
1708 pos += scnprintf(buf + pos, bufsz - pos,
1709 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1710 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1711 accum_bt->lo_priority_tx_denied_cnt);
1712 pos += scnprintf(buf + pos, bufsz - pos,
1713 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1714 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1715 accum_bt->hi_priority_rx_req_cnt);
1716 pos += scnprintf(buf + pos, bufsz - pos,
1717 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1718 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1719 accum_bt->hi_priority_rx_denied_cnt);
1720 pos += scnprintf(buf + pos, bufsz - pos,
1721 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1722 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1723 accum_bt->lo_priority_rx_req_cnt);
1724 pos += scnprintf(buf + pos, bufsz - pos,
1725 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1726 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1727 accum_bt->lo_priority_rx_denied_cnt);
1728
1729 pos += scnprintf(buf + pos, bufsz - pos,
1730 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1731 le32_to_cpu(priv->statistics.num_bt_kills),
1732 priv->statistics.accum_num_bt_kills);
1733
1734 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1735 kfree(buf);
1736 return ret;
1737}
1738
1739static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1740 char __user *user_buf,
1741 size_t count, loff_t *ppos)
1742{
1743 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1744 int pos = 0;
1745 char *buf;
1746 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1747 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1748 ssize_t ret;
1749
1750 if (!iwl_is_alive(priv))
1751 return -EAGAIN;
1752
1753 buf = kzalloc(bufsz, GFP_KERNEL);
1754 if (!buf) {
1755 IWL_ERR(priv, "Can not allocate Buffer\n");
1756 return -ENOMEM;
1757 }
1758
1759 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1760 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1761 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001762 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001763 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1764 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001765 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001766 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1767 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001768 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001769 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1770 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001771 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001772 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1773 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001774 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001775 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1776 iwl_get_tx_fail_reason(
1777 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001778 priv->reply_tx_stats.int_crossed_retry);
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_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001781 priv->reply_tx_stats.short_limit);
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_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001784 priv->reply_tx_stats.long_limit);
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_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001787 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001788 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1789 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001790 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001791 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1792 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001793 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001794 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1795 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001796 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001797 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1798 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001799 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001800 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1801 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001802 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001803 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1804 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001805 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001806 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1807 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001808 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001809 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1810 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001811 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001812 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1813 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001814 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001815 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1816 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001817 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001818 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1819 iwl_get_tx_fail_reason(
1820 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001821 priv->reply_tx_stats.insuff_cf_poll);
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_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001824 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001825 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1826 iwl_get_tx_fail_reason(
1827 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001828 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001829 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001830 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001831
1832 pos += scnprintf(buf + pos, bufsz - pos,
1833 "\nStatistics_Agg_TX_Error:\n");
1834
1835 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1836 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001837 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001838 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1839 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001840 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001841 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1842 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001843 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001844 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1845 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001846 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001847 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1848 iwl_get_agg_tx_fail_reason(
1849 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001851 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1852 iwl_get_agg_tx_fail_reason(
1853 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001854 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001855 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1856 iwl_get_agg_tx_fail_reason(
1857 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001858 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001859 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1860 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001861 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001862 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1863 iwl_get_agg_tx_fail_reason(
1864 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001865 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001866 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1867 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001868 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001869 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1870 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001871 priv->reply_agg_tx_stats.dump_tx);
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_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001874 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001875 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001876 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001877
1878 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1879 kfree(buf);
1880 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001881}
1882
Wey-Yi Guy52259352009-08-07 15:41:43 -07001883static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1884 char __user *user_buf,
1885 size_t count, loff_t *ppos) {
1886
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001887 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001888 int pos = 0;
1889 int cnt = 0;
1890 char *buf;
1891 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1892 ssize_t ret;
1893 struct iwl_sensitivity_data *data;
1894
1895 data = &priv->sensitivity_data;
1896 buf = kzalloc(bufsz, GFP_KERNEL);
1897 if (!buf) {
1898 IWL_ERR(priv, "Can not allocate Buffer\n");
1899 return -ENOMEM;
1900 }
1901
1902 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1903 data->auto_corr_ofdm);
1904 pos += scnprintf(buf + pos, bufsz - pos,
1905 "auto_corr_ofdm_mrc:\t\t %u\n",
1906 data->auto_corr_ofdm_mrc);
1907 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1908 data->auto_corr_ofdm_x1);
1909 pos += scnprintf(buf + pos, bufsz - pos,
1910 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1911 data->auto_corr_ofdm_mrc_x1);
1912 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1913 data->auto_corr_cck);
1914 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1915 data->auto_corr_cck_mrc);
1916 pos += scnprintf(buf + pos, bufsz - pos,
1917 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1918 data->last_bad_plcp_cnt_ofdm);
1919 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1920 data->last_fa_cnt_ofdm);
1921 pos += scnprintf(buf + pos, bufsz - pos,
1922 "last_bad_plcp_cnt_cck:\t\t %u\n",
1923 data->last_bad_plcp_cnt_cck);
1924 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1925 data->last_fa_cnt_cck);
1926 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1927 data->nrg_curr_state);
1928 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1929 data->nrg_prev_state);
1930 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1931 for (cnt = 0; cnt < 10; cnt++) {
1932 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1933 data->nrg_value[cnt]);
1934 }
1935 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1936 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1937 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1938 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1939 data->nrg_silence_rssi[cnt]);
1940 }
1941 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1942 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1943 data->nrg_silence_ref);
1944 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1945 data->nrg_energy_idx);
1946 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1947 data->nrg_silence_idx);
1948 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1949 data->nrg_th_cck);
1950 pos += scnprintf(buf + pos, bufsz - pos,
1951 "nrg_auto_corr_silence_diff:\t %u\n",
1952 data->nrg_auto_corr_silence_diff);
1953 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1954 data->num_in_cck_no_fa);
1955 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1956 data->nrg_th_ofdm);
1957
1958 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1959 kfree(buf);
1960 return ret;
1961}
1962
1963
1964static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1965 char __user *user_buf,
1966 size_t count, loff_t *ppos) {
1967
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001968 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001969 int pos = 0;
1970 int cnt = 0;
1971 char *buf;
1972 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1973 ssize_t ret;
1974 struct iwl_chain_noise_data *data;
1975
1976 data = &priv->chain_noise_data;
1977 buf = kzalloc(bufsz, GFP_KERNEL);
1978 if (!buf) {
1979 IWL_ERR(priv, "Can not allocate Buffer\n");
1980 return -ENOMEM;
1981 }
1982
1983 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1984 data->active_chains);
1985 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1986 data->chain_noise_a);
1987 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1988 data->chain_noise_b);
1989 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1990 data->chain_noise_c);
1991 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1992 data->chain_signal_a);
1993 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1994 data->chain_signal_b);
1995 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1996 data->chain_signal_c);
1997 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1998 data->beacon_count);
1999
2000 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2001 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2002 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2003 data->disconn_array[cnt]);
2004 }
2005 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2006 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2007 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2008 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2009 data->delta_gain_code[cnt]);
2010 }
2011 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2012 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2013 data->radio_write);
2014 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2015 data->state);
2016
2017 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2018 kfree(buf);
2019 return ret;
2020}
2021
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002022static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2023 char __user *user_buf,
2024 size_t count, loff_t *ppos)
2025{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002026 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002027 char buf[60];
2028 int pos = 0;
2029 const size_t bufsz = sizeof(buf);
2030 u32 pwrsave_status;
2031
2032 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
2033 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2034
2035 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2036 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2037 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2038 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2039 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2040 "error");
2041
2042 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2043}
2044
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002045static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002046 const char __user *user_buf,
2047 size_t count, loff_t *ppos)
2048{
2049 struct iwl_priv *priv = file->private_data;
2050 char buf[8];
2051 int buf_size;
2052 int clear;
2053
2054 memset(buf, 0, sizeof(buf));
2055 buf_size = min(count, sizeof(buf) - 1);
2056 if (copy_from_user(buf, user_buf, buf_size))
2057 return -EFAULT;
2058 if (sscanf(buf, "%d", &clear) != 1)
2059 return -EFAULT;
2060
2061 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002062 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002063 iwl_send_statistics_request(priv, CMD_SYNC, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002064 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002065
2066 return count;
2067}
2068
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08002069static ssize_t iwl_dbgfs_csr_write(struct file *file,
2070 const char __user *user_buf,
2071 size_t count, loff_t *ppos)
2072{
2073 struct iwl_priv *priv = file->private_data;
2074 char buf[8];
2075 int buf_size;
2076 int csr;
2077
2078 memset(buf, 0, sizeof(buf));
2079 buf_size = min(count, sizeof(buf) - 1);
2080 if (copy_from_user(buf, user_buf, buf_size))
2081 return -EFAULT;
2082 if (sscanf(buf, "%d", &csr) != 1)
2083 return -EFAULT;
2084
Wey-Yi Guy3ecccbc2011-03-29 17:53:15 -07002085 iwl_dump_csr(priv);
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08002086
2087 return count;
2088}
2089
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002090static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2091 char __user *user_buf,
2092 size_t count, loff_t *ppos) {
2093
Joe Perches57674302010-07-12 13:50:06 -07002094 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002095 int pos = 0;
2096 char buf[128];
2097 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002098
2099 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2100 priv->event_log.ucode_trace ? "On" : "Off");
2101 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2102 priv->event_log.non_wraps_count);
2103 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2104 priv->event_log.wraps_once_count);
2105 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2106 priv->event_log.wraps_more_count);
2107
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002108 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002109}
2110
2111static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2112 const char __user *user_buf,
2113 size_t count, loff_t *ppos)
2114{
2115 struct iwl_priv *priv = file->private_data;
2116 char buf[8];
2117 int buf_size;
2118 int trace;
2119
2120 memset(buf, 0, sizeof(buf));
2121 buf_size = min(count, sizeof(buf) - 1);
2122 if (copy_from_user(buf, user_buf, buf_size))
2123 return -EFAULT;
2124 if (sscanf(buf, "%d", &trace) != 1)
2125 return -EFAULT;
2126
2127 if (trace) {
2128 priv->event_log.ucode_trace = true;
2129 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
2130 mod_timer(&priv->ucode_trace,
2131 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
2132 } else {
2133 priv->event_log.ucode_trace = false;
2134 del_timer_sync(&priv->ucode_trace);
2135 }
2136
2137 return count;
2138}
2139
Johannes Berg60987202010-02-18 00:36:07 -08002140static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2141 char __user *user_buf,
2142 size_t count, loff_t *ppos) {
2143
Joe Perches57674302010-07-12 13:50:06 -07002144 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002145 int len = 0;
2146 char buf[20];
2147
Johannes Berg246ed352010-08-23 10:46:32 +02002148 len = sprintf(buf, "0x%04X\n",
2149 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002150 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2151}
2152
2153static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2154 char __user *user_buf,
2155 size_t count, loff_t *ppos) {
2156
Joe Perches57674302010-07-12 13:50:06 -07002157 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002158 int len = 0;
2159 char buf[20];
2160
2161 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002162 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002163 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2164}
2165
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08002166static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
2167 char __user *user_buf,
2168 size_t count, loff_t *ppos)
2169{
Joe Perches57674302010-07-12 13:50:06 -07002170 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08002171 char *buf;
2172 int pos = 0;
2173 ssize_t ret = -EFAULT;
2174
Wey-Yi Guy3ecccbc2011-03-29 17:53:15 -07002175 ret = pos = iwl_dump_fh(priv, &buf, true);
2176 if (buf) {
2177 ret = simple_read_from_buffer(user_buf,
2178 count, ppos, buf, pos);
2179 kfree(buf);
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08002180 }
2181
2182 return ret;
2183}
2184
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002185static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2186 char __user *user_buf,
2187 size_t count, loff_t *ppos) {
2188
2189 struct iwl_priv *priv = file->private_data;
2190 int pos = 0;
2191 char buf[12];
2192 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002193
2194 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2195 priv->missed_beacon_threshold);
2196
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002197 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002198}
2199
2200static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2201 const char __user *user_buf,
2202 size_t count, loff_t *ppos)
2203{
2204 struct iwl_priv *priv = file->private_data;
2205 char buf[8];
2206 int buf_size;
2207 int missed;
2208
2209 memset(buf, 0, sizeof(buf));
2210 buf_size = min(count, sizeof(buf) - 1);
2211 if (copy_from_user(buf, user_buf, buf_size))
2212 return -EFAULT;
2213 if (sscanf(buf, "%d", &missed) != 1)
2214 return -EINVAL;
2215
2216 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2217 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2218 priv->missed_beacon_threshold =
2219 IWL_MISSED_BEACON_THRESHOLD_DEF;
2220 else
2221 priv->missed_beacon_threshold = missed;
2222
2223 return count;
2224}
2225
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002226static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2227 char __user *user_buf,
2228 size_t count, loff_t *ppos) {
2229
Joe Perches57674302010-07-12 13:50:06 -07002230 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002231 int pos = 0;
2232 char buf[12];
2233 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002234
2235 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002236 priv->cfg->base_params->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002237
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002238 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002239}
2240
2241static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2242 const char __user *user_buf,
2243 size_t count, loff_t *ppos) {
2244
2245 struct iwl_priv *priv = file->private_data;
2246 char buf[8];
2247 int buf_size;
2248 int plcp;
2249
2250 memset(buf, 0, sizeof(buf));
2251 buf_size = min(count, sizeof(buf) - 1);
2252 if (copy_from_user(buf, user_buf, buf_size))
2253 return -EFAULT;
2254 if (sscanf(buf, "%d", &plcp) != 1)
2255 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002256 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002257 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002258 priv->cfg->base_params->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002259 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002260 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002261 priv->cfg->base_params->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002262 return count;
2263}
2264
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002265static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2266 char __user *user_buf,
2267 size_t count, loff_t *ppos) {
2268
2269 struct iwl_priv *priv = file->private_data;
2270 int i, pos = 0;
2271 char buf[300];
2272 const size_t bufsz = sizeof(buf);
2273 struct iwl_force_reset *force_reset;
2274
2275 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2276 force_reset = &priv->force_reset[i];
2277 pos += scnprintf(buf + pos, bufsz - pos,
2278 "Force reset method %d\n", i);
2279 pos += scnprintf(buf + pos, bufsz - pos,
2280 "\tnumber of reset request: %d\n",
2281 force_reset->reset_request_count);
2282 pos += scnprintf(buf + pos, bufsz - pos,
2283 "\tnumber of reset request success: %d\n",
2284 force_reset->reset_success_count);
2285 pos += scnprintf(buf + pos, bufsz - pos,
2286 "\tnumber of reset request reject: %d\n",
2287 force_reset->reset_reject_count);
2288 pos += scnprintf(buf + pos, bufsz - pos,
2289 "\treset duration: %lu\n",
2290 force_reset->reset_duration);
2291 }
2292 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2293}
2294
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002295static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2296 const char __user *user_buf,
2297 size_t count, loff_t *ppos) {
2298
2299 struct iwl_priv *priv = file->private_data;
2300 char buf[8];
2301 int buf_size;
2302 int reset, ret;
2303
2304 memset(buf, 0, sizeof(buf));
2305 buf_size = min(count, sizeof(buf) - 1);
2306 if (copy_from_user(buf, user_buf, buf_size))
2307 return -EFAULT;
2308 if (sscanf(buf, "%d", &reset) != 1)
2309 return -EINVAL;
2310 switch (reset) {
2311 case IWL_RF_RESET:
2312 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002313 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002314 break;
2315 default:
2316 return -EINVAL;
2317 }
2318 return ret ? ret : count;
2319}
2320
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002321static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2322 const char __user *user_buf,
2323 size_t count, loff_t *ppos) {
2324
2325 struct iwl_priv *priv = file->private_data;
2326 char buf[8];
2327 int buf_size;
2328 int flush;
2329
2330 memset(buf, 0, sizeof(buf));
2331 buf_size = min(count, sizeof(buf) - 1);
2332 if (copy_from_user(buf, user_buf, buf_size))
2333 return -EFAULT;
2334 if (sscanf(buf, "%d", &flush) != 1)
2335 return -EINVAL;
2336
2337 if (iwl_is_rfkill(priv))
2338 return -EFAULT;
2339
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002340 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002341
2342 return count;
2343}
2344
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002345static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002346 const char __user *user_buf,
2347 size_t count, loff_t *ppos) {
2348
2349 struct iwl_priv *priv = file->private_data;
2350 char buf[8];
2351 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002352 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002353
2354 memset(buf, 0, sizeof(buf));
2355 buf_size = min(count, sizeof(buf) - 1);
2356 if (copy_from_user(buf, user_buf, buf_size))
2357 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002358 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002359 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002360 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2361 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002362
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002363 priv->cfg->base_params->wd_timeout = timeout;
2364 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002365 return count;
2366}
2367
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002368static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2369 char __user *user_buf,
2370 size_t count, loff_t *ppos) {
2371
2372 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2373 int pos = 0;
2374 char buf[200];
2375 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002376
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002377 if (!priv->bt_enable_flag) {
2378 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002379 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002380 }
2381 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2382 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002383 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2384 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2385 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2386 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002387 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002388 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002389 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2390 priv->bt_ch_announce, priv->kill_ack_mask,
2391 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002392
2393 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2394 switch (priv->bt_traffic_load) {
2395 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2396 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2397 break;
2398 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2399 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2400 break;
2401 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2402 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2403 break;
2404 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2405 default:
2406 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2407 break;
2408 }
2409
Johannes Berg08960de2011-04-05 09:41:53 -07002410 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002411}
2412
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002413static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2414 char __user *user_buf,
2415 size_t count, loff_t *ppos)
2416{
2417 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2418
2419 int pos = 0;
2420 char buf[40];
2421 const size_t bufsz = sizeof(buf);
2422
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002423 if (priv->cfg->ht_params)
2424 pos += scnprintf(buf + pos, bufsz - pos,
2425 "use %s for aggregation\n",
2426 (priv->cfg->ht_params->use_rts_for_aggregation) ?
2427 "rts/cts" : "cts-to-self");
2428 else
2429 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2430
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002431 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2432}
2433
2434static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2435 const char __user *user_buf,
2436 size_t count, loff_t *ppos) {
2437
2438 struct iwl_priv *priv = file->private_data;
2439 char buf[8];
2440 int buf_size;
2441 int rts;
2442
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002443 if (!priv->cfg->ht_params)
2444 return -EINVAL;
2445
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002446 memset(buf, 0, sizeof(buf));
2447 buf_size = min(count, sizeof(buf) - 1);
2448 if (copy_from_user(buf, user_buf, buf_size))
2449 return -EFAULT;
2450 if (sscanf(buf, "%d", &rts) != 1)
2451 return -EINVAL;
2452 if (rts)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002453 priv->cfg->ht_params->use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002454 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002455 priv->cfg->ht_params->use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002456 return count;
2457}
2458
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002459DEBUGFS_READ_FILE_OPS(rx_statistics);
2460DEBUGFS_READ_FILE_OPS(tx_statistics);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002461DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2462DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2463DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002464DEBUGFS_READ_FILE_OPS(sensitivity);
2465DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002466DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002467DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2468DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08002469DEBUGFS_WRITE_FILE_OPS(csr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002470DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08002471DEBUGFS_READ_FILE_OPS(fh_reg);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002472DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002473DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002474DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002475DEBUGFS_READ_FILE_OPS(rxon_flags);
2476DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002477DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002478DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002479DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002480DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002481DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002482DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002483
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002484/*
2485 * Create the debugfs files and directories
2486 *
2487 */
2488int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2489{
Zhu Yi95b1a822008-05-29 16:34:50 +08002490 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002491 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002492
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002493 dir_drv = debugfs_create_dir(name, phyd);
2494 if (!dir_drv)
2495 return -ENOMEM;
2496
2497 priv->debugfs_dir = dir_drv;
2498
2499 dir_data = debugfs_create_dir("data", dir_drv);
2500 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002501 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002502 dir_rf = debugfs_create_dir("rf", dir_drv);
2503 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002504 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002505 dir_debug = debugfs_create_dir("debug", dir_drv);
2506 if (!dir_debug)
2507 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002508
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002509 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2510 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002511 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002512 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
2513 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2514 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2515 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
2516 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
2517 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002518 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2519 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002520 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2521 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
2522 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2523 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002524 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2525 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2526 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
2527 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
2528 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
2529 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002530 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002531 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002532 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2533 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2534 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002535 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002536 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002537
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002538 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2539 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002540 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002541 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002542 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002543 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2544 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002545 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002546 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002547 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002548 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2549 &priv->disable_sens_cal);
2550 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2551 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002552
2553 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2554 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002555 return 0;
2556
2557err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002558 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002559 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002560 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002561}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002562
2563/**
2564 * Remove the debugfs files and directories
2565 *
2566 */
2567void iwl_dbgfs_unregister(struct iwl_priv *priv)
2568{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002569 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002570 return;
2571
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002572 debugfs_remove_recursive(priv->debugfs_dir);
2573 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002574}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002575
2576
Tomas Winkler445c2df2008-05-15 13:54:16 +08002577