blob: 1c235d685ae601ffe926dd245136c604f09657bd [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08005 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Tomas Winkler712b6cf2008-03-12 16:58:52 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h>
35#include <net/mac80211.h>
36
37
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070039#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070040#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070041#include "iwl-io.h"
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -070042#include "iwl-agn.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070043
44/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080045#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
46 if (!debugfs_create_file(#name, mode, parent, priv, \
47 &iwl_dbgfs_##name##_ops)) \
48 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070049} while (0)
50
Johannes Berg4c84a8f2010-01-22 14:22:54 -080051#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
52 struct dentry *__tmp; \
53 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
54 parent, ptr); \
55 if (IS_ERR(__tmp) || !__tmp) \
56 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070057} while (0)
58
Johannes Berg4c84a8f2010-01-22 14:22:54 -080059#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
60 struct dentry *__tmp; \
61 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
62 parent, ptr); \
63 if (IS_ERR(__tmp) || !__tmp) \
64 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080065} while (0)
66
Johannes Bergca934b62011-09-15 11:46:48 -070067#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
68 struct dentry *__tmp; \
69 __tmp = debugfs_create_u32(#name, mode, \
70 parent, ptr); \
71 if (IS_ERR(__tmp) || !__tmp) \
72 goto err; \
73} while (0)
74
Tomas Winkler712b6cf2008-03-12 16:58:52 -070075/* file operation */
76#define DEBUGFS_READ_FUNC(name) \
77static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
78 char __user *user_buf, \
79 size_t count, loff_t *ppos);
80
81#define DEBUGFS_WRITE_FUNC(name) \
82static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
83 const char __user *user_buf, \
84 size_t count, loff_t *ppos);
85
86
87static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
88{
89 file->private_data = inode->i_private;
90 return 0;
91}
92
93#define DEBUGFS_READ_FILE_OPS(name) \
94 DEBUGFS_READ_FUNC(name); \
95static const struct file_operations iwl_dbgfs_##name##_ops = { \
96 .read = iwl_dbgfs_##name##_read, \
97 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020098 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070099};
100
Ester Kummer189a2b52008-05-15 13:54:18 +0800101#define DEBUGFS_WRITE_FILE_OPS(name) \
102 DEBUGFS_WRITE_FUNC(name); \
103static const struct file_operations iwl_dbgfs_##name##_ops = { \
104 .write = iwl_dbgfs_##name##_write, \
105 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200106 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800107};
108
109
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700110#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
111 DEBUGFS_READ_FUNC(name); \
112 DEBUGFS_WRITE_FUNC(name); \
113static const struct file_operations iwl_dbgfs_##name##_ops = { \
114 .write = iwl_dbgfs_##name##_write, \
115 .read = iwl_dbgfs_##name##_read, \
116 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200117 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700118};
119
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
121 char __user *user_buf,
122 size_t count, loff_t *ppos) {
123
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700124 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700125 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700126 int pos = 0;
127
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700128 int cnt;
129 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800130 const size_t bufsz = 100 +
131 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700132 buf = kzalloc(bufsz, GFP_KERNEL);
133 if (!buf)
134 return -ENOMEM;
135 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
136 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
137 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800138 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700139 get_mgmt_string(cnt),
140 priv->tx_stats.mgmt[cnt]);
141 }
142 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
143 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
144 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800145 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700146 get_ctrl_string(cnt),
147 priv->tx_stats.ctrl[cnt]);
148 }
149 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
150 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
151 priv->tx_stats.data_cnt);
152 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
153 priv->tx_stats.data_bytes);
154 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
155 kfree(buf);
156 return ret;
157}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700158
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800159static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700160 const char __user *user_buf,
161 size_t count, loff_t *ppos)
162{
163 struct iwl_priv *priv = file->private_data;
164 u32 clear_flag;
165 char buf[8];
166 int buf_size;
167
168 memset(buf, 0, sizeof(buf));
169 buf_size = min(count, sizeof(buf) - 1);
170 if (copy_from_user(buf, user_buf, buf_size))
171 return -EFAULT;
172 if (sscanf(buf, "%x", &clear_flag) != 1)
173 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800174 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700175
176 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700177}
178
179static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
180 char __user *user_buf,
181 size_t count, loff_t *ppos) {
182
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700183 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700184 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700185 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700186 int cnt;
187 ssize_t ret;
188 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800189 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700190 buf = kzalloc(bufsz, GFP_KERNEL);
191 if (!buf)
192 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700193
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700194 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
195 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
196 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800197 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700198 get_mgmt_string(cnt),
199 priv->rx_stats.mgmt[cnt]);
200 }
201 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
202 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
203 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800204 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700205 get_ctrl_string(cnt),
206 priv->rx_stats.ctrl[cnt]);
207 }
208 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
209 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
210 priv->rx_stats.data_cnt);
211 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
212 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700213
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700214 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
215 kfree(buf);
216 return ret;
217}
218
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700219static ssize_t iwl_dbgfs_sram_read(struct file *file,
220 char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
Jay Sternberg24834d22011-01-11 15:41:00 -0800223 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800224 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700225 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800226 int i = 0;
227 bool device_format = false;
228 int offset = 0;
229 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800231 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700232 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800233 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700234
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800235 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800236 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
237 priv->dbgfs_sram_offset = 0x800000;
Johannes Berg0692fe42012-03-06 13:30:37 -0800238 if (priv->shrd->ucode_type == IWL_UCODE_INIT)
239 priv->dbgfs_sram_len = priv->fw->ucode_init.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800240 else
Johannes Berg0692fe42012-03-06 13:30:37 -0800241 priv->dbgfs_sram_len = priv->fw->ucode_rt.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800242 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800243 len = priv->dbgfs_sram_len;
244
245 if (len == -4) {
246 device_format = true;
247 len = 4;
248 }
249
250 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800251 buf = kmalloc(bufsz, GFP_KERNEL);
252 if (!buf)
253 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800254
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800255 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800256 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800257 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800258 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800259
260 /* adjust sram address since reads are only on even u32 boundaries */
261 offset = priv->dbgfs_sram_offset & 0x3;
262 sram = priv->dbgfs_sram_offset & ~0x3;
263
264 /* read the first u32 from sram */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200265 val = iwl_read_targ_mem(trans(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800266
267 for (; len; len--) {
268 /* put the address at the start of every line */
269 if (i == 0)
270 pos += scnprintf(buf + pos, bufsz - pos,
271 "%08X: ", sram + offset);
272
273 if (device_format)
274 pos += scnprintf(buf + pos, bufsz - pos,
275 "%02x", (val >> (8 * (3 - offset))) & 0xff);
276 else
277 pos += scnprintf(buf + pos, bufsz - pos,
278 "%02x ", (val >> (8 * offset)) & 0xff);
279
280 /* if all bytes processed, read the next u32 from sram */
281 if (++offset == 4) {
282 sram += 4;
283 offset = 0;
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200284 val = iwl_read_targ_mem(trans(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700285 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800286
287 /* put in extra spaces and split lines for human readability */
288 if (++i == 16) {
289 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800290 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800291 } else if (!(i & 7)) {
292 pos += scnprintf(buf + pos, bufsz - pos, " ");
293 } else if (!(i & 3)) {
294 pos += scnprintf(buf + pos, bufsz - pos, " ");
295 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700296 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800297 if (i)
298 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700299
300 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800301 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700302 return ret;
303}
304
305static ssize_t iwl_dbgfs_sram_write(struct file *file,
306 const char __user *user_buf,
307 size_t count, loff_t *ppos)
308{
309 struct iwl_priv *priv = file->private_data;
310 char buf[64];
311 int buf_size;
312 u32 offset, len;
313
314 memset(buf, 0, sizeof(buf));
315 buf_size = min(count, sizeof(buf) - 1);
316 if (copy_from_user(buf, user_buf, buf_size))
317 return -EFAULT;
318
319 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800320 priv->dbgfs_sram_offset = offset;
321 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800322 } else if (sscanf(buf, "%x", &offset) == 1) {
323 priv->dbgfs_sram_offset = offset;
324 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700325 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800326 priv->dbgfs_sram_offset = 0;
327 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700328 }
329
330 return count;
331}
332
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700333static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
334 char __user *user_buf,
335 size_t count, loff_t *ppos)
336{
337 struct iwl_priv *priv = file->private_data;
338
339 if (!priv->wowlan_sram)
340 return -ENODATA;
341
342 return simple_read_from_buffer(user_buf, count, ppos,
343 priv->wowlan_sram,
Johannes Berg0692fe42012-03-06 13:30:37 -0800344 priv->fw->ucode_wowlan.data.len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700345}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700346static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
347 size_t count, loff_t *ppos)
348{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700349 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800350 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700351 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700352 char *buf;
353 int i, j, pos = 0;
354 ssize_t ret;
355 /* Add 30 for initial string */
356 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700357
358 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300359 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700360 return -ENOMEM;
361
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700362 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700363 priv->num_stations);
364
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700365 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700366 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700367 if (!station->used)
368 continue;
369 pos += scnprintf(buf + pos, bufsz - pos,
370 "station %d - addr: %pM, flags: %#x\n",
371 i, station->sta.sta.addr,
372 station->sta.station_flags_msk);
373 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200374 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700375
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700376 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200377 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700378 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200379 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700380 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700381 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700382
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700383 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700384 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700385 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700386 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700387 }
Johannes Bergda735112010-05-03 01:25:24 -0700388
389 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700390 }
391
392 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
393 kfree(buf);
394 return ret;
395}
396
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700397static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800398 char __user *user_buf,
399 size_t count,
400 loff_t *ppos)
401{
402 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700403 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800404 int pos = 0, ofs = 0, buf_size = 0;
405 const u8 *ptr;
406 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700407 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800408 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800409 buf_size = 4 * eeprom_len + 256;
410
411 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700412 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800413 return -ENODATA;
414 }
415
Don Fryab36eab2011-11-30 15:37:32 -0800416 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200417 if (!ptr) {
418 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
419 return -ENOMEM;
420 }
421
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800422 /* 4 characters for byte 0xYY */
423 buf = kzalloc(buf_size, GFP_KERNEL);
424 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800425 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800426 return -ENOMEM;
427 }
Don Fryab36eab2011-11-30 15:37:32 -0800428 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700429 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
430 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800431 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700432 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800433 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
434 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
435 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
436 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700437 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800438 if (buf_size - pos > 0)
439 buf[pos++] = '\n';
440 }
441
442 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
443 kfree(buf);
444 return ret;
445}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700446
Winkler, Tomasd366df52008-12-02 12:14:01 -0800447static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
448 size_t count, loff_t *ppos)
449{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700450 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800451 struct ieee80211_channel *channels = NULL;
452 const struct ieee80211_supported_band *supp_band = NULL;
453 int pos = 0, i, bufsz = PAGE_SIZE;
454 char *buf;
455 ssize_t ret;
456
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700457 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800458 return -EAGAIN;
459
460 buf = kzalloc(bufsz, GFP_KERNEL);
461 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800462 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800463 return -ENOMEM;
464 }
465
466 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700467 if (supp_band) {
468 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800469
Winkler, Tomasd366df52008-12-02 12:14:01 -0800470 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700471 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
472 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800473
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700474 for (i = 0; i < supp_band->n_channels; i++)
475 pos += scnprintf(buf + pos, bufsz - pos,
476 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700477 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700478 channels[i].max_power,
479 channels[i].flags & IEEE80211_CHAN_RADAR ?
480 " (IEEE 802.11h required)" : "",
481 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
482 || (channels[i].flags &
483 IEEE80211_CHAN_RADAR)) ? "" :
484 ", IBSS",
485 channels[i].flags &
486 IEEE80211_CHAN_PASSIVE_SCAN ?
487 "passive only" : "active/passive");
488 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800489 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700490 if (supp_band) {
491 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800492
Winkler, Tomasd366df52008-12-02 12:14:01 -0800493 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700494 "Displaying %d channels in 5.2GHz band (802.11a)\n",
495 supp_band->n_channels);
496
497 for (i = 0; i < supp_band->n_channels; i++)
498 pos += scnprintf(buf + pos, bufsz - pos,
499 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700500 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700501 channels[i].max_power,
502 channels[i].flags & IEEE80211_CHAN_RADAR ?
503 " (IEEE 802.11h required)" : "",
504 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
505 || (channels[i].flags &
506 IEEE80211_CHAN_RADAR)) ? "" :
507 ", IBSS",
508 channels[i].flags &
509 IEEE80211_CHAN_PASSIVE_SCAN ?
510 "passive only" : "active/passive");
511 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800512 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
513 kfree(buf);
514 return ret;
515}
516
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700517static ssize_t iwl_dbgfs_status_read(struct file *file,
518 char __user *user_buf,
519 size_t count, loff_t *ppos) {
520
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700521 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700522 char buf[512];
523 int pos = 0;
524 const size_t bufsz = sizeof(buf);
525
526 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700527 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700528 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700529 test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700530 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700531 test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700532 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800533 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700534 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700535 test_bit(STATUS_ALIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700536 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700537 test_bit(STATUS_READY, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700538 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700539 test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700540 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700541 test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700542 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700543 test_bit(STATUS_STATISTICS, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700544 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700545 test_bit(STATUS_SCANNING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700546 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700547 test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700548 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700549 test_bit(STATUS_SCAN_HW, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700550 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700551 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700552 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700553 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700554 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
555}
556
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700557static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700558 char __user *user_buf,
559 size_t count, loff_t *ppos) {
560
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700561 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700562
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700563 int pos = 0;
564 int cnt = 0;
565 char *buf;
566 int bufsz = 24 * 64; /* 24 items * 64 char per item */
567 ssize_t ret;
568
569 buf = kzalloc(bufsz, GFP_KERNEL);
570 if (!buf) {
571 IWL_ERR(priv, "Can not allocate Buffer\n");
572 return -ENOMEM;
573 }
574
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700575 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700576 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700577 pos += scnprintf(buf + pos, bufsz - pos,
578 "\tRx handler[%36s]:\t\t %u\n",
579 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700580 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700581 }
582
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700583 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
584 kfree(buf);
585 return ret;
586}
587
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700588static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700589 const char __user *user_buf,
590 size_t count, loff_t *ppos)
591{
592 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700593
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700594 char buf[8];
595 int buf_size;
596 u32 reset_flag;
597
598 memset(buf, 0, sizeof(buf));
599 buf_size = min(count, sizeof(buf) - 1);
600 if (copy_from_user(buf, user_buf, buf_size))
601 return -EFAULT;
602 if (sscanf(buf, "%x", &reset_flag) != 1)
603 return -EFAULT;
604 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700605 memset(&priv->rx_handlers_stats[0], 0,
606 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700607
608 return count;
609}
610
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700611static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
612 size_t count, loff_t *ppos)
613{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700614 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200615 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700616 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200617 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700618 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700619
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200620 for_each_context(priv, ctx) {
621 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
622 ctx->ctxid);
623 for (i = 0; i < AC_NUM; i++) {
624 pos += scnprintf(buf + pos, bufsz - pos,
625 "\tcw_min\tcw_max\taifsn\ttxop\n");
626 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700627 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200628 ctx->qos_data.def_qos_parm.ac[i].cw_min,
629 ctx->qos_data.def_qos_parm.ac[i].cw_max,
630 ctx->qos_data.def_qos_parm.ac[i].aifsn,
631 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
632 }
633 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700634 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800635 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700636}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700637
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700638static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
639 char __user *user_buf,
640 size_t count, loff_t *ppos)
641{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700642 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700643 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700644 struct iwl_tt_restriction *restriction;
645 char buf[100];
646 int pos = 0;
647 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700648
649 pos += scnprintf(buf + pos, bufsz - pos,
650 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700651 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700652 pos += scnprintf(buf + pos, bufsz - pos,
653 "Thermal Throttling State: %d\n",
654 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700655 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700656 restriction = tt->restriction + tt->state;
657 pos += scnprintf(buf + pos, bufsz - pos,
658 "Tx mode: %d\n",
659 restriction->tx_stream);
660 pos += scnprintf(buf + pos, bufsz - pos,
661 "Rx mode: %d\n",
662 restriction->rx_stream);
663 pos += scnprintf(buf + pos, bufsz - pos,
664 "HT mode: %d\n",
665 restriction->is_ht);
666 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800667 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700668}
669
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700670static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
671 const char __user *user_buf,
672 size_t count, loff_t *ppos)
673{
674 struct iwl_priv *priv = file->private_data;
675 char buf[8];
676 int buf_size;
677 int ht40;
678
679 memset(buf, 0, sizeof(buf));
680 buf_size = min(count, sizeof(buf) - 1);
681 if (copy_from_user(buf, user_buf, buf_size))
682 return -EFAULT;
683 if (sscanf(buf, "%d", &ht40) != 1)
684 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200685 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700686 priv->disable_ht40 = ht40 ? true : false;
687 else {
688 IWL_ERR(priv, "Sta associated with AP - "
689 "Change to 40MHz channel support is not allowed\n");
690 return -EINVAL;
691 }
692
693 return count;
694}
695
696static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
697 char __user *user_buf,
698 size_t count, loff_t *ppos)
699{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700700 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700701 char buf[100];
702 int pos = 0;
703 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700704
705 pos += scnprintf(buf + pos, bufsz - pos,
706 "11n 40MHz Mode: %s\n",
707 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800708 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700709}
710
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700711static ssize_t iwl_dbgfs_temperature_read(struct file *file,
712 char __user *user_buf,
713 size_t count, loff_t *ppos)
714{
715 struct iwl_priv *priv = file->private_data;
716 char buf[8];
717 int pos = 0;
718 const size_t bufsz = sizeof(buf);
719
720 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
721 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
722}
723
724
Johannes Berge312c242009-08-07 15:41:51 -0700725static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
726 const char __user *user_buf,
727 size_t count, loff_t *ppos)
728{
729 struct iwl_priv *priv = file->private_data;
730 char buf[8];
731 int buf_size;
732 int value;
733
734 memset(buf, 0, sizeof(buf));
735 buf_size = min(count, sizeof(buf) - 1);
736 if (copy_from_user(buf, user_buf, buf_size))
737 return -EFAULT;
738
739 if (sscanf(buf, "%d", &value) != 1)
740 return -EINVAL;
741
742 /*
743 * Our users expect 0 to be "CAM", but 0 isn't actually
744 * valid here. However, let's not confuse them and present
745 * IWL_POWER_INDEX_1 as "1", not "0".
746 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700747 if (value == 0)
748 return -EINVAL;
749 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700750 value -= 1;
751
752 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
753 return -EINVAL;
754
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700755 if (!iwl_is_ready_rf(priv->shrd))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700756 return -EAGAIN;
757
Johannes Berge312c242009-08-07 15:41:51 -0700758 priv->power_data.debug_sleep_level_override = value;
759
Johannes Bergb1eea292012-03-06 13:30:42 -0800760 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700761 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800762 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700763
764 return count;
765}
766
767static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
768 char __user *user_buf,
769 size_t count, loff_t *ppos)
770{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700771 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700772 char buf[10];
773 int pos, value;
774 const size_t bufsz = sizeof(buf);
775
776 /* see the write function */
777 value = priv->power_data.debug_sleep_level_override;
778 if (value >= 0)
779 value += 1;
780
781 pos = scnprintf(buf, bufsz, "%d\n", value);
782 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
783}
784
785static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
786 char __user *user_buf,
787 size_t count, loff_t *ppos)
788{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700789 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700790 char buf[200];
791 int pos = 0, i;
792 const size_t bufsz = sizeof(buf);
793 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
794
795 pos += scnprintf(buf + pos, bufsz - pos,
796 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
797 pos += scnprintf(buf + pos, bufsz - pos,
798 "RX/TX timeout: %d/%d usec\n",
799 le32_to_cpu(cmd->rx_data_timeout),
800 le32_to_cpu(cmd->tx_data_timeout));
801 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
802 pos += scnprintf(buf + pos, bufsz - pos,
803 "sleep_interval[%d]: %d\n", i,
804 le32_to_cpu(cmd->sleep_interval[i]));
805
806 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
807}
808
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700809DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700810DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700811DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700812DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800813DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700814DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700815DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700816DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700817DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700818DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700819DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700820DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
821DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700822
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700823static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
824 char __user *user_buf,
825 size_t count, loff_t *ppos)
826{
827 struct iwl_priv *priv = file->private_data;
828 int pos = 0, ofs = 0;
829 int cnt = 0, entry;
830
831 char *buf;
832 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
833 (hw_params(priv).max_txq_num * 32 * 8) + 400;
834 const u8 *ptr;
835 ssize_t ret;
836
837 buf = kzalloc(bufsz, GFP_KERNEL);
838 if (!buf) {
839 IWL_ERR(priv, "Can not allocate buffer\n");
840 return -ENOMEM;
841 }
Johannes Berga8bceb32012-03-05 11:24:30 -0800842 if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700843 ptr = priv->tx_traffic;
844 pos += scnprintf(buf + pos, bufsz - pos,
845 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
846 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
847 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
848 entry++, ofs += 16) {
849 pos += scnprintf(buf + pos, bufsz - pos,
850 "0x%.4x ", ofs);
851 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
852 buf + pos, bufsz - pos, 0);
853 pos += strlen(buf + pos);
854 if (bufsz - pos > 0)
855 buf[pos++] = '\n';
856 }
857 }
858 }
859
Johannes Berga8bceb32012-03-05 11:24:30 -0800860 if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700861 ptr = priv->rx_traffic;
862 pos += scnprintf(buf + pos, bufsz - pos,
863 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
864 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
865 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
866 entry++, ofs += 16) {
867 pos += scnprintf(buf + pos, bufsz - pos,
868 "0x%.4x ", ofs);
869 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
870 buf + pos, bufsz - pos, 0);
871 pos += strlen(buf + pos);
872 if (bufsz - pos > 0)
873 buf[pos++] = '\n';
874 }
875 }
876 }
877
878 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
879 kfree(buf);
880 return ret;
881}
882
883static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
884 const char __user *user_buf,
885 size_t count, loff_t *ppos)
886{
887 struct iwl_priv *priv = file->private_data;
888 char buf[8];
889 int buf_size;
890 int traffic_log;
891
892 memset(buf, 0, sizeof(buf));
893 buf_size = min(count, sizeof(buf) - 1);
894 if (copy_from_user(buf, user_buf, buf_size))
895 return -EFAULT;
896 if (sscanf(buf, "%d", &traffic_log) != 1)
897 return -EFAULT;
898 if (traffic_log == 0)
899 iwl_reset_traffic_log(priv);
900
901 return count;
902}
903
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700904static const char *fmt_value = " %-30s %10u\n";
905static const char *fmt_hex = " %-30s 0x%02X\n";
906static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
907static const char *fmt_header =
908 "%-32s current cumulative delta max\n";
909
910static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
911{
912 int p = 0;
913 u32 flag;
914
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800915 lockdep_assert_held(&priv->statistics.lock);
916
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700917 flag = le32_to_cpu(priv->statistics.flag);
918
919 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
920 if (flag & UCODE_STATISTICS_CLEAR_MSK)
921 p += scnprintf(buf + p, bufsz - p,
922 "\tStatistics have been cleared\n");
923 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
924 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
925 ? "2.4 GHz" : "5.2 GHz");
926 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
927 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
928 ? "enabled" : "disabled");
929
930 return p;
931}
932
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700933static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
934 char __user *user_buf,
935 size_t count, loff_t *ppos)
936{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700937 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700938 int pos = 0;
939 char *buf;
940 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
941 sizeof(struct statistics_rx_non_phy) * 40 +
942 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
943 ssize_t ret;
944 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
945 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
946 struct statistics_rx_non_phy *general, *accum_general;
947 struct statistics_rx_non_phy *delta_general, *max_general;
948 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
949
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700950 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700951 return -EAGAIN;
952
953 buf = kzalloc(bufsz, GFP_KERNEL);
954 if (!buf) {
955 IWL_ERR(priv, "Can not allocate Buffer\n");
956 return -ENOMEM;
957 }
958
959 /*
960 * the statistic information display here is based on
961 * the last statistics notification from uCode
962 * might not reflect the current uCode activity
963 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800964 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700965 ofdm = &priv->statistics.rx_ofdm;
966 cck = &priv->statistics.rx_cck;
967 general = &priv->statistics.rx_non_phy;
968 ht = &priv->statistics.rx_ofdm_ht;
969 accum_ofdm = &priv->accum_stats.rx_ofdm;
970 accum_cck = &priv->accum_stats.rx_cck;
971 accum_general = &priv->accum_stats.rx_non_phy;
972 accum_ht = &priv->accum_stats.rx_ofdm_ht;
973 delta_ofdm = &priv->delta_stats.rx_ofdm;
974 delta_cck = &priv->delta_stats.rx_cck;
975 delta_general = &priv->delta_stats.rx_non_phy;
976 delta_ht = &priv->delta_stats.rx_ofdm_ht;
977 max_ofdm = &priv->max_delta_stats.rx_ofdm;
978 max_cck = &priv->max_delta_stats.rx_cck;
979 max_general = &priv->max_delta_stats.rx_non_phy;
980 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
981
982 pos += iwl_statistics_flag(priv, buf, bufsz);
983 pos += scnprintf(buf + pos, bufsz - pos,
984 fmt_header, "Statistics_Rx - OFDM:");
985 pos += scnprintf(buf + pos, bufsz - pos,
986 fmt_table, "ina_cnt:",
987 le32_to_cpu(ofdm->ina_cnt),
988 accum_ofdm->ina_cnt,
989 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
990 pos += scnprintf(buf + pos, bufsz - pos,
991 fmt_table, "fina_cnt:",
992 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
993 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
994 pos += scnprintf(buf + pos, bufsz - pos,
995 fmt_table, "plcp_err:",
996 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
997 delta_ofdm->plcp_err, max_ofdm->plcp_err);
998 pos += scnprintf(buf + pos, bufsz - pos,
999 fmt_table, "crc32_err:",
1000 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1001 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1002 pos += scnprintf(buf + pos, bufsz - pos,
1003 fmt_table, "overrun_err:",
1004 le32_to_cpu(ofdm->overrun_err),
1005 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1006 max_ofdm->overrun_err);
1007 pos += scnprintf(buf + pos, bufsz - pos,
1008 fmt_table, "early_overrun_err:",
1009 le32_to_cpu(ofdm->early_overrun_err),
1010 accum_ofdm->early_overrun_err,
1011 delta_ofdm->early_overrun_err,
1012 max_ofdm->early_overrun_err);
1013 pos += scnprintf(buf + pos, bufsz - pos,
1014 fmt_table, "crc32_good:",
1015 le32_to_cpu(ofdm->crc32_good),
1016 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1017 max_ofdm->crc32_good);
1018 pos += scnprintf(buf + pos, bufsz - pos,
1019 fmt_table, "false_alarm_cnt:",
1020 le32_to_cpu(ofdm->false_alarm_cnt),
1021 accum_ofdm->false_alarm_cnt,
1022 delta_ofdm->false_alarm_cnt,
1023 max_ofdm->false_alarm_cnt);
1024 pos += scnprintf(buf + pos, bufsz - pos,
1025 fmt_table, "fina_sync_err_cnt:",
1026 le32_to_cpu(ofdm->fina_sync_err_cnt),
1027 accum_ofdm->fina_sync_err_cnt,
1028 delta_ofdm->fina_sync_err_cnt,
1029 max_ofdm->fina_sync_err_cnt);
1030 pos += scnprintf(buf + pos, bufsz - pos,
1031 fmt_table, "sfd_timeout:",
1032 le32_to_cpu(ofdm->sfd_timeout),
1033 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1034 max_ofdm->sfd_timeout);
1035 pos += scnprintf(buf + pos, bufsz - pos,
1036 fmt_table, "fina_timeout:",
1037 le32_to_cpu(ofdm->fina_timeout),
1038 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1039 max_ofdm->fina_timeout);
1040 pos += scnprintf(buf + pos, bufsz - pos,
1041 fmt_table, "unresponded_rts:",
1042 le32_to_cpu(ofdm->unresponded_rts),
1043 accum_ofdm->unresponded_rts,
1044 delta_ofdm->unresponded_rts,
1045 max_ofdm->unresponded_rts);
1046 pos += scnprintf(buf + pos, bufsz - pos,
1047 fmt_table, "rxe_frame_lmt_ovrun:",
1048 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1049 accum_ofdm->rxe_frame_limit_overrun,
1050 delta_ofdm->rxe_frame_limit_overrun,
1051 max_ofdm->rxe_frame_limit_overrun);
1052 pos += scnprintf(buf + pos, bufsz - pos,
1053 fmt_table, "sent_ack_cnt:",
1054 le32_to_cpu(ofdm->sent_ack_cnt),
1055 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1056 max_ofdm->sent_ack_cnt);
1057 pos += scnprintf(buf + pos, bufsz - pos,
1058 fmt_table, "sent_cts_cnt:",
1059 le32_to_cpu(ofdm->sent_cts_cnt),
1060 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1061 max_ofdm->sent_cts_cnt);
1062 pos += scnprintf(buf + pos, bufsz - pos,
1063 fmt_table, "sent_ba_rsp_cnt:",
1064 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1065 accum_ofdm->sent_ba_rsp_cnt,
1066 delta_ofdm->sent_ba_rsp_cnt,
1067 max_ofdm->sent_ba_rsp_cnt);
1068 pos += scnprintf(buf + pos, bufsz - pos,
1069 fmt_table, "dsp_self_kill:",
1070 le32_to_cpu(ofdm->dsp_self_kill),
1071 accum_ofdm->dsp_self_kill,
1072 delta_ofdm->dsp_self_kill,
1073 max_ofdm->dsp_self_kill);
1074 pos += scnprintf(buf + pos, bufsz - pos,
1075 fmt_table, "mh_format_err:",
1076 le32_to_cpu(ofdm->mh_format_err),
1077 accum_ofdm->mh_format_err,
1078 delta_ofdm->mh_format_err,
1079 max_ofdm->mh_format_err);
1080 pos += scnprintf(buf + pos, bufsz - pos,
1081 fmt_table, "re_acq_main_rssi_sum:",
1082 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1083 accum_ofdm->re_acq_main_rssi_sum,
1084 delta_ofdm->re_acq_main_rssi_sum,
1085 max_ofdm->re_acq_main_rssi_sum);
1086
1087 pos += scnprintf(buf + pos, bufsz - pos,
1088 fmt_header, "Statistics_Rx - CCK:");
1089 pos += scnprintf(buf + pos, bufsz - pos,
1090 fmt_table, "ina_cnt:",
1091 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1092 delta_cck->ina_cnt, max_cck->ina_cnt);
1093 pos += scnprintf(buf + pos, bufsz - pos,
1094 fmt_table, "fina_cnt:",
1095 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1096 delta_cck->fina_cnt, max_cck->fina_cnt);
1097 pos += scnprintf(buf + pos, bufsz - pos,
1098 fmt_table, "plcp_err:",
1099 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1100 delta_cck->plcp_err, max_cck->plcp_err);
1101 pos += scnprintf(buf + pos, bufsz - pos,
1102 fmt_table, "crc32_err:",
1103 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1104 delta_cck->crc32_err, max_cck->crc32_err);
1105 pos += scnprintf(buf + pos, bufsz - pos,
1106 fmt_table, "overrun_err:",
1107 le32_to_cpu(cck->overrun_err),
1108 accum_cck->overrun_err, delta_cck->overrun_err,
1109 max_cck->overrun_err);
1110 pos += scnprintf(buf + pos, bufsz - pos,
1111 fmt_table, "early_overrun_err:",
1112 le32_to_cpu(cck->early_overrun_err),
1113 accum_cck->early_overrun_err,
1114 delta_cck->early_overrun_err,
1115 max_cck->early_overrun_err);
1116 pos += scnprintf(buf + pos, bufsz - pos,
1117 fmt_table, "crc32_good:",
1118 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1119 delta_cck->crc32_good, max_cck->crc32_good);
1120 pos += scnprintf(buf + pos, bufsz - pos,
1121 fmt_table, "false_alarm_cnt:",
1122 le32_to_cpu(cck->false_alarm_cnt),
1123 accum_cck->false_alarm_cnt,
1124 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1125 pos += scnprintf(buf + pos, bufsz - pos,
1126 fmt_table, "fina_sync_err_cnt:",
1127 le32_to_cpu(cck->fina_sync_err_cnt),
1128 accum_cck->fina_sync_err_cnt,
1129 delta_cck->fina_sync_err_cnt,
1130 max_cck->fina_sync_err_cnt);
1131 pos += scnprintf(buf + pos, bufsz - pos,
1132 fmt_table, "sfd_timeout:",
1133 le32_to_cpu(cck->sfd_timeout),
1134 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1135 max_cck->sfd_timeout);
1136 pos += scnprintf(buf + pos, bufsz - pos,
1137 fmt_table, "fina_timeout:",
1138 le32_to_cpu(cck->fina_timeout),
1139 accum_cck->fina_timeout, delta_cck->fina_timeout,
1140 max_cck->fina_timeout);
1141 pos += scnprintf(buf + pos, bufsz - pos,
1142 fmt_table, "unresponded_rts:",
1143 le32_to_cpu(cck->unresponded_rts),
1144 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1145 max_cck->unresponded_rts);
1146 pos += scnprintf(buf + pos, bufsz - pos,
1147 fmt_table, "rxe_frame_lmt_ovrun:",
1148 le32_to_cpu(cck->rxe_frame_limit_overrun),
1149 accum_cck->rxe_frame_limit_overrun,
1150 delta_cck->rxe_frame_limit_overrun,
1151 max_cck->rxe_frame_limit_overrun);
1152 pos += scnprintf(buf + pos, bufsz - pos,
1153 fmt_table, "sent_ack_cnt:",
1154 le32_to_cpu(cck->sent_ack_cnt),
1155 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1156 max_cck->sent_ack_cnt);
1157 pos += scnprintf(buf + pos, bufsz - pos,
1158 fmt_table, "sent_cts_cnt:",
1159 le32_to_cpu(cck->sent_cts_cnt),
1160 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1161 max_cck->sent_cts_cnt);
1162 pos += scnprintf(buf + pos, bufsz - pos,
1163 fmt_table, "sent_ba_rsp_cnt:",
1164 le32_to_cpu(cck->sent_ba_rsp_cnt),
1165 accum_cck->sent_ba_rsp_cnt,
1166 delta_cck->sent_ba_rsp_cnt,
1167 max_cck->sent_ba_rsp_cnt);
1168 pos += scnprintf(buf + pos, bufsz - pos,
1169 fmt_table, "dsp_self_kill:",
1170 le32_to_cpu(cck->dsp_self_kill),
1171 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1172 max_cck->dsp_self_kill);
1173 pos += scnprintf(buf + pos, bufsz - pos,
1174 fmt_table, "mh_format_err:",
1175 le32_to_cpu(cck->mh_format_err),
1176 accum_cck->mh_format_err, delta_cck->mh_format_err,
1177 max_cck->mh_format_err);
1178 pos += scnprintf(buf + pos, bufsz - pos,
1179 fmt_table, "re_acq_main_rssi_sum:",
1180 le32_to_cpu(cck->re_acq_main_rssi_sum),
1181 accum_cck->re_acq_main_rssi_sum,
1182 delta_cck->re_acq_main_rssi_sum,
1183 max_cck->re_acq_main_rssi_sum);
1184
1185 pos += scnprintf(buf + pos, bufsz - pos,
1186 fmt_header, "Statistics_Rx - GENERAL:");
1187 pos += scnprintf(buf + pos, bufsz - pos,
1188 fmt_table, "bogus_cts:",
1189 le32_to_cpu(general->bogus_cts),
1190 accum_general->bogus_cts, delta_general->bogus_cts,
1191 max_general->bogus_cts);
1192 pos += scnprintf(buf + pos, bufsz - pos,
1193 fmt_table, "bogus_ack:",
1194 le32_to_cpu(general->bogus_ack),
1195 accum_general->bogus_ack, delta_general->bogus_ack,
1196 max_general->bogus_ack);
1197 pos += scnprintf(buf + pos, bufsz - pos,
1198 fmt_table, "non_bssid_frames:",
1199 le32_to_cpu(general->non_bssid_frames),
1200 accum_general->non_bssid_frames,
1201 delta_general->non_bssid_frames,
1202 max_general->non_bssid_frames);
1203 pos += scnprintf(buf + pos, bufsz - pos,
1204 fmt_table, "filtered_frames:",
1205 le32_to_cpu(general->filtered_frames),
1206 accum_general->filtered_frames,
1207 delta_general->filtered_frames,
1208 max_general->filtered_frames);
1209 pos += scnprintf(buf + pos, bufsz - pos,
1210 fmt_table, "non_channel_beacons:",
1211 le32_to_cpu(general->non_channel_beacons),
1212 accum_general->non_channel_beacons,
1213 delta_general->non_channel_beacons,
1214 max_general->non_channel_beacons);
1215 pos += scnprintf(buf + pos, bufsz - pos,
1216 fmt_table, "channel_beacons:",
1217 le32_to_cpu(general->channel_beacons),
1218 accum_general->channel_beacons,
1219 delta_general->channel_beacons,
1220 max_general->channel_beacons);
1221 pos += scnprintf(buf + pos, bufsz - pos,
1222 fmt_table, "num_missed_bcon:",
1223 le32_to_cpu(general->num_missed_bcon),
1224 accum_general->num_missed_bcon,
1225 delta_general->num_missed_bcon,
1226 max_general->num_missed_bcon);
1227 pos += scnprintf(buf + pos, bufsz - pos,
1228 fmt_table, "adc_rx_saturation_time:",
1229 le32_to_cpu(general->adc_rx_saturation_time),
1230 accum_general->adc_rx_saturation_time,
1231 delta_general->adc_rx_saturation_time,
1232 max_general->adc_rx_saturation_time);
1233 pos += scnprintf(buf + pos, bufsz - pos,
1234 fmt_table, "ina_detect_search_tm:",
1235 le32_to_cpu(general->ina_detection_search_time),
1236 accum_general->ina_detection_search_time,
1237 delta_general->ina_detection_search_time,
1238 max_general->ina_detection_search_time);
1239 pos += scnprintf(buf + pos, bufsz - pos,
1240 fmt_table, "beacon_silence_rssi_a:",
1241 le32_to_cpu(general->beacon_silence_rssi_a),
1242 accum_general->beacon_silence_rssi_a,
1243 delta_general->beacon_silence_rssi_a,
1244 max_general->beacon_silence_rssi_a);
1245 pos += scnprintf(buf + pos, bufsz - pos,
1246 fmt_table, "beacon_silence_rssi_b:",
1247 le32_to_cpu(general->beacon_silence_rssi_b),
1248 accum_general->beacon_silence_rssi_b,
1249 delta_general->beacon_silence_rssi_b,
1250 max_general->beacon_silence_rssi_b);
1251 pos += scnprintf(buf + pos, bufsz - pos,
1252 fmt_table, "beacon_silence_rssi_c:",
1253 le32_to_cpu(general->beacon_silence_rssi_c),
1254 accum_general->beacon_silence_rssi_c,
1255 delta_general->beacon_silence_rssi_c,
1256 max_general->beacon_silence_rssi_c);
1257 pos += scnprintf(buf + pos, bufsz - pos,
1258 fmt_table, "interference_data_flag:",
1259 le32_to_cpu(general->interference_data_flag),
1260 accum_general->interference_data_flag,
1261 delta_general->interference_data_flag,
1262 max_general->interference_data_flag);
1263 pos += scnprintf(buf + pos, bufsz - pos,
1264 fmt_table, "channel_load:",
1265 le32_to_cpu(general->channel_load),
1266 accum_general->channel_load,
1267 delta_general->channel_load,
1268 max_general->channel_load);
1269 pos += scnprintf(buf + pos, bufsz - pos,
1270 fmt_table, "dsp_false_alarms:",
1271 le32_to_cpu(general->dsp_false_alarms),
1272 accum_general->dsp_false_alarms,
1273 delta_general->dsp_false_alarms,
1274 max_general->dsp_false_alarms);
1275 pos += scnprintf(buf + pos, bufsz - pos,
1276 fmt_table, "beacon_rssi_a:",
1277 le32_to_cpu(general->beacon_rssi_a),
1278 accum_general->beacon_rssi_a,
1279 delta_general->beacon_rssi_a,
1280 max_general->beacon_rssi_a);
1281 pos += scnprintf(buf + pos, bufsz - pos,
1282 fmt_table, "beacon_rssi_b:",
1283 le32_to_cpu(general->beacon_rssi_b),
1284 accum_general->beacon_rssi_b,
1285 delta_general->beacon_rssi_b,
1286 max_general->beacon_rssi_b);
1287 pos += scnprintf(buf + pos, bufsz - pos,
1288 fmt_table, "beacon_rssi_c:",
1289 le32_to_cpu(general->beacon_rssi_c),
1290 accum_general->beacon_rssi_c,
1291 delta_general->beacon_rssi_c,
1292 max_general->beacon_rssi_c);
1293 pos += scnprintf(buf + pos, bufsz - pos,
1294 fmt_table, "beacon_energy_a:",
1295 le32_to_cpu(general->beacon_energy_a),
1296 accum_general->beacon_energy_a,
1297 delta_general->beacon_energy_a,
1298 max_general->beacon_energy_a);
1299 pos += scnprintf(buf + pos, bufsz - pos,
1300 fmt_table, "beacon_energy_b:",
1301 le32_to_cpu(general->beacon_energy_b),
1302 accum_general->beacon_energy_b,
1303 delta_general->beacon_energy_b,
1304 max_general->beacon_energy_b);
1305 pos += scnprintf(buf + pos, bufsz - pos,
1306 fmt_table, "beacon_energy_c:",
1307 le32_to_cpu(general->beacon_energy_c),
1308 accum_general->beacon_energy_c,
1309 delta_general->beacon_energy_c,
1310 max_general->beacon_energy_c);
1311
1312 pos += scnprintf(buf + pos, bufsz - pos,
1313 fmt_header, "Statistics_Rx - OFDM_HT:");
1314 pos += scnprintf(buf + pos, bufsz - pos,
1315 fmt_table, "plcp_err:",
1316 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1317 delta_ht->plcp_err, max_ht->plcp_err);
1318 pos += scnprintf(buf + pos, bufsz - pos,
1319 fmt_table, "overrun_err:",
1320 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1321 delta_ht->overrun_err, max_ht->overrun_err);
1322 pos += scnprintf(buf + pos, bufsz - pos,
1323 fmt_table, "early_overrun_err:",
1324 le32_to_cpu(ht->early_overrun_err),
1325 accum_ht->early_overrun_err,
1326 delta_ht->early_overrun_err,
1327 max_ht->early_overrun_err);
1328 pos += scnprintf(buf + pos, bufsz - pos,
1329 fmt_table, "crc32_good:",
1330 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1331 delta_ht->crc32_good, max_ht->crc32_good);
1332 pos += scnprintf(buf + pos, bufsz - pos,
1333 fmt_table, "crc32_err:",
1334 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1335 delta_ht->crc32_err, max_ht->crc32_err);
1336 pos += scnprintf(buf + pos, bufsz - pos,
1337 fmt_table, "mh_format_err:",
1338 le32_to_cpu(ht->mh_format_err),
1339 accum_ht->mh_format_err,
1340 delta_ht->mh_format_err, max_ht->mh_format_err);
1341 pos += scnprintf(buf + pos, bufsz - pos,
1342 fmt_table, "agg_crc32_good:",
1343 le32_to_cpu(ht->agg_crc32_good),
1344 accum_ht->agg_crc32_good,
1345 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1346 pos += scnprintf(buf + pos, bufsz - pos,
1347 fmt_table, "agg_mpdu_cnt:",
1348 le32_to_cpu(ht->agg_mpdu_cnt),
1349 accum_ht->agg_mpdu_cnt,
1350 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1351 pos += scnprintf(buf + pos, bufsz - pos,
1352 fmt_table, "agg_cnt:",
1353 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1354 delta_ht->agg_cnt, max_ht->agg_cnt);
1355 pos += scnprintf(buf + pos, bufsz - pos,
1356 fmt_table, "unsupport_mcs:",
1357 le32_to_cpu(ht->unsupport_mcs),
1358 accum_ht->unsupport_mcs,
1359 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1360
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001361 spin_unlock_bh(&priv->statistics.lock);
1362
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001363 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1364 kfree(buf);
1365 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001366}
1367
1368static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1369 char __user *user_buf,
1370 size_t count, loff_t *ppos)
1371{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001372 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001373 int pos = 0;
1374 char *buf;
1375 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1376 ssize_t ret;
1377 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1378
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001379 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001380 return -EAGAIN;
1381
1382 buf = kzalloc(bufsz, GFP_KERNEL);
1383 if (!buf) {
1384 IWL_ERR(priv, "Can not allocate Buffer\n");
1385 return -ENOMEM;
1386 }
1387
1388 /* the statistic information display here is based on
1389 * the last statistics notification from uCode
1390 * might not reflect the current uCode activity
1391 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001392 spin_lock_bh(&priv->statistics.lock);
1393
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001394 tx = &priv->statistics.tx;
1395 accum_tx = &priv->accum_stats.tx;
1396 delta_tx = &priv->delta_stats.tx;
1397 max_tx = &priv->max_delta_stats.tx;
1398
1399 pos += iwl_statistics_flag(priv, buf, bufsz);
1400 pos += scnprintf(buf + pos, bufsz - pos,
1401 fmt_header, "Statistics_Tx:");
1402 pos += scnprintf(buf + pos, bufsz - pos,
1403 fmt_table, "preamble:",
1404 le32_to_cpu(tx->preamble_cnt),
1405 accum_tx->preamble_cnt,
1406 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1407 pos += scnprintf(buf + pos, bufsz - pos,
1408 fmt_table, "rx_detected_cnt:",
1409 le32_to_cpu(tx->rx_detected_cnt),
1410 accum_tx->rx_detected_cnt,
1411 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1412 pos += scnprintf(buf + pos, bufsz - pos,
1413 fmt_table, "bt_prio_defer_cnt:",
1414 le32_to_cpu(tx->bt_prio_defer_cnt),
1415 accum_tx->bt_prio_defer_cnt,
1416 delta_tx->bt_prio_defer_cnt,
1417 max_tx->bt_prio_defer_cnt);
1418 pos += scnprintf(buf + pos, bufsz - pos,
1419 fmt_table, "bt_prio_kill_cnt:",
1420 le32_to_cpu(tx->bt_prio_kill_cnt),
1421 accum_tx->bt_prio_kill_cnt,
1422 delta_tx->bt_prio_kill_cnt,
1423 max_tx->bt_prio_kill_cnt);
1424 pos += scnprintf(buf + pos, bufsz - pos,
1425 fmt_table, "few_bytes_cnt:",
1426 le32_to_cpu(tx->few_bytes_cnt),
1427 accum_tx->few_bytes_cnt,
1428 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1429 pos += scnprintf(buf + pos, bufsz - pos,
1430 fmt_table, "cts_timeout:",
1431 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1432 delta_tx->cts_timeout, max_tx->cts_timeout);
1433 pos += scnprintf(buf + pos, bufsz - pos,
1434 fmt_table, "ack_timeout:",
1435 le32_to_cpu(tx->ack_timeout),
1436 accum_tx->ack_timeout,
1437 delta_tx->ack_timeout, max_tx->ack_timeout);
1438 pos += scnprintf(buf + pos, bufsz - pos,
1439 fmt_table, "expected_ack_cnt:",
1440 le32_to_cpu(tx->expected_ack_cnt),
1441 accum_tx->expected_ack_cnt,
1442 delta_tx->expected_ack_cnt,
1443 max_tx->expected_ack_cnt);
1444 pos += scnprintf(buf + pos, bufsz - pos,
1445 fmt_table, "actual_ack_cnt:",
1446 le32_to_cpu(tx->actual_ack_cnt),
1447 accum_tx->actual_ack_cnt,
1448 delta_tx->actual_ack_cnt,
1449 max_tx->actual_ack_cnt);
1450 pos += scnprintf(buf + pos, bufsz - pos,
1451 fmt_table, "dump_msdu_cnt:",
1452 le32_to_cpu(tx->dump_msdu_cnt),
1453 accum_tx->dump_msdu_cnt,
1454 delta_tx->dump_msdu_cnt,
1455 max_tx->dump_msdu_cnt);
1456 pos += scnprintf(buf + pos, bufsz - pos,
1457 fmt_table, "abort_nxt_frame_mismatch:",
1458 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1459 accum_tx->burst_abort_next_frame_mismatch_cnt,
1460 delta_tx->burst_abort_next_frame_mismatch_cnt,
1461 max_tx->burst_abort_next_frame_mismatch_cnt);
1462 pos += scnprintf(buf + pos, bufsz - pos,
1463 fmt_table, "abort_missing_nxt_frame:",
1464 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1465 accum_tx->burst_abort_missing_next_frame_cnt,
1466 delta_tx->burst_abort_missing_next_frame_cnt,
1467 max_tx->burst_abort_missing_next_frame_cnt);
1468 pos += scnprintf(buf + pos, bufsz - pos,
1469 fmt_table, "cts_timeout_collision:",
1470 le32_to_cpu(tx->cts_timeout_collision),
1471 accum_tx->cts_timeout_collision,
1472 delta_tx->cts_timeout_collision,
1473 max_tx->cts_timeout_collision);
1474 pos += scnprintf(buf + pos, bufsz - pos,
1475 fmt_table, "ack_ba_timeout_collision:",
1476 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1477 accum_tx->ack_or_ba_timeout_collision,
1478 delta_tx->ack_or_ba_timeout_collision,
1479 max_tx->ack_or_ba_timeout_collision);
1480 pos += scnprintf(buf + pos, bufsz - pos,
1481 fmt_table, "agg ba_timeout:",
1482 le32_to_cpu(tx->agg.ba_timeout),
1483 accum_tx->agg.ba_timeout,
1484 delta_tx->agg.ba_timeout,
1485 max_tx->agg.ba_timeout);
1486 pos += scnprintf(buf + pos, bufsz - pos,
1487 fmt_table, "agg ba_resched_frames:",
1488 le32_to_cpu(tx->agg.ba_reschedule_frames),
1489 accum_tx->agg.ba_reschedule_frames,
1490 delta_tx->agg.ba_reschedule_frames,
1491 max_tx->agg.ba_reschedule_frames);
1492 pos += scnprintf(buf + pos, bufsz - pos,
1493 fmt_table, "agg scd_query_agg_frame:",
1494 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1495 accum_tx->agg.scd_query_agg_frame_cnt,
1496 delta_tx->agg.scd_query_agg_frame_cnt,
1497 max_tx->agg.scd_query_agg_frame_cnt);
1498 pos += scnprintf(buf + pos, bufsz - pos,
1499 fmt_table, "agg scd_query_no_agg:",
1500 le32_to_cpu(tx->agg.scd_query_no_agg),
1501 accum_tx->agg.scd_query_no_agg,
1502 delta_tx->agg.scd_query_no_agg,
1503 max_tx->agg.scd_query_no_agg);
1504 pos += scnprintf(buf + pos, bufsz - pos,
1505 fmt_table, "agg scd_query_agg:",
1506 le32_to_cpu(tx->agg.scd_query_agg),
1507 accum_tx->agg.scd_query_agg,
1508 delta_tx->agg.scd_query_agg,
1509 max_tx->agg.scd_query_agg);
1510 pos += scnprintf(buf + pos, bufsz - pos,
1511 fmt_table, "agg scd_query_mismatch:",
1512 le32_to_cpu(tx->agg.scd_query_mismatch),
1513 accum_tx->agg.scd_query_mismatch,
1514 delta_tx->agg.scd_query_mismatch,
1515 max_tx->agg.scd_query_mismatch);
1516 pos += scnprintf(buf + pos, bufsz - pos,
1517 fmt_table, "agg frame_not_ready:",
1518 le32_to_cpu(tx->agg.frame_not_ready),
1519 accum_tx->agg.frame_not_ready,
1520 delta_tx->agg.frame_not_ready,
1521 max_tx->agg.frame_not_ready);
1522 pos += scnprintf(buf + pos, bufsz - pos,
1523 fmt_table, "agg underrun:",
1524 le32_to_cpu(tx->agg.underrun),
1525 accum_tx->agg.underrun,
1526 delta_tx->agg.underrun, max_tx->agg.underrun);
1527 pos += scnprintf(buf + pos, bufsz - pos,
1528 fmt_table, "agg bt_prio_kill:",
1529 le32_to_cpu(tx->agg.bt_prio_kill),
1530 accum_tx->agg.bt_prio_kill,
1531 delta_tx->agg.bt_prio_kill,
1532 max_tx->agg.bt_prio_kill);
1533 pos += scnprintf(buf + pos, bufsz - pos,
1534 fmt_table, "agg rx_ba_rsp_cnt:",
1535 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1536 accum_tx->agg.rx_ba_rsp_cnt,
1537 delta_tx->agg.rx_ba_rsp_cnt,
1538 max_tx->agg.rx_ba_rsp_cnt);
1539
1540 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1541 pos += scnprintf(buf + pos, bufsz - pos,
1542 "tx power: (1/2 dB step)\n");
Johannes Berg7e79a392012-03-05 11:24:32 -08001543 if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1544 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001545 pos += scnprintf(buf + pos, bufsz - pos,
1546 fmt_hex, "antenna A:",
1547 tx->tx_power.ant_a);
Johannes Berg7e79a392012-03-05 11:24:32 -08001548 if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1549 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001550 pos += scnprintf(buf + pos, bufsz - pos,
1551 fmt_hex, "antenna B:",
1552 tx->tx_power.ant_b);
Johannes Berg7e79a392012-03-05 11:24:32 -08001553 if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1554 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001555 pos += scnprintf(buf + pos, bufsz - pos,
1556 fmt_hex, "antenna C:",
1557 tx->tx_power.ant_c);
1558 }
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001559
1560 spin_unlock_bh(&priv->statistics.lock);
1561
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001562 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1563 kfree(buf);
1564 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001565}
1566
1567static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1568 char __user *user_buf,
1569 size_t count, loff_t *ppos)
1570{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001571 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001572 int pos = 0;
1573 char *buf;
1574 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1575 ssize_t ret;
1576 struct statistics_general_common *general, *accum_general;
1577 struct statistics_general_common *delta_general, *max_general;
1578 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1579 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1580
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001581 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001582 return -EAGAIN;
1583
1584 buf = kzalloc(bufsz, GFP_KERNEL);
1585 if (!buf) {
1586 IWL_ERR(priv, "Can not allocate Buffer\n");
1587 return -ENOMEM;
1588 }
1589
1590 /* the statistic information display here is based on
1591 * the last statistics notification from uCode
1592 * might not reflect the current uCode activity
1593 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001594
1595 spin_lock_bh(&priv->statistics.lock);
1596
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001597 general = &priv->statistics.common;
1598 dbg = &priv->statistics.common.dbg;
1599 div = &priv->statistics.common.div;
1600 accum_general = &priv->accum_stats.common;
1601 accum_dbg = &priv->accum_stats.common.dbg;
1602 accum_div = &priv->accum_stats.common.div;
1603 delta_general = &priv->delta_stats.common;
1604 max_general = &priv->max_delta_stats.common;
1605 delta_dbg = &priv->delta_stats.common.dbg;
1606 max_dbg = &priv->max_delta_stats.common.dbg;
1607 delta_div = &priv->delta_stats.common.div;
1608 max_div = &priv->max_delta_stats.common.div;
1609
1610 pos += iwl_statistics_flag(priv, buf, bufsz);
1611 pos += scnprintf(buf + pos, bufsz - pos,
1612 fmt_header, "Statistics_General:");
1613 pos += scnprintf(buf + pos, bufsz - pos,
1614 fmt_value, "temperature:",
1615 le32_to_cpu(general->temperature));
1616 pos += scnprintf(buf + pos, bufsz - pos,
1617 fmt_value, "temperature_m:",
1618 le32_to_cpu(general->temperature_m));
1619 pos += scnprintf(buf + pos, bufsz - pos,
1620 fmt_value, "ttl_timestamp:",
1621 le32_to_cpu(general->ttl_timestamp));
1622 pos += scnprintf(buf + pos, bufsz - pos,
1623 fmt_table, "burst_check:",
1624 le32_to_cpu(dbg->burst_check),
1625 accum_dbg->burst_check,
1626 delta_dbg->burst_check, max_dbg->burst_check);
1627 pos += scnprintf(buf + pos, bufsz - pos,
1628 fmt_table, "burst_count:",
1629 le32_to_cpu(dbg->burst_count),
1630 accum_dbg->burst_count,
1631 delta_dbg->burst_count, max_dbg->burst_count);
1632 pos += scnprintf(buf + pos, bufsz - pos,
1633 fmt_table, "wait_for_silence_timeout_count:",
1634 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1635 accum_dbg->wait_for_silence_timeout_cnt,
1636 delta_dbg->wait_for_silence_timeout_cnt,
1637 max_dbg->wait_for_silence_timeout_cnt);
1638 pos += scnprintf(buf + pos, bufsz - pos,
1639 fmt_table, "sleep_time:",
1640 le32_to_cpu(general->sleep_time),
1641 accum_general->sleep_time,
1642 delta_general->sleep_time, max_general->sleep_time);
1643 pos += scnprintf(buf + pos, bufsz - pos,
1644 fmt_table, "slots_out:",
1645 le32_to_cpu(general->slots_out),
1646 accum_general->slots_out,
1647 delta_general->slots_out, max_general->slots_out);
1648 pos += scnprintf(buf + pos, bufsz - pos,
1649 fmt_table, "slots_idle:",
1650 le32_to_cpu(general->slots_idle),
1651 accum_general->slots_idle,
1652 delta_general->slots_idle, max_general->slots_idle);
1653 pos += scnprintf(buf + pos, bufsz - pos,
1654 fmt_table, "tx_on_a:",
1655 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1656 delta_div->tx_on_a, max_div->tx_on_a);
1657 pos += scnprintf(buf + pos, bufsz - pos,
1658 fmt_table, "tx_on_b:",
1659 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1660 delta_div->tx_on_b, max_div->tx_on_b);
1661 pos += scnprintf(buf + pos, bufsz - pos,
1662 fmt_table, "exec_time:",
1663 le32_to_cpu(div->exec_time), accum_div->exec_time,
1664 delta_div->exec_time, max_div->exec_time);
1665 pos += scnprintf(buf + pos, bufsz - pos,
1666 fmt_table, "probe_time:",
1667 le32_to_cpu(div->probe_time), accum_div->probe_time,
1668 delta_div->probe_time, max_div->probe_time);
1669 pos += scnprintf(buf + pos, bufsz - pos,
1670 fmt_table, "rx_enable_counter:",
1671 le32_to_cpu(general->rx_enable_counter),
1672 accum_general->rx_enable_counter,
1673 delta_general->rx_enable_counter,
1674 max_general->rx_enable_counter);
1675 pos += scnprintf(buf + pos, bufsz - pos,
1676 fmt_table, "num_of_sos_states:",
1677 le32_to_cpu(general->num_of_sos_states),
1678 accum_general->num_of_sos_states,
1679 delta_general->num_of_sos_states,
1680 max_general->num_of_sos_states);
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001681
1682 spin_unlock_bh(&priv->statistics.lock);
1683
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001684 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1685 kfree(buf);
1686 return ret;
1687}
1688
1689static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1690 char __user *user_buf,
1691 size_t count, loff_t *ppos)
1692{
1693 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1694 int pos = 0;
1695 char *buf;
1696 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1697 ssize_t ret;
1698 struct statistics_bt_activity *bt, *accum_bt;
1699
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001700 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001701 return -EAGAIN;
1702
1703 if (!priv->bt_enable_flag)
1704 return -EINVAL;
1705
1706 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001707 mutex_lock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001708 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001709 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001710
1711 if (ret) {
1712 IWL_ERR(priv,
1713 "Error sending statistics request: %zd\n", ret);
1714 return -EAGAIN;
1715 }
1716 buf = kzalloc(bufsz, GFP_KERNEL);
1717 if (!buf) {
1718 IWL_ERR(priv, "Can not allocate Buffer\n");
1719 return -ENOMEM;
1720 }
1721
1722 /*
1723 * the statistic information display here is based on
1724 * the last statistics notification from uCode
1725 * might not reflect the current uCode activity
1726 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001727
1728 spin_lock_bh(&priv->statistics.lock);
1729
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001730 bt = &priv->statistics.bt_activity;
1731 accum_bt = &priv->accum_stats.bt_activity;
1732
1733 pos += iwl_statistics_flag(priv, buf, bufsz);
1734 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1735 pos += scnprintf(buf + pos, bufsz - pos,
1736 "\t\t\tcurrent\t\t\taccumulative\n");
1737 pos += scnprintf(buf + pos, bufsz - pos,
1738 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1739 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1740 accum_bt->hi_priority_tx_req_cnt);
1741 pos += scnprintf(buf + pos, bufsz - pos,
1742 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1743 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1744 accum_bt->hi_priority_tx_denied_cnt);
1745 pos += scnprintf(buf + pos, bufsz - pos,
1746 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1747 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1748 accum_bt->lo_priority_tx_req_cnt);
1749 pos += scnprintf(buf + pos, bufsz - pos,
1750 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1751 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1752 accum_bt->lo_priority_tx_denied_cnt);
1753 pos += scnprintf(buf + pos, bufsz - pos,
1754 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1755 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1756 accum_bt->hi_priority_rx_req_cnt);
1757 pos += scnprintf(buf + pos, bufsz - pos,
1758 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1759 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1760 accum_bt->hi_priority_rx_denied_cnt);
1761 pos += scnprintf(buf + pos, bufsz - pos,
1762 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1763 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1764 accum_bt->lo_priority_rx_req_cnt);
1765 pos += scnprintf(buf + pos, bufsz - pos,
1766 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1767 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1768 accum_bt->lo_priority_rx_denied_cnt);
1769
1770 pos += scnprintf(buf + pos, bufsz - pos,
1771 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1772 le32_to_cpu(priv->statistics.num_bt_kills),
1773 priv->statistics.accum_num_bt_kills);
1774
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001775 spin_unlock_bh(&priv->statistics.lock);
1776
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001777 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1778 kfree(buf);
1779 return ret;
1780}
1781
1782static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1783 char __user *user_buf,
1784 size_t count, loff_t *ppos)
1785{
1786 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1787 int pos = 0;
1788 char *buf;
1789 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1790 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1791 ssize_t ret;
1792
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001793 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001794 return -EAGAIN;
1795
1796 buf = kzalloc(bufsz, GFP_KERNEL);
1797 if (!buf) {
1798 IWL_ERR(priv, "Can not allocate Buffer\n");
1799 return -ENOMEM;
1800 }
1801
1802 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1803 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1804 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
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_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001808 priv->reply_tx_stats.pp_few_bytes);
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_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001811 priv->reply_tx_stats.pp_bt_prio);
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_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001814 priv->reply_tx_stats.pp_quiet_period);
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_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001817 priv->reply_tx_stats.pp_calc_ttak);
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_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001821 priv->reply_tx_stats.int_crossed_retry);
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_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001824 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001825 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1826 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001827 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001828 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1829 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001830 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001831 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1832 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001833 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001834 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1835 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001836 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001837 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1838 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001839 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001840 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1841 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001842 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001843 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1844 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001845 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001846 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1847 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001848 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001849 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1850 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001851 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001852 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1853 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001854 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001855 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1856 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001857 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001858 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1859 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001860 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001861 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1862 iwl_get_tx_fail_reason(
1863 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001864 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001865 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1866 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001867 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001868 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1869 iwl_get_tx_fail_reason(
1870 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001871 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001872 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001873 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001874
1875 pos += scnprintf(buf + pos, bufsz - pos,
1876 "\nStatistics_Agg_TX_Error:\n");
1877
1878 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1879 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001880 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001881 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1882 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001883 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001884 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1885 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001886 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001887 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1888 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001889 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001890 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1891 iwl_get_agg_tx_fail_reason(
1892 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001893 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001894 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1895 iwl_get_agg_tx_fail_reason(
1896 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001897 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001898 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1899 iwl_get_agg_tx_fail_reason(
1900 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001901 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001902 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1903 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001904 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001905 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1906 iwl_get_agg_tx_fail_reason(
1907 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001908 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001909 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1910 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001911 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001912 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1913 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001914 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001915 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1916 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001917 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001918 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001919 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001920
1921 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1922 kfree(buf);
1923 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001924}
1925
Wey-Yi Guy52259352009-08-07 15:41:43 -07001926static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1927 char __user *user_buf,
1928 size_t count, loff_t *ppos) {
1929
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001930 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001931 int pos = 0;
1932 int cnt = 0;
1933 char *buf;
1934 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1935 ssize_t ret;
1936 struct iwl_sensitivity_data *data;
1937
1938 data = &priv->sensitivity_data;
1939 buf = kzalloc(bufsz, GFP_KERNEL);
1940 if (!buf) {
1941 IWL_ERR(priv, "Can not allocate Buffer\n");
1942 return -ENOMEM;
1943 }
1944
1945 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1946 data->auto_corr_ofdm);
1947 pos += scnprintf(buf + pos, bufsz - pos,
1948 "auto_corr_ofdm_mrc:\t\t %u\n",
1949 data->auto_corr_ofdm_mrc);
1950 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1951 data->auto_corr_ofdm_x1);
1952 pos += scnprintf(buf + pos, bufsz - pos,
1953 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1954 data->auto_corr_ofdm_mrc_x1);
1955 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1956 data->auto_corr_cck);
1957 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1958 data->auto_corr_cck_mrc);
1959 pos += scnprintf(buf + pos, bufsz - pos,
1960 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1961 data->last_bad_plcp_cnt_ofdm);
1962 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1963 data->last_fa_cnt_ofdm);
1964 pos += scnprintf(buf + pos, bufsz - pos,
1965 "last_bad_plcp_cnt_cck:\t\t %u\n",
1966 data->last_bad_plcp_cnt_cck);
1967 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1968 data->last_fa_cnt_cck);
1969 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1970 data->nrg_curr_state);
1971 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1972 data->nrg_prev_state);
1973 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1974 for (cnt = 0; cnt < 10; cnt++) {
1975 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1976 data->nrg_value[cnt]);
1977 }
1978 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1979 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1980 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1981 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1982 data->nrg_silence_rssi[cnt]);
1983 }
1984 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1985 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1986 data->nrg_silence_ref);
1987 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1988 data->nrg_energy_idx);
1989 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1990 data->nrg_silence_idx);
1991 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1992 data->nrg_th_cck);
1993 pos += scnprintf(buf + pos, bufsz - pos,
1994 "nrg_auto_corr_silence_diff:\t %u\n",
1995 data->nrg_auto_corr_silence_diff);
1996 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1997 data->num_in_cck_no_fa);
1998 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1999 data->nrg_th_ofdm);
2000
2001 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2002 kfree(buf);
2003 return ret;
2004}
2005
2006
2007static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2008 char __user *user_buf,
2009 size_t count, loff_t *ppos) {
2010
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002011 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002012 int pos = 0;
2013 int cnt = 0;
2014 char *buf;
2015 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2016 ssize_t ret;
2017 struct iwl_chain_noise_data *data;
2018
2019 data = &priv->chain_noise_data;
2020 buf = kzalloc(bufsz, GFP_KERNEL);
2021 if (!buf) {
2022 IWL_ERR(priv, "Can not allocate Buffer\n");
2023 return -ENOMEM;
2024 }
2025
2026 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2027 data->active_chains);
2028 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2029 data->chain_noise_a);
2030 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2031 data->chain_noise_b);
2032 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2033 data->chain_noise_c);
2034 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2035 data->chain_signal_a);
2036 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2037 data->chain_signal_b);
2038 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2039 data->chain_signal_c);
2040 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2041 data->beacon_count);
2042
2043 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2044 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2045 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2046 data->disconn_array[cnt]);
2047 }
2048 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2049 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2050 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2051 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2052 data->delta_gain_code[cnt]);
2053 }
2054 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2055 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2056 data->radio_write);
2057 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2058 data->state);
2059
2060 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2061 kfree(buf);
2062 return ret;
2063}
2064
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002065static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2066 char __user *user_buf,
2067 size_t count, loff_t *ppos)
2068{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002069 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002070 char buf[60];
2071 int pos = 0;
2072 const size_t bufsz = sizeof(buf);
2073 u32 pwrsave_status;
2074
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002075 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002076 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2077
2078 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2079 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2080 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2081 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2082 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2083 "error");
2084
2085 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2086}
2087
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002088static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002089 const char __user *user_buf,
2090 size_t count, loff_t *ppos)
2091{
2092 struct iwl_priv *priv = file->private_data;
2093 char buf[8];
2094 int buf_size;
2095 int clear;
2096
2097 memset(buf, 0, sizeof(buf));
2098 buf_size = min(count, sizeof(buf) - 1);
2099 if (copy_from_user(buf, user_buf, buf_size))
2100 return -EFAULT;
2101 if (sscanf(buf, "%d", &clear) != 1)
2102 return -EFAULT;
2103
2104 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08002105 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002106 iwl_send_statistics_request(priv, CMD_SYNC, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08002107 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002108
2109 return count;
2110}
2111
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002112static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2113 char __user *user_buf,
2114 size_t count, loff_t *ppos) {
2115
Joe Perches57674302010-07-12 13:50:06 -07002116 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002117 int pos = 0;
2118 char buf[128];
2119 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002120
2121 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2122 priv->event_log.ucode_trace ? "On" : "Off");
2123 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2124 priv->event_log.non_wraps_count);
2125 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2126 priv->event_log.wraps_once_count);
2127 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2128 priv->event_log.wraps_more_count);
2129
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002130 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002131}
2132
2133static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2134 const char __user *user_buf,
2135 size_t count, loff_t *ppos)
2136{
2137 struct iwl_priv *priv = file->private_data;
2138 char buf[8];
2139 int buf_size;
2140 int trace;
2141
2142 memset(buf, 0, sizeof(buf));
2143 buf_size = min(count, sizeof(buf) - 1);
2144 if (copy_from_user(buf, user_buf, buf_size))
2145 return -EFAULT;
2146 if (sscanf(buf, "%d", &trace) != 1)
2147 return -EFAULT;
2148
2149 if (trace) {
2150 priv->event_log.ucode_trace = true;
Johannes Berg98d4bf02012-01-13 11:56:11 +01002151 if (iwl_is_alive(priv->shrd)) {
2152 /* start collecting data now */
2153 mod_timer(&priv->ucode_trace, jiffies);
2154 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002155 } else {
2156 priv->event_log.ucode_trace = false;
2157 del_timer_sync(&priv->ucode_trace);
2158 }
2159
2160 return count;
2161}
2162
Johannes Berg60987202010-02-18 00:36:07 -08002163static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2164 char __user *user_buf,
2165 size_t count, loff_t *ppos) {
2166
Joe Perches57674302010-07-12 13:50:06 -07002167 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002168 int len = 0;
2169 char buf[20];
2170
Johannes Berg246ed352010-08-23 10:46:32 +02002171 len = sprintf(buf, "0x%04X\n",
2172 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002173 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2174}
2175
2176static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2177 char __user *user_buf,
2178 size_t count, loff_t *ppos) {
2179
Joe Perches57674302010-07-12 13:50:06 -07002180 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002181 int len = 0;
2182 char buf[20];
2183
2184 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002185 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002186 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2187}
2188
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002189static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2190 char __user *user_buf,
2191 size_t count, loff_t *ppos) {
2192
2193 struct iwl_priv *priv = file->private_data;
2194 int pos = 0;
2195 char buf[12];
2196 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002197
2198 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2199 priv->missed_beacon_threshold);
2200
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002201 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002202}
2203
2204static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2205 const char __user *user_buf,
2206 size_t count, loff_t *ppos)
2207{
2208 struct iwl_priv *priv = file->private_data;
2209 char buf[8];
2210 int buf_size;
2211 int missed;
2212
2213 memset(buf, 0, sizeof(buf));
2214 buf_size = min(count, sizeof(buf) - 1);
2215 if (copy_from_user(buf, user_buf, buf_size))
2216 return -EFAULT;
2217 if (sscanf(buf, "%d", &missed) != 1)
2218 return -EINVAL;
2219
2220 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2221 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2222 priv->missed_beacon_threshold =
2223 IWL_MISSED_BEACON_THRESHOLD_DEF;
2224 else
2225 priv->missed_beacon_threshold = missed;
2226
2227 return count;
2228}
2229
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002230static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2231 char __user *user_buf,
2232 size_t count, loff_t *ppos) {
2233
Joe Perches57674302010-07-12 13:50:06 -07002234 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002235 int pos = 0;
2236 char buf[12];
2237 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002238
2239 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002240 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002241
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002242 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002243}
2244
2245static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2246 const char __user *user_buf,
2247 size_t count, loff_t *ppos) {
2248
2249 struct iwl_priv *priv = file->private_data;
2250 char buf[8];
2251 int buf_size;
2252 int plcp;
2253
2254 memset(buf, 0, sizeof(buf));
2255 buf_size = min(count, sizeof(buf) - 1);
2256 if (copy_from_user(buf, user_buf, buf_size))
2257 return -EFAULT;
2258 if (sscanf(buf, "%d", &plcp) != 1)
2259 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002260 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002261 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002262 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002263 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002264 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002265 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002266 return count;
2267}
2268
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002269static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2270 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002271 size_t count, loff_t *ppos)
2272{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002273 struct iwl_priv *priv = file->private_data;
2274 int i, pos = 0;
2275 char buf[300];
2276 const size_t bufsz = sizeof(buf);
2277 struct iwl_force_reset *force_reset;
2278
2279 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2280 force_reset = &priv->force_reset[i];
2281 pos += scnprintf(buf + pos, bufsz - pos,
2282 "Force reset method %d\n", i);
2283 pos += scnprintf(buf + pos, bufsz - pos,
2284 "\tnumber of reset request: %d\n",
2285 force_reset->reset_request_count);
2286 pos += scnprintf(buf + pos, bufsz - pos,
2287 "\tnumber of reset request success: %d\n",
2288 force_reset->reset_success_count);
2289 pos += scnprintf(buf + pos, bufsz - pos,
2290 "\tnumber of reset request reject: %d\n",
2291 force_reset->reset_reject_count);
2292 pos += scnprintf(buf + pos, bufsz - pos,
2293 "\treset duration: %lu\n",
2294 force_reset->reset_duration);
2295 }
2296 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2297}
2298
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002299static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2300 const char __user *user_buf,
2301 size_t count, loff_t *ppos) {
2302
2303 struct iwl_priv *priv = file->private_data;
2304 char buf[8];
2305 int buf_size;
2306 int reset, ret;
2307
2308 memset(buf, 0, sizeof(buf));
2309 buf_size = min(count, sizeof(buf) - 1);
2310 if (copy_from_user(buf, user_buf, buf_size))
2311 return -EFAULT;
2312 if (sscanf(buf, "%d", &reset) != 1)
2313 return -EINVAL;
2314 switch (reset) {
2315 case IWL_RF_RESET:
2316 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002317 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002318 break;
2319 default:
2320 return -EINVAL;
2321 }
2322 return ret ? ret : count;
2323}
2324
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002325static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2326 const char __user *user_buf,
2327 size_t count, loff_t *ppos) {
2328
2329 struct iwl_priv *priv = file->private_data;
2330 char buf[8];
2331 int buf_size;
2332 int flush;
2333
2334 memset(buf, 0, sizeof(buf));
2335 buf_size = min(count, sizeof(buf) - 1);
2336 if (copy_from_user(buf, user_buf, buf_size))
2337 return -EFAULT;
2338 if (sscanf(buf, "%d", &flush) != 1)
2339 return -EINVAL;
2340
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07002341 if (iwl_is_rfkill(priv->shrd))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002342 return -EFAULT;
2343
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002344 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002345
2346 return count;
2347}
2348
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002349static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002350 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002351 size_t count, loff_t *ppos)
2352{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002353 struct iwl_priv *priv = file->private_data;
2354 char buf[8];
2355 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002356 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002357
2358 memset(buf, 0, sizeof(buf));
2359 buf_size = min(count, sizeof(buf) - 1);
2360 if (copy_from_user(buf, user_buf, buf_size))
2361 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002362 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002363 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002364 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2365 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002366
Johannes Berge7a09432012-03-06 13:30:54 -08002367 hw_params(priv).wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002368 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002369 return count;
2370}
2371
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002372static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2373 char __user *user_buf,
2374 size_t count, loff_t *ppos) {
2375
2376 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2377 int pos = 0;
2378 char buf[200];
2379 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002380
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002381 if (!priv->bt_enable_flag) {
2382 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002383 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002384 }
2385 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2386 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002387 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2388 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2389 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2390 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002391 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002392 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002393 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2394 priv->bt_ch_announce, priv->kill_ack_mask,
2395 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002396
2397 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2398 switch (priv->bt_traffic_load) {
2399 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2400 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2401 break;
2402 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2403 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2404 break;
2405 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2406 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2407 break;
2408 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2409 default:
2410 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2411 break;
2412 }
2413
Johannes Berg08960de2011-04-05 09:41:53 -07002414 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002415}
2416
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002417static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2418 char __user *user_buf,
2419 size_t count, loff_t *ppos)
2420{
2421 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2422
2423 int pos = 0;
2424 char buf[40];
2425 const size_t bufsz = sizeof(buf);
2426
Don Fry38622412011-12-16 07:07:36 -08002427 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002428 pos += scnprintf(buf + pos, bufsz - pos,
2429 "use %s for aggregation\n",
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002430 (hw_params(priv).use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002431 "rts/cts" : "cts-to-self");
2432 else
2433 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2434
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002435 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2436}
2437
2438static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2439 const char __user *user_buf,
2440 size_t count, loff_t *ppos) {
2441
2442 struct iwl_priv *priv = file->private_data;
2443 char buf[8];
2444 int buf_size;
2445 int rts;
2446
Don Fry38622412011-12-16 07:07:36 -08002447 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002448 return -EINVAL;
2449
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002450 memset(buf, 0, sizeof(buf));
2451 buf_size = min(count, sizeof(buf) - 1);
2452 if (copy_from_user(buf, user_buf, buf_size))
2453 return -EFAULT;
2454 if (sscanf(buf, "%d", &rts) != 1)
2455 return -EINVAL;
2456 if (rts)
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002457 hw_params(priv).use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002458 else
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002459 hw_params(priv).use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002460 return count;
2461}
2462
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002463static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2464 const char __user *user_buf,
2465 size_t count, loff_t *ppos)
2466{
2467 struct iwl_priv *priv = file->private_data;
2468 char buf[8];
2469 int buf_size;
2470
2471 memset(buf, 0, sizeof(buf));
2472 buf_size = min(count, sizeof(buf) - 1);
2473 if (copy_from_user(buf, user_buf, buf_size))
2474 return -EFAULT;
2475
2476 iwl_cmd_echo_test(priv);
2477 return count;
2478}
2479
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002480DEBUGFS_READ_FILE_OPS(rx_statistics);
2481DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002482DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002483DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2484DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2485DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002486DEBUGFS_READ_FILE_OPS(sensitivity);
2487DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002488DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002489DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2490DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002491DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002492DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002493DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002494DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002495DEBUGFS_READ_FILE_OPS(rxon_flags);
2496DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002497DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002498DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002499DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002500DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002501DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002502DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002503DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002504
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002505/*
2506 * Create the debugfs files and directories
2507 *
2508 */
2509int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2510{
Zhu Yi95b1a822008-05-29 16:34:50 +08002511 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002512 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002513
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002514 dir_drv = debugfs_create_dir(name, phyd);
2515 if (!dir_drv)
2516 return -ENOMEM;
2517
2518 priv->debugfs_dir = dir_drv;
2519
2520 dir_data = debugfs_create_dir("data", dir_drv);
2521 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002522 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002523 dir_rf = debugfs_create_dir("rf", dir_drv);
2524 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002525 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002526 dir_debug = debugfs_create_dir("debug", dir_drv);
2527 if (!dir_debug)
2528 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002529
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002530 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2531 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002532 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002533 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2534 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2535 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002536 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002537 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002538 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2539 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002540 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2541 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002542 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002543
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002544 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2545 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002546 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002547 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2548 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2549 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002550 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002551 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002552 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002553 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2554 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2555 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002556 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002557 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002558 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2559 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002560 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002561 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002562 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002563 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2564 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002565 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002566 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002567 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002568 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002569
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002570 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2571 &priv->disable_sens_cal);
2572 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2573 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002574
2575 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2576 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002577 return 0;
2578
2579err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002580 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002581 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002582 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002583}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002584
2585/**
2586 * Remove the debugfs files and directories
2587 *
2588 */
2589void iwl_dbgfs_unregister(struct iwl_priv *priv)
2590{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002591 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002592 return;
2593
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002594 debugfs_remove_recursive(priv->debugfs_dir);
2595 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002596}