blob: d587bcdda015c4914a04177d8c2135a8f9ef368f [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
Tomas Winkler712b6cf2008-03-12 16:58:52 -070087#define DEBUGFS_READ_FILE_OPS(name) \
88 DEBUGFS_READ_FUNC(name); \
89static const struct file_operations iwl_dbgfs_##name##_ops = { \
90 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070091 .open = simple_open, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +020092 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070093};
94
Ester Kummer189a2b52008-05-15 13:54:18 +080095#define DEBUGFS_WRITE_FILE_OPS(name) \
96 DEBUGFS_WRITE_FUNC(name); \
97static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
Stephen Boyd234e3402012-04-05 14:25:11 -070099 .open = simple_open, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +0200100 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800101};
102
103
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700104#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
105 DEBUGFS_READ_FUNC(name); \
106 DEBUGFS_WRITE_FUNC(name); \
107static const struct file_operations iwl_dbgfs_##name##_ops = { \
108 .write = iwl_dbgfs_##name##_write, \
109 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -0700110 .open = simple_open, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +0200111 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700112};
113
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700114static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
115 char __user *user_buf,
116 size_t count, loff_t *ppos) {
117
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700118 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700119 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120 int pos = 0;
121
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700122 int cnt;
123 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800124 const size_t bufsz = 100 +
125 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700126 buf = kzalloc(bufsz, GFP_KERNEL);
127 if (!buf)
128 return -ENOMEM;
129 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
130 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
131 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800132 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700133 get_mgmt_string(cnt),
134 priv->tx_stats.mgmt[cnt]);
135 }
136 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
137 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
138 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800139 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700140 get_ctrl_string(cnt),
141 priv->tx_stats.ctrl[cnt]);
142 }
143 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
144 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
145 priv->tx_stats.data_cnt);
146 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
147 priv->tx_stats.data_bytes);
148 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
149 kfree(buf);
150 return ret;
151}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700152
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800153static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700154 const char __user *user_buf,
155 size_t count, loff_t *ppos)
156{
157 struct iwl_priv *priv = file->private_data;
158 u32 clear_flag;
159 char buf[8];
160 int buf_size;
161
162 memset(buf, 0, sizeof(buf));
163 buf_size = min(count, sizeof(buf) - 1);
164 if (copy_from_user(buf, user_buf, buf_size))
165 return -EFAULT;
166 if (sscanf(buf, "%x", &clear_flag) != 1)
167 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800168 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700169
170 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700171}
172
173static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
174 char __user *user_buf,
175 size_t count, loff_t *ppos) {
176
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700177 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700178 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700179 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700180 int cnt;
181 ssize_t ret;
182 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800183 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700184 buf = kzalloc(bufsz, GFP_KERNEL);
185 if (!buf)
186 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700187
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700188 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
189 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
190 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800191 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700192 get_mgmt_string(cnt),
193 priv->rx_stats.mgmt[cnt]);
194 }
195 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
196 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
197 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800198 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700199 get_ctrl_string(cnt),
200 priv->rx_stats.ctrl[cnt]);
201 }
202 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
203 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
204 priv->rx_stats.data_cnt);
205 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
206 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700207
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700208 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
209 kfree(buf);
210 return ret;
211}
212
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700213static ssize_t iwl_dbgfs_sram_read(struct file *file,
214 char __user *user_buf,
215 size_t count, loff_t *ppos)
216{
Jay Sternberg24834d22011-01-11 15:41:00 -0800217 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800218 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700219 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800220 int i = 0;
221 bool device_format = false;
222 int offset = 0;
223 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700224 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800225 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700226 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800227 const struct fw_img *img;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800228 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700229
Johannes Berg82342812014-02-27 09:52:56 +0800230 if (!iwl_is_ready_rf(priv))
231 return -EAGAIN;
232
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800233 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800234 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
235 priv->dbgfs_sram_offset = 0x800000;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800236 if (!priv->ucode_loaded) {
237 IWL_ERR(priv, "No uCode has been loadded.\n");
238 return -EINVAL;
239 }
David Spinadel6dfa8d02012-03-10 13:00:14 -0800240 img = &priv->fw->img[priv->shrd->ucode_type];
241 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_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;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800338 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700339
340 if (!priv->wowlan_sram)
341 return -ENODATA;
342
343 return simple_read_from_buffer(user_buf, count, ppos,
344 priv->wowlan_sram,
David Spinadel6dfa8d02012-03-10 13:00:14 -0800345 img->sec[IWL_UCODE_SECTION_DATA].len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700346}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700347static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
348 size_t count, loff_t *ppos)
349{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700350 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800351 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700352 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700353 char *buf;
354 int i, j, pos = 0;
355 ssize_t ret;
356 /* Add 30 for initial string */
357 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700358
359 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300360 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700361 return -ENOMEM;
362
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700363 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700364 priv->num_stations);
365
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700366 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700367 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700368 if (!station->used)
369 continue;
370 pos += scnprintf(buf + pos, bufsz - pos,
371 "station %d - addr: %pM, flags: %#x\n",
372 i, station->sta.sta.addr,
373 station->sta.station_flags_msk);
374 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200375 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700376
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700377 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200378 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700379 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200380 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700381 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700382 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700383
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700384 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700385 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700386 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700387 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700388 }
Johannes Bergda735112010-05-03 01:25:24 -0700389
390 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700391 }
392
393 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
394 kfree(buf);
395 return ret;
396}
397
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700398static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800399 char __user *user_buf,
400 size_t count,
401 loff_t *ppos)
402{
403 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700404 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800405 int pos = 0, ofs = 0, buf_size = 0;
406 const u8 *ptr;
407 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700408 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800409 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800410 buf_size = 4 * eeprom_len + 256;
411
412 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700413 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800414 return -ENODATA;
415 }
416
Don Fryab36eab2011-11-30 15:37:32 -0800417 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200418 if (!ptr) {
419 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
420 return -ENOMEM;
421 }
422
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800423 /* 4 characters for byte 0xYY */
424 buf = kzalloc(buf_size, GFP_KERNEL);
425 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800426 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800427 return -ENOMEM;
428 }
Don Fryab36eab2011-11-30 15:37:32 -0800429 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700430 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
431 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800432 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700433 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800434 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
435 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
436 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
437 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700438 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800439 if (buf_size - pos > 0)
440 buf[pos++] = '\n';
441 }
442
443 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
444 kfree(buf);
445 return ret;
446}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700447
Winkler, Tomasd366df52008-12-02 12:14:01 -0800448static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
449 size_t count, loff_t *ppos)
450{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700451 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800452 struct ieee80211_channel *channels = NULL;
453 const struct ieee80211_supported_band *supp_band = NULL;
454 int pos = 0, i, bufsz = PAGE_SIZE;
455 char *buf;
456 ssize_t ret;
457
Don Fry83626402012-03-07 09:52:37 -0800458 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800459 return -EAGAIN;
460
461 buf = kzalloc(bufsz, GFP_KERNEL);
462 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800463 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800464 return -ENOMEM;
465 }
466
467 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700468 if (supp_band) {
469 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800470
Winkler, Tomasd366df52008-12-02 12:14:01 -0800471 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700472 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
473 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800474
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700475 for (i = 0; i < supp_band->n_channels; i++)
476 pos += scnprintf(buf + pos, bufsz - pos,
477 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700478 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700479 channels[i].max_power,
480 channels[i].flags & IEEE80211_CHAN_RADAR ?
481 " (IEEE 802.11h required)" : "",
482 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
483 || (channels[i].flags &
484 IEEE80211_CHAN_RADAR)) ? "" :
485 ", IBSS",
486 channels[i].flags &
487 IEEE80211_CHAN_PASSIVE_SCAN ?
488 "passive only" : "active/passive");
489 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800490 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700491 if (supp_band) {
492 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800493
Winkler, Tomasd366df52008-12-02 12:14:01 -0800494 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700495 "Displaying %d channels in 5.2GHz band (802.11a)\n",
496 supp_band->n_channels);
497
498 for (i = 0; i < supp_band->n_channels; i++)
499 pos += scnprintf(buf + pos, bufsz - pos,
500 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700501 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700502 channels[i].max_power,
503 channels[i].flags & IEEE80211_CHAN_RADAR ?
504 " (IEEE 802.11h required)" : "",
505 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
506 || (channels[i].flags &
507 IEEE80211_CHAN_RADAR)) ? "" :
508 ", IBSS",
509 channels[i].flags &
510 IEEE80211_CHAN_PASSIVE_SCAN ?
511 "passive only" : "active/passive");
512 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800513 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
514 kfree(buf);
515 return ret;
516}
517
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700518static ssize_t iwl_dbgfs_status_read(struct file *file,
519 char __user *user_buf,
520 size_t count, loff_t *ppos) {
521
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700522 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700523 char buf[512];
524 int pos = 0;
525 const size_t bufsz = sizeof(buf);
526
527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700528 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800530 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800532 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800534 test_bit(STATUS_ALIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800536 test_bit(STATUS_READY, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800538 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800540 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800542 test_bit(STATUS_STATISTICS, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800544 test_bit(STATUS_SCANNING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800546 test_bit(STATUS_SCAN_ABORTING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800548 test_bit(STATUS_SCAN_HW, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700550 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700552 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700553 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
554}
555
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700556static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700557 char __user *user_buf,
558 size_t count, loff_t *ppos) {
559
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700560 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700561
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700562 int pos = 0;
563 int cnt = 0;
564 char *buf;
565 int bufsz = 24 * 64; /* 24 items * 64 char per item */
566 ssize_t ret;
567
568 buf = kzalloc(bufsz, GFP_KERNEL);
569 if (!buf) {
570 IWL_ERR(priv, "Can not allocate Buffer\n");
571 return -ENOMEM;
572 }
573
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700574 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700575 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700576 pos += scnprintf(buf + pos, bufsz - pos,
577 "\tRx handler[%36s]:\t\t %u\n",
578 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700579 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700580 }
581
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700582 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
583 kfree(buf);
584 return ret;
585}
586
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700587static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700588 const char __user *user_buf,
589 size_t count, loff_t *ppos)
590{
591 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700592
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700593 char buf[8];
594 int buf_size;
595 u32 reset_flag;
596
597 memset(buf, 0, sizeof(buf));
598 buf_size = min(count, sizeof(buf) - 1);
599 if (copy_from_user(buf, user_buf, buf_size))
600 return -EFAULT;
601 if (sscanf(buf, "%x", &reset_flag) != 1)
602 return -EFAULT;
603 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700604 memset(&priv->rx_handlers_stats[0], 0,
605 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700606
607 return count;
608}
609
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700610static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
611 size_t count, loff_t *ppos)
612{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700613 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200614 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700615 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200616 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700617 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700618
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200619 for_each_context(priv, ctx) {
620 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
621 ctx->ctxid);
622 for (i = 0; i < AC_NUM; i++) {
623 pos += scnprintf(buf + pos, bufsz - pos,
624 "\tcw_min\tcw_max\taifsn\ttxop\n");
625 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700626 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200627 ctx->qos_data.def_qos_parm.ac[i].cw_min,
628 ctx->qos_data.def_qos_parm.ac[i].cw_max,
629 ctx->qos_data.def_qos_parm.ac[i].aifsn,
630 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
631 }
632 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700633 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800634 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700635}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700636
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700637static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
638 char __user *user_buf,
639 size_t count, loff_t *ppos)
640{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700641 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700642 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700643 struct iwl_tt_restriction *restriction;
644 char buf[100];
645 int pos = 0;
646 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700647
648 pos += scnprintf(buf + pos, bufsz - pos,
649 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700650 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700651 pos += scnprintf(buf + pos, bufsz - pos,
652 "Thermal Throttling State: %d\n",
653 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700654 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700655 restriction = tt->restriction + tt->state;
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "Tx mode: %d\n",
658 restriction->tx_stream);
659 pos += scnprintf(buf + pos, bufsz - pos,
660 "Rx mode: %d\n",
661 restriction->rx_stream);
662 pos += scnprintf(buf + pos, bufsz - pos,
663 "HT mode: %d\n",
664 restriction->is_ht);
665 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800666 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700667}
668
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700669static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
670 const char __user *user_buf,
671 size_t count, loff_t *ppos)
672{
673 struct iwl_priv *priv = file->private_data;
674 char buf[8];
675 int buf_size;
676 int ht40;
677
678 memset(buf, 0, sizeof(buf));
679 buf_size = min(count, sizeof(buf) - 1);
680 if (copy_from_user(buf, user_buf, buf_size))
681 return -EFAULT;
682 if (sscanf(buf, "%d", &ht40) != 1)
683 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200684 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700685 priv->disable_ht40 = ht40 ? true : false;
686 else {
687 IWL_ERR(priv, "Sta associated with AP - "
688 "Change to 40MHz channel support is not allowed\n");
689 return -EINVAL;
690 }
691
692 return count;
693}
694
695static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
696 char __user *user_buf,
697 size_t count, loff_t *ppos)
698{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700699 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700700 char buf[100];
701 int pos = 0;
702 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700703
704 pos += scnprintf(buf + pos, bufsz - pos,
705 "11n 40MHz Mode: %s\n",
706 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800707 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700708}
709
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700710static ssize_t iwl_dbgfs_temperature_read(struct file *file,
711 char __user *user_buf,
712 size_t count, loff_t *ppos)
713{
714 struct iwl_priv *priv = file->private_data;
715 char buf[8];
716 int pos = 0;
717 const size_t bufsz = sizeof(buf);
718
719 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
720 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
721}
722
723
Johannes Berge312c242009-08-07 15:41:51 -0700724static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
725 const char __user *user_buf,
726 size_t count, loff_t *ppos)
727{
728 struct iwl_priv *priv = file->private_data;
729 char buf[8];
730 int buf_size;
731 int value;
732
733 memset(buf, 0, sizeof(buf));
734 buf_size = min(count, sizeof(buf) - 1);
735 if (copy_from_user(buf, user_buf, buf_size))
736 return -EFAULT;
737
738 if (sscanf(buf, "%d", &value) != 1)
739 return -EINVAL;
740
741 /*
742 * Our users expect 0 to be "CAM", but 0 isn't actually
743 * valid here. However, let's not confuse them and present
744 * IWL_POWER_INDEX_1 as "1", not "0".
745 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700746 if (value == 0)
747 return -EINVAL;
748 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700749 value -= 1;
750
751 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
752 return -EINVAL;
753
Don Fry83626402012-03-07 09:52:37 -0800754 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700755 return -EAGAIN;
756
Johannes Berge312c242009-08-07 15:41:51 -0700757 priv->power_data.debug_sleep_level_override = value;
758
Johannes Bergb1eea292012-03-06 13:30:42 -0800759 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700760 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800761 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700762
763 return count;
764}
765
766static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
767 char __user *user_buf,
768 size_t count, loff_t *ppos)
769{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700770 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700771 char buf[10];
772 int pos, value;
773 const size_t bufsz = sizeof(buf);
774
775 /* see the write function */
776 value = priv->power_data.debug_sleep_level_override;
777 if (value >= 0)
778 value += 1;
779
780 pos = scnprintf(buf, bufsz, "%d\n", value);
781 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
782}
783
784static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
785 char __user *user_buf,
786 size_t count, loff_t *ppos)
787{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700788 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700789 char buf[200];
790 int pos = 0, i;
791 const size_t bufsz = sizeof(buf);
792 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
793
794 pos += scnprintf(buf + pos, bufsz - pos,
795 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
796 pos += scnprintf(buf + pos, bufsz - pos,
797 "RX/TX timeout: %d/%d usec\n",
798 le32_to_cpu(cmd->rx_data_timeout),
799 le32_to_cpu(cmd->tx_data_timeout));
800 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
801 pos += scnprintf(buf + pos, bufsz - pos,
802 "sleep_interval[%d]: %d\n", i,
803 le32_to_cpu(cmd->sleep_interval[i]));
804
805 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
806}
807
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700808DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700809DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700810DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700811DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800812DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700813DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700814DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700815DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700816DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700817DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700818DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700819DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
820DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700821
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700822static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
823 char __user *user_buf,
824 size_t count, loff_t *ppos)
825{
826 struct iwl_priv *priv = file->private_data;
827 int pos = 0, ofs = 0;
828 int cnt = 0, entry;
829
830 char *buf;
831 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy1745e442012-03-09 11:13:40 -0800832 (cfg(priv)->base_params->num_of_queues * 32 * 8) + 400;
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700833 const u8 *ptr;
834 ssize_t ret;
835
836 buf = kzalloc(bufsz, GFP_KERNEL);
837 if (!buf) {
838 IWL_ERR(priv, "Can not allocate buffer\n");
839 return -ENOMEM;
840 }
Johannes Berga8bceb32012-03-05 11:24:30 -0800841 if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700842 ptr = priv->tx_traffic;
843 pos += scnprintf(buf + pos, bufsz - pos,
844 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
845 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
846 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
847 entry++, ofs += 16) {
848 pos += scnprintf(buf + pos, bufsz - pos,
849 "0x%.4x ", ofs);
850 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
851 buf + pos, bufsz - pos, 0);
852 pos += strlen(buf + pos);
853 if (bufsz - pos > 0)
854 buf[pos++] = '\n';
855 }
856 }
857 }
858
Johannes Berga8bceb32012-03-05 11:24:30 -0800859 if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700860 ptr = priv->rx_traffic;
861 pos += scnprintf(buf + pos, bufsz - pos,
862 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
863 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
864 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
865 entry++, ofs += 16) {
866 pos += scnprintf(buf + pos, bufsz - pos,
867 "0x%.4x ", ofs);
868 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
869 buf + pos, bufsz - pos, 0);
870 pos += strlen(buf + pos);
871 if (bufsz - pos > 0)
872 buf[pos++] = '\n';
873 }
874 }
875 }
876
877 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
878 kfree(buf);
879 return ret;
880}
881
882static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
883 const char __user *user_buf,
884 size_t count, loff_t *ppos)
885{
886 struct iwl_priv *priv = file->private_data;
887 char buf[8];
888 int buf_size;
889 int traffic_log;
890
891 memset(buf, 0, sizeof(buf));
892 buf_size = min(count, sizeof(buf) - 1);
893 if (copy_from_user(buf, user_buf, buf_size))
894 return -EFAULT;
895 if (sscanf(buf, "%d", &traffic_log) != 1)
896 return -EFAULT;
897 if (traffic_log == 0)
898 iwl_reset_traffic_log(priv);
899
900 return count;
901}
902
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700903static const char *fmt_value = " %-30s %10u\n";
904static const char *fmt_hex = " %-30s 0x%02X\n";
905static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
906static const char *fmt_header =
907 "%-32s current cumulative delta max\n";
908
909static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
910{
911 int p = 0;
912 u32 flag;
913
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800914 lockdep_assert_held(&priv->statistics.lock);
915
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700916 flag = le32_to_cpu(priv->statistics.flag);
917
918 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
919 if (flag & UCODE_STATISTICS_CLEAR_MSK)
920 p += scnprintf(buf + p, bufsz - p,
921 "\tStatistics have been cleared\n");
922 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
923 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
924 ? "2.4 GHz" : "5.2 GHz");
925 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
926 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
927 ? "enabled" : "disabled");
928
929 return p;
930}
931
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700932static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
933 char __user *user_buf,
934 size_t count, loff_t *ppos)
935{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700936 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700937 int pos = 0;
938 char *buf;
939 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
940 sizeof(struct statistics_rx_non_phy) * 40 +
941 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
942 ssize_t ret;
943 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
944 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
945 struct statistics_rx_non_phy *general, *accum_general;
946 struct statistics_rx_non_phy *delta_general, *max_general;
947 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
948
Don Fry83626402012-03-07 09:52:37 -0800949 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700950 return -EAGAIN;
951
952 buf = kzalloc(bufsz, GFP_KERNEL);
953 if (!buf) {
954 IWL_ERR(priv, "Can not allocate Buffer\n");
955 return -ENOMEM;
956 }
957
958 /*
959 * the statistic information display here is based on
960 * the last statistics notification from uCode
961 * might not reflect the current uCode activity
962 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800963 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700964 ofdm = &priv->statistics.rx_ofdm;
965 cck = &priv->statistics.rx_cck;
966 general = &priv->statistics.rx_non_phy;
967 ht = &priv->statistics.rx_ofdm_ht;
968 accum_ofdm = &priv->accum_stats.rx_ofdm;
969 accum_cck = &priv->accum_stats.rx_cck;
970 accum_general = &priv->accum_stats.rx_non_phy;
971 accum_ht = &priv->accum_stats.rx_ofdm_ht;
972 delta_ofdm = &priv->delta_stats.rx_ofdm;
973 delta_cck = &priv->delta_stats.rx_cck;
974 delta_general = &priv->delta_stats.rx_non_phy;
975 delta_ht = &priv->delta_stats.rx_ofdm_ht;
976 max_ofdm = &priv->max_delta_stats.rx_ofdm;
977 max_cck = &priv->max_delta_stats.rx_cck;
978 max_general = &priv->max_delta_stats.rx_non_phy;
979 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
980
981 pos += iwl_statistics_flag(priv, buf, bufsz);
982 pos += scnprintf(buf + pos, bufsz - pos,
983 fmt_header, "Statistics_Rx - OFDM:");
984 pos += scnprintf(buf + pos, bufsz - pos,
985 fmt_table, "ina_cnt:",
986 le32_to_cpu(ofdm->ina_cnt),
987 accum_ofdm->ina_cnt,
988 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
989 pos += scnprintf(buf + pos, bufsz - pos,
990 fmt_table, "fina_cnt:",
991 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
992 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
993 pos += scnprintf(buf + pos, bufsz - pos,
994 fmt_table, "plcp_err:",
995 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
996 delta_ofdm->plcp_err, max_ofdm->plcp_err);
997 pos += scnprintf(buf + pos, bufsz - pos,
998 fmt_table, "crc32_err:",
999 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1000 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1001 pos += scnprintf(buf + pos, bufsz - pos,
1002 fmt_table, "overrun_err:",
1003 le32_to_cpu(ofdm->overrun_err),
1004 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1005 max_ofdm->overrun_err);
1006 pos += scnprintf(buf + pos, bufsz - pos,
1007 fmt_table, "early_overrun_err:",
1008 le32_to_cpu(ofdm->early_overrun_err),
1009 accum_ofdm->early_overrun_err,
1010 delta_ofdm->early_overrun_err,
1011 max_ofdm->early_overrun_err);
1012 pos += scnprintf(buf + pos, bufsz - pos,
1013 fmt_table, "crc32_good:",
1014 le32_to_cpu(ofdm->crc32_good),
1015 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1016 max_ofdm->crc32_good);
1017 pos += scnprintf(buf + pos, bufsz - pos,
1018 fmt_table, "false_alarm_cnt:",
1019 le32_to_cpu(ofdm->false_alarm_cnt),
1020 accum_ofdm->false_alarm_cnt,
1021 delta_ofdm->false_alarm_cnt,
1022 max_ofdm->false_alarm_cnt);
1023 pos += scnprintf(buf + pos, bufsz - pos,
1024 fmt_table, "fina_sync_err_cnt:",
1025 le32_to_cpu(ofdm->fina_sync_err_cnt),
1026 accum_ofdm->fina_sync_err_cnt,
1027 delta_ofdm->fina_sync_err_cnt,
1028 max_ofdm->fina_sync_err_cnt);
1029 pos += scnprintf(buf + pos, bufsz - pos,
1030 fmt_table, "sfd_timeout:",
1031 le32_to_cpu(ofdm->sfd_timeout),
1032 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1033 max_ofdm->sfd_timeout);
1034 pos += scnprintf(buf + pos, bufsz - pos,
1035 fmt_table, "fina_timeout:",
1036 le32_to_cpu(ofdm->fina_timeout),
1037 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1038 max_ofdm->fina_timeout);
1039 pos += scnprintf(buf + pos, bufsz - pos,
1040 fmt_table, "unresponded_rts:",
1041 le32_to_cpu(ofdm->unresponded_rts),
1042 accum_ofdm->unresponded_rts,
1043 delta_ofdm->unresponded_rts,
1044 max_ofdm->unresponded_rts);
1045 pos += scnprintf(buf + pos, bufsz - pos,
1046 fmt_table, "rxe_frame_lmt_ovrun:",
1047 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1048 accum_ofdm->rxe_frame_limit_overrun,
1049 delta_ofdm->rxe_frame_limit_overrun,
1050 max_ofdm->rxe_frame_limit_overrun);
1051 pos += scnprintf(buf + pos, bufsz - pos,
1052 fmt_table, "sent_ack_cnt:",
1053 le32_to_cpu(ofdm->sent_ack_cnt),
1054 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1055 max_ofdm->sent_ack_cnt);
1056 pos += scnprintf(buf + pos, bufsz - pos,
1057 fmt_table, "sent_cts_cnt:",
1058 le32_to_cpu(ofdm->sent_cts_cnt),
1059 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1060 max_ofdm->sent_cts_cnt);
1061 pos += scnprintf(buf + pos, bufsz - pos,
1062 fmt_table, "sent_ba_rsp_cnt:",
1063 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1064 accum_ofdm->sent_ba_rsp_cnt,
1065 delta_ofdm->sent_ba_rsp_cnt,
1066 max_ofdm->sent_ba_rsp_cnt);
1067 pos += scnprintf(buf + pos, bufsz - pos,
1068 fmt_table, "dsp_self_kill:",
1069 le32_to_cpu(ofdm->dsp_self_kill),
1070 accum_ofdm->dsp_self_kill,
1071 delta_ofdm->dsp_self_kill,
1072 max_ofdm->dsp_self_kill);
1073 pos += scnprintf(buf + pos, bufsz - pos,
1074 fmt_table, "mh_format_err:",
1075 le32_to_cpu(ofdm->mh_format_err),
1076 accum_ofdm->mh_format_err,
1077 delta_ofdm->mh_format_err,
1078 max_ofdm->mh_format_err);
1079 pos += scnprintf(buf + pos, bufsz - pos,
1080 fmt_table, "re_acq_main_rssi_sum:",
1081 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1082 accum_ofdm->re_acq_main_rssi_sum,
1083 delta_ofdm->re_acq_main_rssi_sum,
1084 max_ofdm->re_acq_main_rssi_sum);
1085
1086 pos += scnprintf(buf + pos, bufsz - pos,
1087 fmt_header, "Statistics_Rx - CCK:");
1088 pos += scnprintf(buf + pos, bufsz - pos,
1089 fmt_table, "ina_cnt:",
1090 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1091 delta_cck->ina_cnt, max_cck->ina_cnt);
1092 pos += scnprintf(buf + pos, bufsz - pos,
1093 fmt_table, "fina_cnt:",
1094 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1095 delta_cck->fina_cnt, max_cck->fina_cnt);
1096 pos += scnprintf(buf + pos, bufsz - pos,
1097 fmt_table, "plcp_err:",
1098 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1099 delta_cck->plcp_err, max_cck->plcp_err);
1100 pos += scnprintf(buf + pos, bufsz - pos,
1101 fmt_table, "crc32_err:",
1102 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1103 delta_cck->crc32_err, max_cck->crc32_err);
1104 pos += scnprintf(buf + pos, bufsz - pos,
1105 fmt_table, "overrun_err:",
1106 le32_to_cpu(cck->overrun_err),
1107 accum_cck->overrun_err, delta_cck->overrun_err,
1108 max_cck->overrun_err);
1109 pos += scnprintf(buf + pos, bufsz - pos,
1110 fmt_table, "early_overrun_err:",
1111 le32_to_cpu(cck->early_overrun_err),
1112 accum_cck->early_overrun_err,
1113 delta_cck->early_overrun_err,
1114 max_cck->early_overrun_err);
1115 pos += scnprintf(buf + pos, bufsz - pos,
1116 fmt_table, "crc32_good:",
1117 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1118 delta_cck->crc32_good, max_cck->crc32_good);
1119 pos += scnprintf(buf + pos, bufsz - pos,
1120 fmt_table, "false_alarm_cnt:",
1121 le32_to_cpu(cck->false_alarm_cnt),
1122 accum_cck->false_alarm_cnt,
1123 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 fmt_table, "fina_sync_err_cnt:",
1126 le32_to_cpu(cck->fina_sync_err_cnt),
1127 accum_cck->fina_sync_err_cnt,
1128 delta_cck->fina_sync_err_cnt,
1129 max_cck->fina_sync_err_cnt);
1130 pos += scnprintf(buf + pos, bufsz - pos,
1131 fmt_table, "sfd_timeout:",
1132 le32_to_cpu(cck->sfd_timeout),
1133 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1134 max_cck->sfd_timeout);
1135 pos += scnprintf(buf + pos, bufsz - pos,
1136 fmt_table, "fina_timeout:",
1137 le32_to_cpu(cck->fina_timeout),
1138 accum_cck->fina_timeout, delta_cck->fina_timeout,
1139 max_cck->fina_timeout);
1140 pos += scnprintf(buf + pos, bufsz - pos,
1141 fmt_table, "unresponded_rts:",
1142 le32_to_cpu(cck->unresponded_rts),
1143 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1144 max_cck->unresponded_rts);
1145 pos += scnprintf(buf + pos, bufsz - pos,
1146 fmt_table, "rxe_frame_lmt_ovrun:",
1147 le32_to_cpu(cck->rxe_frame_limit_overrun),
1148 accum_cck->rxe_frame_limit_overrun,
1149 delta_cck->rxe_frame_limit_overrun,
1150 max_cck->rxe_frame_limit_overrun);
1151 pos += scnprintf(buf + pos, bufsz - pos,
1152 fmt_table, "sent_ack_cnt:",
1153 le32_to_cpu(cck->sent_ack_cnt),
1154 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1155 max_cck->sent_ack_cnt);
1156 pos += scnprintf(buf + pos, bufsz - pos,
1157 fmt_table, "sent_cts_cnt:",
1158 le32_to_cpu(cck->sent_cts_cnt),
1159 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1160 max_cck->sent_cts_cnt);
1161 pos += scnprintf(buf + pos, bufsz - pos,
1162 fmt_table, "sent_ba_rsp_cnt:",
1163 le32_to_cpu(cck->sent_ba_rsp_cnt),
1164 accum_cck->sent_ba_rsp_cnt,
1165 delta_cck->sent_ba_rsp_cnt,
1166 max_cck->sent_ba_rsp_cnt);
1167 pos += scnprintf(buf + pos, bufsz - pos,
1168 fmt_table, "dsp_self_kill:",
1169 le32_to_cpu(cck->dsp_self_kill),
1170 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1171 max_cck->dsp_self_kill);
1172 pos += scnprintf(buf + pos, bufsz - pos,
1173 fmt_table, "mh_format_err:",
1174 le32_to_cpu(cck->mh_format_err),
1175 accum_cck->mh_format_err, delta_cck->mh_format_err,
1176 max_cck->mh_format_err);
1177 pos += scnprintf(buf + pos, bufsz - pos,
1178 fmt_table, "re_acq_main_rssi_sum:",
1179 le32_to_cpu(cck->re_acq_main_rssi_sum),
1180 accum_cck->re_acq_main_rssi_sum,
1181 delta_cck->re_acq_main_rssi_sum,
1182 max_cck->re_acq_main_rssi_sum);
1183
1184 pos += scnprintf(buf + pos, bufsz - pos,
1185 fmt_header, "Statistics_Rx - GENERAL:");
1186 pos += scnprintf(buf + pos, bufsz - pos,
1187 fmt_table, "bogus_cts:",
1188 le32_to_cpu(general->bogus_cts),
1189 accum_general->bogus_cts, delta_general->bogus_cts,
1190 max_general->bogus_cts);
1191 pos += scnprintf(buf + pos, bufsz - pos,
1192 fmt_table, "bogus_ack:",
1193 le32_to_cpu(general->bogus_ack),
1194 accum_general->bogus_ack, delta_general->bogus_ack,
1195 max_general->bogus_ack);
1196 pos += scnprintf(buf + pos, bufsz - pos,
1197 fmt_table, "non_bssid_frames:",
1198 le32_to_cpu(general->non_bssid_frames),
1199 accum_general->non_bssid_frames,
1200 delta_general->non_bssid_frames,
1201 max_general->non_bssid_frames);
1202 pos += scnprintf(buf + pos, bufsz - pos,
1203 fmt_table, "filtered_frames:",
1204 le32_to_cpu(general->filtered_frames),
1205 accum_general->filtered_frames,
1206 delta_general->filtered_frames,
1207 max_general->filtered_frames);
1208 pos += scnprintf(buf + pos, bufsz - pos,
1209 fmt_table, "non_channel_beacons:",
1210 le32_to_cpu(general->non_channel_beacons),
1211 accum_general->non_channel_beacons,
1212 delta_general->non_channel_beacons,
1213 max_general->non_channel_beacons);
1214 pos += scnprintf(buf + pos, bufsz - pos,
1215 fmt_table, "channel_beacons:",
1216 le32_to_cpu(general->channel_beacons),
1217 accum_general->channel_beacons,
1218 delta_general->channel_beacons,
1219 max_general->channel_beacons);
1220 pos += scnprintf(buf + pos, bufsz - pos,
1221 fmt_table, "num_missed_bcon:",
1222 le32_to_cpu(general->num_missed_bcon),
1223 accum_general->num_missed_bcon,
1224 delta_general->num_missed_bcon,
1225 max_general->num_missed_bcon);
1226 pos += scnprintf(buf + pos, bufsz - pos,
1227 fmt_table, "adc_rx_saturation_time:",
1228 le32_to_cpu(general->adc_rx_saturation_time),
1229 accum_general->adc_rx_saturation_time,
1230 delta_general->adc_rx_saturation_time,
1231 max_general->adc_rx_saturation_time);
1232 pos += scnprintf(buf + pos, bufsz - pos,
1233 fmt_table, "ina_detect_search_tm:",
1234 le32_to_cpu(general->ina_detection_search_time),
1235 accum_general->ina_detection_search_time,
1236 delta_general->ina_detection_search_time,
1237 max_general->ina_detection_search_time);
1238 pos += scnprintf(buf + pos, bufsz - pos,
1239 fmt_table, "beacon_silence_rssi_a:",
1240 le32_to_cpu(general->beacon_silence_rssi_a),
1241 accum_general->beacon_silence_rssi_a,
1242 delta_general->beacon_silence_rssi_a,
1243 max_general->beacon_silence_rssi_a);
1244 pos += scnprintf(buf + pos, bufsz - pos,
1245 fmt_table, "beacon_silence_rssi_b:",
1246 le32_to_cpu(general->beacon_silence_rssi_b),
1247 accum_general->beacon_silence_rssi_b,
1248 delta_general->beacon_silence_rssi_b,
1249 max_general->beacon_silence_rssi_b);
1250 pos += scnprintf(buf + pos, bufsz - pos,
1251 fmt_table, "beacon_silence_rssi_c:",
1252 le32_to_cpu(general->beacon_silence_rssi_c),
1253 accum_general->beacon_silence_rssi_c,
1254 delta_general->beacon_silence_rssi_c,
1255 max_general->beacon_silence_rssi_c);
1256 pos += scnprintf(buf + pos, bufsz - pos,
1257 fmt_table, "interference_data_flag:",
1258 le32_to_cpu(general->interference_data_flag),
1259 accum_general->interference_data_flag,
1260 delta_general->interference_data_flag,
1261 max_general->interference_data_flag);
1262 pos += scnprintf(buf + pos, bufsz - pos,
1263 fmt_table, "channel_load:",
1264 le32_to_cpu(general->channel_load),
1265 accum_general->channel_load,
1266 delta_general->channel_load,
1267 max_general->channel_load);
1268 pos += scnprintf(buf + pos, bufsz - pos,
1269 fmt_table, "dsp_false_alarms:",
1270 le32_to_cpu(general->dsp_false_alarms),
1271 accum_general->dsp_false_alarms,
1272 delta_general->dsp_false_alarms,
1273 max_general->dsp_false_alarms);
1274 pos += scnprintf(buf + pos, bufsz - pos,
1275 fmt_table, "beacon_rssi_a:",
1276 le32_to_cpu(general->beacon_rssi_a),
1277 accum_general->beacon_rssi_a,
1278 delta_general->beacon_rssi_a,
1279 max_general->beacon_rssi_a);
1280 pos += scnprintf(buf + pos, bufsz - pos,
1281 fmt_table, "beacon_rssi_b:",
1282 le32_to_cpu(general->beacon_rssi_b),
1283 accum_general->beacon_rssi_b,
1284 delta_general->beacon_rssi_b,
1285 max_general->beacon_rssi_b);
1286 pos += scnprintf(buf + pos, bufsz - pos,
1287 fmt_table, "beacon_rssi_c:",
1288 le32_to_cpu(general->beacon_rssi_c),
1289 accum_general->beacon_rssi_c,
1290 delta_general->beacon_rssi_c,
1291 max_general->beacon_rssi_c);
1292 pos += scnprintf(buf + pos, bufsz - pos,
1293 fmt_table, "beacon_energy_a:",
1294 le32_to_cpu(general->beacon_energy_a),
1295 accum_general->beacon_energy_a,
1296 delta_general->beacon_energy_a,
1297 max_general->beacon_energy_a);
1298 pos += scnprintf(buf + pos, bufsz - pos,
1299 fmt_table, "beacon_energy_b:",
1300 le32_to_cpu(general->beacon_energy_b),
1301 accum_general->beacon_energy_b,
1302 delta_general->beacon_energy_b,
1303 max_general->beacon_energy_b);
1304 pos += scnprintf(buf + pos, bufsz - pos,
1305 fmt_table, "beacon_energy_c:",
1306 le32_to_cpu(general->beacon_energy_c),
1307 accum_general->beacon_energy_c,
1308 delta_general->beacon_energy_c,
1309 max_general->beacon_energy_c);
1310
1311 pos += scnprintf(buf + pos, bufsz - pos,
1312 fmt_header, "Statistics_Rx - OFDM_HT:");
1313 pos += scnprintf(buf + pos, bufsz - pos,
1314 fmt_table, "plcp_err:",
1315 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1316 delta_ht->plcp_err, max_ht->plcp_err);
1317 pos += scnprintf(buf + pos, bufsz - pos,
1318 fmt_table, "overrun_err:",
1319 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1320 delta_ht->overrun_err, max_ht->overrun_err);
1321 pos += scnprintf(buf + pos, bufsz - pos,
1322 fmt_table, "early_overrun_err:",
1323 le32_to_cpu(ht->early_overrun_err),
1324 accum_ht->early_overrun_err,
1325 delta_ht->early_overrun_err,
1326 max_ht->early_overrun_err);
1327 pos += scnprintf(buf + pos, bufsz - pos,
1328 fmt_table, "crc32_good:",
1329 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1330 delta_ht->crc32_good, max_ht->crc32_good);
1331 pos += scnprintf(buf + pos, bufsz - pos,
1332 fmt_table, "crc32_err:",
1333 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1334 delta_ht->crc32_err, max_ht->crc32_err);
1335 pos += scnprintf(buf + pos, bufsz - pos,
1336 fmt_table, "mh_format_err:",
1337 le32_to_cpu(ht->mh_format_err),
1338 accum_ht->mh_format_err,
1339 delta_ht->mh_format_err, max_ht->mh_format_err);
1340 pos += scnprintf(buf + pos, bufsz - pos,
1341 fmt_table, "agg_crc32_good:",
1342 le32_to_cpu(ht->agg_crc32_good),
1343 accum_ht->agg_crc32_good,
1344 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1345 pos += scnprintf(buf + pos, bufsz - pos,
1346 fmt_table, "agg_mpdu_cnt:",
1347 le32_to_cpu(ht->agg_mpdu_cnt),
1348 accum_ht->agg_mpdu_cnt,
1349 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1350 pos += scnprintf(buf + pos, bufsz - pos,
1351 fmt_table, "agg_cnt:",
1352 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1353 delta_ht->agg_cnt, max_ht->agg_cnt);
1354 pos += scnprintf(buf + pos, bufsz - pos,
1355 fmt_table, "unsupport_mcs:",
1356 le32_to_cpu(ht->unsupport_mcs),
1357 accum_ht->unsupport_mcs,
1358 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1359
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001360 spin_unlock_bh(&priv->statistics.lock);
1361
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001362 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1363 kfree(buf);
1364 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001365}
1366
1367static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1368 char __user *user_buf,
1369 size_t count, loff_t *ppos)
1370{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001371 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001372 int pos = 0;
1373 char *buf;
1374 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1375 ssize_t ret;
1376 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1377
Don Fry83626402012-03-07 09:52:37 -08001378 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001379 return -EAGAIN;
1380
1381 buf = kzalloc(bufsz, GFP_KERNEL);
1382 if (!buf) {
1383 IWL_ERR(priv, "Can not allocate Buffer\n");
1384 return -ENOMEM;
1385 }
1386
1387 /* the statistic information display here is based on
1388 * the last statistics notification from uCode
1389 * might not reflect the current uCode activity
1390 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001391 spin_lock_bh(&priv->statistics.lock);
1392
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001393 tx = &priv->statistics.tx;
1394 accum_tx = &priv->accum_stats.tx;
1395 delta_tx = &priv->delta_stats.tx;
1396 max_tx = &priv->max_delta_stats.tx;
1397
1398 pos += iwl_statistics_flag(priv, buf, bufsz);
1399 pos += scnprintf(buf + pos, bufsz - pos,
1400 fmt_header, "Statistics_Tx:");
1401 pos += scnprintf(buf + pos, bufsz - pos,
1402 fmt_table, "preamble:",
1403 le32_to_cpu(tx->preamble_cnt),
1404 accum_tx->preamble_cnt,
1405 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1406 pos += scnprintf(buf + pos, bufsz - pos,
1407 fmt_table, "rx_detected_cnt:",
1408 le32_to_cpu(tx->rx_detected_cnt),
1409 accum_tx->rx_detected_cnt,
1410 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1411 pos += scnprintf(buf + pos, bufsz - pos,
1412 fmt_table, "bt_prio_defer_cnt:",
1413 le32_to_cpu(tx->bt_prio_defer_cnt),
1414 accum_tx->bt_prio_defer_cnt,
1415 delta_tx->bt_prio_defer_cnt,
1416 max_tx->bt_prio_defer_cnt);
1417 pos += scnprintf(buf + pos, bufsz - pos,
1418 fmt_table, "bt_prio_kill_cnt:",
1419 le32_to_cpu(tx->bt_prio_kill_cnt),
1420 accum_tx->bt_prio_kill_cnt,
1421 delta_tx->bt_prio_kill_cnt,
1422 max_tx->bt_prio_kill_cnt);
1423 pos += scnprintf(buf + pos, bufsz - pos,
1424 fmt_table, "few_bytes_cnt:",
1425 le32_to_cpu(tx->few_bytes_cnt),
1426 accum_tx->few_bytes_cnt,
1427 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1428 pos += scnprintf(buf + pos, bufsz - pos,
1429 fmt_table, "cts_timeout:",
1430 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1431 delta_tx->cts_timeout, max_tx->cts_timeout);
1432 pos += scnprintf(buf + pos, bufsz - pos,
1433 fmt_table, "ack_timeout:",
1434 le32_to_cpu(tx->ack_timeout),
1435 accum_tx->ack_timeout,
1436 delta_tx->ack_timeout, max_tx->ack_timeout);
1437 pos += scnprintf(buf + pos, bufsz - pos,
1438 fmt_table, "expected_ack_cnt:",
1439 le32_to_cpu(tx->expected_ack_cnt),
1440 accum_tx->expected_ack_cnt,
1441 delta_tx->expected_ack_cnt,
1442 max_tx->expected_ack_cnt);
1443 pos += scnprintf(buf + pos, bufsz - pos,
1444 fmt_table, "actual_ack_cnt:",
1445 le32_to_cpu(tx->actual_ack_cnt),
1446 accum_tx->actual_ack_cnt,
1447 delta_tx->actual_ack_cnt,
1448 max_tx->actual_ack_cnt);
1449 pos += scnprintf(buf + pos, bufsz - pos,
1450 fmt_table, "dump_msdu_cnt:",
1451 le32_to_cpu(tx->dump_msdu_cnt),
1452 accum_tx->dump_msdu_cnt,
1453 delta_tx->dump_msdu_cnt,
1454 max_tx->dump_msdu_cnt);
1455 pos += scnprintf(buf + pos, bufsz - pos,
1456 fmt_table, "abort_nxt_frame_mismatch:",
1457 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1458 accum_tx->burst_abort_next_frame_mismatch_cnt,
1459 delta_tx->burst_abort_next_frame_mismatch_cnt,
1460 max_tx->burst_abort_next_frame_mismatch_cnt);
1461 pos += scnprintf(buf + pos, bufsz - pos,
1462 fmt_table, "abort_missing_nxt_frame:",
1463 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1464 accum_tx->burst_abort_missing_next_frame_cnt,
1465 delta_tx->burst_abort_missing_next_frame_cnt,
1466 max_tx->burst_abort_missing_next_frame_cnt);
1467 pos += scnprintf(buf + pos, bufsz - pos,
1468 fmt_table, "cts_timeout_collision:",
1469 le32_to_cpu(tx->cts_timeout_collision),
1470 accum_tx->cts_timeout_collision,
1471 delta_tx->cts_timeout_collision,
1472 max_tx->cts_timeout_collision);
1473 pos += scnprintf(buf + pos, bufsz - pos,
1474 fmt_table, "ack_ba_timeout_collision:",
1475 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1476 accum_tx->ack_or_ba_timeout_collision,
1477 delta_tx->ack_or_ba_timeout_collision,
1478 max_tx->ack_or_ba_timeout_collision);
1479 pos += scnprintf(buf + pos, bufsz - pos,
1480 fmt_table, "agg ba_timeout:",
1481 le32_to_cpu(tx->agg.ba_timeout),
1482 accum_tx->agg.ba_timeout,
1483 delta_tx->agg.ba_timeout,
1484 max_tx->agg.ba_timeout);
1485 pos += scnprintf(buf + pos, bufsz - pos,
1486 fmt_table, "agg ba_resched_frames:",
1487 le32_to_cpu(tx->agg.ba_reschedule_frames),
1488 accum_tx->agg.ba_reschedule_frames,
1489 delta_tx->agg.ba_reschedule_frames,
1490 max_tx->agg.ba_reschedule_frames);
1491 pos += scnprintf(buf + pos, bufsz - pos,
1492 fmt_table, "agg scd_query_agg_frame:",
1493 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1494 accum_tx->agg.scd_query_agg_frame_cnt,
1495 delta_tx->agg.scd_query_agg_frame_cnt,
1496 max_tx->agg.scd_query_agg_frame_cnt);
1497 pos += scnprintf(buf + pos, bufsz - pos,
1498 fmt_table, "agg scd_query_no_agg:",
1499 le32_to_cpu(tx->agg.scd_query_no_agg),
1500 accum_tx->agg.scd_query_no_agg,
1501 delta_tx->agg.scd_query_no_agg,
1502 max_tx->agg.scd_query_no_agg);
1503 pos += scnprintf(buf + pos, bufsz - pos,
1504 fmt_table, "agg scd_query_agg:",
1505 le32_to_cpu(tx->agg.scd_query_agg),
1506 accum_tx->agg.scd_query_agg,
1507 delta_tx->agg.scd_query_agg,
1508 max_tx->agg.scd_query_agg);
1509 pos += scnprintf(buf + pos, bufsz - pos,
1510 fmt_table, "agg scd_query_mismatch:",
1511 le32_to_cpu(tx->agg.scd_query_mismatch),
1512 accum_tx->agg.scd_query_mismatch,
1513 delta_tx->agg.scd_query_mismatch,
1514 max_tx->agg.scd_query_mismatch);
1515 pos += scnprintf(buf + pos, bufsz - pos,
1516 fmt_table, "agg frame_not_ready:",
1517 le32_to_cpu(tx->agg.frame_not_ready),
1518 accum_tx->agg.frame_not_ready,
1519 delta_tx->agg.frame_not_ready,
1520 max_tx->agg.frame_not_ready);
1521 pos += scnprintf(buf + pos, bufsz - pos,
1522 fmt_table, "agg underrun:",
1523 le32_to_cpu(tx->agg.underrun),
1524 accum_tx->agg.underrun,
1525 delta_tx->agg.underrun, max_tx->agg.underrun);
1526 pos += scnprintf(buf + pos, bufsz - pos,
1527 fmt_table, "agg bt_prio_kill:",
1528 le32_to_cpu(tx->agg.bt_prio_kill),
1529 accum_tx->agg.bt_prio_kill,
1530 delta_tx->agg.bt_prio_kill,
1531 max_tx->agg.bt_prio_kill);
1532 pos += scnprintf(buf + pos, bufsz - pos,
1533 fmt_table, "agg rx_ba_rsp_cnt:",
1534 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1535 accum_tx->agg.rx_ba_rsp_cnt,
1536 delta_tx->agg.rx_ba_rsp_cnt,
1537 max_tx->agg.rx_ba_rsp_cnt);
1538
1539 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1540 pos += scnprintf(buf + pos, bufsz - pos,
1541 "tx power: (1/2 dB step)\n");
Johannes Berg7e79a392012-03-05 11:24:32 -08001542 if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1543 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001544 pos += scnprintf(buf + pos, bufsz - pos,
1545 fmt_hex, "antenna A:",
1546 tx->tx_power.ant_a);
Johannes Berg7e79a392012-03-05 11:24:32 -08001547 if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1548 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001549 pos += scnprintf(buf + pos, bufsz - pos,
1550 fmt_hex, "antenna B:",
1551 tx->tx_power.ant_b);
Johannes Berg7e79a392012-03-05 11:24:32 -08001552 if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1553 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001554 pos += scnprintf(buf + pos, bufsz - pos,
1555 fmt_hex, "antenna C:",
1556 tx->tx_power.ant_c);
1557 }
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001558
1559 spin_unlock_bh(&priv->statistics.lock);
1560
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001561 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1562 kfree(buf);
1563 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001564}
1565
1566static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1567 char __user *user_buf,
1568 size_t count, loff_t *ppos)
1569{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001570 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001571 int pos = 0;
1572 char *buf;
1573 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1574 ssize_t ret;
1575 struct statistics_general_common *general, *accum_general;
1576 struct statistics_general_common *delta_general, *max_general;
1577 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1578 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1579
Don Fry83626402012-03-07 09:52:37 -08001580 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001581 return -EAGAIN;
1582
1583 buf = kzalloc(bufsz, GFP_KERNEL);
1584 if (!buf) {
1585 IWL_ERR(priv, "Can not allocate Buffer\n");
1586 return -ENOMEM;
1587 }
1588
1589 /* the statistic information display here is based on
1590 * the last statistics notification from uCode
1591 * might not reflect the current uCode activity
1592 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001593
1594 spin_lock_bh(&priv->statistics.lock);
1595
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001596 general = &priv->statistics.common;
1597 dbg = &priv->statistics.common.dbg;
1598 div = &priv->statistics.common.div;
1599 accum_general = &priv->accum_stats.common;
1600 accum_dbg = &priv->accum_stats.common.dbg;
1601 accum_div = &priv->accum_stats.common.div;
1602 delta_general = &priv->delta_stats.common;
1603 max_general = &priv->max_delta_stats.common;
1604 delta_dbg = &priv->delta_stats.common.dbg;
1605 max_dbg = &priv->max_delta_stats.common.dbg;
1606 delta_div = &priv->delta_stats.common.div;
1607 max_div = &priv->max_delta_stats.common.div;
1608
1609 pos += iwl_statistics_flag(priv, buf, bufsz);
1610 pos += scnprintf(buf + pos, bufsz - pos,
1611 fmt_header, "Statistics_General:");
1612 pos += scnprintf(buf + pos, bufsz - pos,
1613 fmt_value, "temperature:",
1614 le32_to_cpu(general->temperature));
1615 pos += scnprintf(buf + pos, bufsz - pos,
1616 fmt_value, "temperature_m:",
1617 le32_to_cpu(general->temperature_m));
1618 pos += scnprintf(buf + pos, bufsz - pos,
1619 fmt_value, "ttl_timestamp:",
1620 le32_to_cpu(general->ttl_timestamp));
1621 pos += scnprintf(buf + pos, bufsz - pos,
1622 fmt_table, "burst_check:",
1623 le32_to_cpu(dbg->burst_check),
1624 accum_dbg->burst_check,
1625 delta_dbg->burst_check, max_dbg->burst_check);
1626 pos += scnprintf(buf + pos, bufsz - pos,
1627 fmt_table, "burst_count:",
1628 le32_to_cpu(dbg->burst_count),
1629 accum_dbg->burst_count,
1630 delta_dbg->burst_count, max_dbg->burst_count);
1631 pos += scnprintf(buf + pos, bufsz - pos,
1632 fmt_table, "wait_for_silence_timeout_count:",
1633 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1634 accum_dbg->wait_for_silence_timeout_cnt,
1635 delta_dbg->wait_for_silence_timeout_cnt,
1636 max_dbg->wait_for_silence_timeout_cnt);
1637 pos += scnprintf(buf + pos, bufsz - pos,
1638 fmt_table, "sleep_time:",
1639 le32_to_cpu(general->sleep_time),
1640 accum_general->sleep_time,
1641 delta_general->sleep_time, max_general->sleep_time);
1642 pos += scnprintf(buf + pos, bufsz - pos,
1643 fmt_table, "slots_out:",
1644 le32_to_cpu(general->slots_out),
1645 accum_general->slots_out,
1646 delta_general->slots_out, max_general->slots_out);
1647 pos += scnprintf(buf + pos, bufsz - pos,
1648 fmt_table, "slots_idle:",
1649 le32_to_cpu(general->slots_idle),
1650 accum_general->slots_idle,
1651 delta_general->slots_idle, max_general->slots_idle);
1652 pos += scnprintf(buf + pos, bufsz - pos,
1653 fmt_table, "tx_on_a:",
1654 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1655 delta_div->tx_on_a, max_div->tx_on_a);
1656 pos += scnprintf(buf + pos, bufsz - pos,
1657 fmt_table, "tx_on_b:",
1658 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1659 delta_div->tx_on_b, max_div->tx_on_b);
1660 pos += scnprintf(buf + pos, bufsz - pos,
1661 fmt_table, "exec_time:",
1662 le32_to_cpu(div->exec_time), accum_div->exec_time,
1663 delta_div->exec_time, max_div->exec_time);
1664 pos += scnprintf(buf + pos, bufsz - pos,
1665 fmt_table, "probe_time:",
1666 le32_to_cpu(div->probe_time), accum_div->probe_time,
1667 delta_div->probe_time, max_div->probe_time);
1668 pos += scnprintf(buf + pos, bufsz - pos,
1669 fmt_table, "rx_enable_counter:",
1670 le32_to_cpu(general->rx_enable_counter),
1671 accum_general->rx_enable_counter,
1672 delta_general->rx_enable_counter,
1673 max_general->rx_enable_counter);
1674 pos += scnprintf(buf + pos, bufsz - pos,
1675 fmt_table, "num_of_sos_states:",
1676 le32_to_cpu(general->num_of_sos_states),
1677 accum_general->num_of_sos_states,
1678 delta_general->num_of_sos_states,
1679 max_general->num_of_sos_states);
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001680
1681 spin_unlock_bh(&priv->statistics.lock);
1682
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001683 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1684 kfree(buf);
1685 return ret;
1686}
1687
1688static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1689 char __user *user_buf,
1690 size_t count, loff_t *ppos)
1691{
1692 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1693 int pos = 0;
1694 char *buf;
1695 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1696 ssize_t ret;
1697 struct statistics_bt_activity *bt, *accum_bt;
1698
Don Fry83626402012-03-07 09:52:37 -08001699 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001700 return -EAGAIN;
1701
1702 if (!priv->bt_enable_flag)
1703 return -EINVAL;
1704
1705 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001706 mutex_lock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001707 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001708 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001709
1710 if (ret) {
1711 IWL_ERR(priv,
1712 "Error sending statistics request: %zd\n", ret);
1713 return -EAGAIN;
1714 }
1715 buf = kzalloc(bufsz, GFP_KERNEL);
1716 if (!buf) {
1717 IWL_ERR(priv, "Can not allocate Buffer\n");
1718 return -ENOMEM;
1719 }
1720
1721 /*
1722 * the statistic information display here is based on
1723 * the last statistics notification from uCode
1724 * might not reflect the current uCode activity
1725 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001726
1727 spin_lock_bh(&priv->statistics.lock);
1728
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001729 bt = &priv->statistics.bt_activity;
1730 accum_bt = &priv->accum_stats.bt_activity;
1731
1732 pos += iwl_statistics_flag(priv, buf, bufsz);
1733 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1734 pos += scnprintf(buf + pos, bufsz - pos,
1735 "\t\t\tcurrent\t\t\taccumulative\n");
1736 pos += scnprintf(buf + pos, bufsz - pos,
1737 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1738 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1739 accum_bt->hi_priority_tx_req_cnt);
1740 pos += scnprintf(buf + pos, bufsz - pos,
1741 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1742 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1743 accum_bt->hi_priority_tx_denied_cnt);
1744 pos += scnprintf(buf + pos, bufsz - pos,
1745 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1746 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1747 accum_bt->lo_priority_tx_req_cnt);
1748 pos += scnprintf(buf + pos, bufsz - pos,
1749 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1750 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1751 accum_bt->lo_priority_tx_denied_cnt);
1752 pos += scnprintf(buf + pos, bufsz - pos,
1753 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1754 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1755 accum_bt->hi_priority_rx_req_cnt);
1756 pos += scnprintf(buf + pos, bufsz - pos,
1757 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1758 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1759 accum_bt->hi_priority_rx_denied_cnt);
1760 pos += scnprintf(buf + pos, bufsz - pos,
1761 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1762 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1763 accum_bt->lo_priority_rx_req_cnt);
1764 pos += scnprintf(buf + pos, bufsz - pos,
1765 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1766 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1767 accum_bt->lo_priority_rx_denied_cnt);
1768
1769 pos += scnprintf(buf + pos, bufsz - pos,
1770 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1771 le32_to_cpu(priv->statistics.num_bt_kills),
1772 priv->statistics.accum_num_bt_kills);
1773
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001774 spin_unlock_bh(&priv->statistics.lock);
1775
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001776 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1777 kfree(buf);
1778 return ret;
1779}
1780
1781static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1782 char __user *user_buf,
1783 size_t count, loff_t *ppos)
1784{
1785 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1786 int pos = 0;
1787 char *buf;
1788 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1789 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1790 ssize_t ret;
1791
Don Fry83626402012-03-07 09:52:37 -08001792 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001793 return -EAGAIN;
1794
1795 buf = kzalloc(bufsz, GFP_KERNEL);
1796 if (!buf) {
1797 IWL_ERR(priv, "Can not allocate Buffer\n");
1798 return -ENOMEM;
1799 }
1800
1801 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1802 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1803 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001804 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001805 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1806 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001807 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001808 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1809 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001810 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001811 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1812 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001813 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001814 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1815 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001816 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001817 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1818 iwl_get_tx_fail_reason(
1819 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001820 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001821 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1822 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001823 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001824 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1825 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001826 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001827 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1828 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001829 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001830 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1831 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001832 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001833 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1834 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001835 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001836 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1837 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001838 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001839 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1840 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001841 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001842 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1843 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001844 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001845 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1846 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001847 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001848 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1849 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001851 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1852 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001853 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001854 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1855 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001856 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001857 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1858 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001859 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001860 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1861 iwl_get_tx_fail_reason(
1862 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001863 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001864 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1865 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001866 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001867 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1868 iwl_get_tx_fail_reason(
1869 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001870 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001871 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001872 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001873
1874 pos += scnprintf(buf + pos, bufsz - pos,
1875 "\nStatistics_Agg_TX_Error:\n");
1876
1877 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1878 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001879 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001880 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1881 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001882 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001883 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1884 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001885 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001886 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1887 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001888 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001889 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1890 iwl_get_agg_tx_fail_reason(
1891 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001892 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001893 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1894 iwl_get_agg_tx_fail_reason(
1895 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001896 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001897 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1898 iwl_get_agg_tx_fail_reason(
1899 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001900 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001901 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1902 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001903 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001904 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1905 iwl_get_agg_tx_fail_reason(
1906 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001907 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001908 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1909 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001910 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001911 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1912 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001913 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001914 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1915 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001916 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001917 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001918 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001919
1920 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1921 kfree(buf);
1922 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001923}
1924
Wey-Yi Guy52259352009-08-07 15:41:43 -07001925static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1926 char __user *user_buf,
1927 size_t count, loff_t *ppos) {
1928
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001929 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001930 int pos = 0;
1931 int cnt = 0;
1932 char *buf;
1933 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1934 ssize_t ret;
1935 struct iwl_sensitivity_data *data;
1936
1937 data = &priv->sensitivity_data;
1938 buf = kzalloc(bufsz, GFP_KERNEL);
1939 if (!buf) {
1940 IWL_ERR(priv, "Can not allocate Buffer\n");
1941 return -ENOMEM;
1942 }
1943
1944 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1945 data->auto_corr_ofdm);
1946 pos += scnprintf(buf + pos, bufsz - pos,
1947 "auto_corr_ofdm_mrc:\t\t %u\n",
1948 data->auto_corr_ofdm_mrc);
1949 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1950 data->auto_corr_ofdm_x1);
1951 pos += scnprintf(buf + pos, bufsz - pos,
1952 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1953 data->auto_corr_ofdm_mrc_x1);
1954 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1955 data->auto_corr_cck);
1956 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1957 data->auto_corr_cck_mrc);
1958 pos += scnprintf(buf + pos, bufsz - pos,
1959 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1960 data->last_bad_plcp_cnt_ofdm);
1961 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1962 data->last_fa_cnt_ofdm);
1963 pos += scnprintf(buf + pos, bufsz - pos,
1964 "last_bad_plcp_cnt_cck:\t\t %u\n",
1965 data->last_bad_plcp_cnt_cck);
1966 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1967 data->last_fa_cnt_cck);
1968 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1969 data->nrg_curr_state);
1970 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1971 data->nrg_prev_state);
1972 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1973 for (cnt = 0; cnt < 10; cnt++) {
1974 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1975 data->nrg_value[cnt]);
1976 }
1977 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1978 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1979 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1980 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1981 data->nrg_silence_rssi[cnt]);
1982 }
1983 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1984 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1985 data->nrg_silence_ref);
1986 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1987 data->nrg_energy_idx);
1988 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1989 data->nrg_silence_idx);
1990 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1991 data->nrg_th_cck);
1992 pos += scnprintf(buf + pos, bufsz - pos,
1993 "nrg_auto_corr_silence_diff:\t %u\n",
1994 data->nrg_auto_corr_silence_diff);
1995 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1996 data->num_in_cck_no_fa);
1997 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1998 data->nrg_th_ofdm);
1999
2000 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2001 kfree(buf);
2002 return ret;
2003}
2004
2005
2006static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2007 char __user *user_buf,
2008 size_t count, loff_t *ppos) {
2009
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002010 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002011 int pos = 0;
2012 int cnt = 0;
2013 char *buf;
2014 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2015 ssize_t ret;
2016 struct iwl_chain_noise_data *data;
2017
2018 data = &priv->chain_noise_data;
2019 buf = kzalloc(bufsz, GFP_KERNEL);
2020 if (!buf) {
2021 IWL_ERR(priv, "Can not allocate Buffer\n");
2022 return -ENOMEM;
2023 }
2024
2025 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2026 data->active_chains);
2027 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2028 data->chain_noise_a);
2029 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2030 data->chain_noise_b);
2031 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2032 data->chain_noise_c);
2033 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2034 data->chain_signal_a);
2035 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2036 data->chain_signal_b);
2037 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2038 data->chain_signal_c);
2039 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2040 data->beacon_count);
2041
2042 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2043 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2044 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2045 data->disconn_array[cnt]);
2046 }
2047 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2048 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2049 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2050 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2051 data->delta_gain_code[cnt]);
2052 }
2053 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2054 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2055 data->radio_write);
2056 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2057 data->state);
2058
2059 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2060 kfree(buf);
2061 return ret;
2062}
2063
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002064static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2065 char __user *user_buf,
2066 size_t count, loff_t *ppos)
2067{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002068 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002069 char buf[60];
2070 int pos = 0;
2071 const size_t bufsz = sizeof(buf);
2072 u32 pwrsave_status;
2073
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002074 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002075 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2076
2077 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2078 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2079 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2080 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2081 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2082 "error");
2083
2084 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2085}
2086
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002087static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002088 const char __user *user_buf,
2089 size_t count, loff_t *ppos)
2090{
2091 struct iwl_priv *priv = file->private_data;
2092 char buf[8];
2093 int buf_size;
2094 int clear;
2095
2096 memset(buf, 0, sizeof(buf));
2097 buf_size = min(count, sizeof(buf) - 1);
2098 if (copy_from_user(buf, user_buf, buf_size))
2099 return -EFAULT;
2100 if (sscanf(buf, "%d", &clear) != 1)
2101 return -EFAULT;
2102
2103 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08002104 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002105 iwl_send_statistics_request(priv, CMD_SYNC, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08002106 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002107
2108 return count;
2109}
2110
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002111static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2112 char __user *user_buf,
2113 size_t count, loff_t *ppos) {
2114
Joe Perches57674302010-07-12 13:50:06 -07002115 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002116 int pos = 0;
2117 char buf[128];
2118 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002119
2120 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2121 priv->event_log.ucode_trace ? "On" : "Off");
2122 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2123 priv->event_log.non_wraps_count);
2124 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2125 priv->event_log.wraps_once_count);
2126 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2127 priv->event_log.wraps_more_count);
2128
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002129 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002130}
2131
2132static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2133 const char __user *user_buf,
2134 size_t count, loff_t *ppos)
2135{
2136 struct iwl_priv *priv = file->private_data;
2137 char buf[8];
2138 int buf_size;
2139 int trace;
2140
2141 memset(buf, 0, sizeof(buf));
2142 buf_size = min(count, sizeof(buf) - 1);
2143 if (copy_from_user(buf, user_buf, buf_size))
2144 return -EFAULT;
2145 if (sscanf(buf, "%d", &trace) != 1)
2146 return -EFAULT;
2147
2148 if (trace) {
2149 priv->event_log.ucode_trace = true;
Don Fry83626402012-03-07 09:52:37 -08002150 if (iwl_is_alive(priv)) {
Johannes Berg98d4bf02012-01-13 11:56:11 +01002151 /* start collecting data now */
2152 mod_timer(&priv->ucode_trace, jiffies);
2153 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002154 } else {
2155 priv->event_log.ucode_trace = false;
2156 del_timer_sync(&priv->ucode_trace);
2157 }
2158
2159 return count;
2160}
2161
Johannes Berg60987202010-02-18 00:36:07 -08002162static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2163 char __user *user_buf,
2164 size_t count, loff_t *ppos) {
2165
Joe Perches57674302010-07-12 13:50:06 -07002166 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002167 int len = 0;
2168 char buf[20];
2169
Johannes Berg246ed352010-08-23 10:46:32 +02002170 len = sprintf(buf, "0x%04X\n",
2171 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002172 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2173}
2174
2175static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2176 char __user *user_buf,
2177 size_t count, loff_t *ppos) {
2178
Joe Perches57674302010-07-12 13:50:06 -07002179 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002180 int len = 0;
2181 char buf[20];
2182
2183 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002184 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002185 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2186}
2187
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002188static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2189 char __user *user_buf,
2190 size_t count, loff_t *ppos) {
2191
2192 struct iwl_priv *priv = file->private_data;
2193 int pos = 0;
2194 char buf[12];
2195 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002196
2197 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2198 priv->missed_beacon_threshold);
2199
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002200 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002201}
2202
2203static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2204 const char __user *user_buf,
2205 size_t count, loff_t *ppos)
2206{
2207 struct iwl_priv *priv = file->private_data;
2208 char buf[8];
2209 int buf_size;
2210 int missed;
2211
2212 memset(buf, 0, sizeof(buf));
2213 buf_size = min(count, sizeof(buf) - 1);
2214 if (copy_from_user(buf, user_buf, buf_size))
2215 return -EFAULT;
2216 if (sscanf(buf, "%d", &missed) != 1)
2217 return -EINVAL;
2218
2219 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2220 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2221 priv->missed_beacon_threshold =
2222 IWL_MISSED_BEACON_THRESHOLD_DEF;
2223 else
2224 priv->missed_beacon_threshold = missed;
2225
2226 return count;
2227}
2228
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002229static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2230 char __user *user_buf,
2231 size_t count, loff_t *ppos) {
2232
Joe Perches57674302010-07-12 13:50:06 -07002233 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002234 int pos = 0;
2235 char buf[12];
2236 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002237
2238 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002239 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002240
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002241 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002242}
2243
2244static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2245 const char __user *user_buf,
2246 size_t count, loff_t *ppos) {
2247
2248 struct iwl_priv *priv = file->private_data;
2249 char buf[8];
2250 int buf_size;
2251 int plcp;
2252
2253 memset(buf, 0, sizeof(buf));
2254 buf_size = min(count, sizeof(buf) - 1);
2255 if (copy_from_user(buf, user_buf, buf_size))
2256 return -EFAULT;
2257 if (sscanf(buf, "%d", &plcp) != 1)
2258 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002259 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002260 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002261 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002262 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002263 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002264 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002265 return count;
2266}
2267
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002268static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2269 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002270 size_t count, loff_t *ppos)
2271{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002272 struct iwl_priv *priv = file->private_data;
2273 int i, pos = 0;
2274 char buf[300];
2275 const size_t bufsz = sizeof(buf);
2276 struct iwl_force_reset *force_reset;
2277
2278 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2279 force_reset = &priv->force_reset[i];
2280 pos += scnprintf(buf + pos, bufsz - pos,
2281 "Force reset method %d\n", i);
2282 pos += scnprintf(buf + pos, bufsz - pos,
2283 "\tnumber of reset request: %d\n",
2284 force_reset->reset_request_count);
2285 pos += scnprintf(buf + pos, bufsz - pos,
2286 "\tnumber of reset request success: %d\n",
2287 force_reset->reset_success_count);
2288 pos += scnprintf(buf + pos, bufsz - pos,
2289 "\tnumber of reset request reject: %d\n",
2290 force_reset->reset_reject_count);
2291 pos += scnprintf(buf + pos, bufsz - pos,
2292 "\treset duration: %lu\n",
2293 force_reset->reset_duration);
2294 }
2295 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2296}
2297
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002298static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2299 const char __user *user_buf,
2300 size_t count, loff_t *ppos) {
2301
2302 struct iwl_priv *priv = file->private_data;
2303 char buf[8];
2304 int buf_size;
2305 int reset, ret;
2306
2307 memset(buf, 0, sizeof(buf));
2308 buf_size = min(count, sizeof(buf) - 1);
2309 if (copy_from_user(buf, user_buf, buf_size))
2310 return -EFAULT;
2311 if (sscanf(buf, "%d", &reset) != 1)
2312 return -EINVAL;
2313 switch (reset) {
2314 case IWL_RF_RESET:
2315 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002316 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002317 break;
2318 default:
2319 return -EINVAL;
2320 }
2321 return ret ? ret : count;
2322}
2323
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002324static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2325 const char __user *user_buf,
2326 size_t count, loff_t *ppos) {
2327
2328 struct iwl_priv *priv = file->private_data;
2329 char buf[8];
2330 int buf_size;
2331 int flush;
2332
2333 memset(buf, 0, sizeof(buf));
2334 buf_size = min(count, sizeof(buf) - 1);
2335 if (copy_from_user(buf, user_buf, buf_size))
2336 return -EFAULT;
2337 if (sscanf(buf, "%d", &flush) != 1)
2338 return -EINVAL;
2339
Don Fry83626402012-03-07 09:52:37 -08002340 if (iwl_is_rfkill(priv))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002341 return -EFAULT;
2342
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002343 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002344
2345 return count;
2346}
2347
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002348static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002349 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002350 size_t count, loff_t *ppos)
2351{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002352 struct iwl_priv *priv = file->private_data;
2353 char buf[8];
2354 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002355 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002356
2357 memset(buf, 0, sizeof(buf));
2358 buf_size = min(count, sizeof(buf) - 1);
2359 if (copy_from_user(buf, user_buf, buf_size))
2360 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002361 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002362 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002363 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2364 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002365
Johannes Berge7a09432012-03-06 13:30:54 -08002366 hw_params(priv).wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002367 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002368 return count;
2369}
2370
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002371static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2372 char __user *user_buf,
2373 size_t count, loff_t *ppos) {
2374
2375 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2376 int pos = 0;
2377 char buf[200];
2378 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002379
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002380 if (!priv->bt_enable_flag) {
2381 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002382 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002383 }
2384 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2385 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002386 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2387 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2388 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2389 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002390 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002391 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002392 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2393 priv->bt_ch_announce, priv->kill_ack_mask,
2394 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002395
2396 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2397 switch (priv->bt_traffic_load) {
2398 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2399 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2400 break;
2401 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2402 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2403 break;
2404 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2405 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2406 break;
2407 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2408 default:
2409 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2410 break;
2411 }
2412
Johannes Berg08960de2011-04-05 09:41:53 -07002413 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002414}
2415
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002416static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2417 char __user *user_buf,
2418 size_t count, loff_t *ppos)
2419{
2420 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2421
2422 int pos = 0;
2423 char buf[40];
2424 const size_t bufsz = sizeof(buf);
2425
Don Fry38622412011-12-16 07:07:36 -08002426 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002427 pos += scnprintf(buf + pos, bufsz - pos,
2428 "use %s for aggregation\n",
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002429 (hw_params(priv).use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002430 "rts/cts" : "cts-to-self");
2431 else
2432 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2433
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002434 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2435}
2436
2437static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2438 const char __user *user_buf,
2439 size_t count, loff_t *ppos) {
2440
2441 struct iwl_priv *priv = file->private_data;
2442 char buf[8];
2443 int buf_size;
2444 int rts;
2445
Don Fry38622412011-12-16 07:07:36 -08002446 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002447 return -EINVAL;
2448
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002449 memset(buf, 0, sizeof(buf));
2450 buf_size = min(count, sizeof(buf) - 1);
2451 if (copy_from_user(buf, user_buf, buf_size))
2452 return -EFAULT;
2453 if (sscanf(buf, "%d", &rts) != 1)
2454 return -EINVAL;
2455 if (rts)
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002456 hw_params(priv).use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002457 else
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002458 hw_params(priv).use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002459 return count;
2460}
2461
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002462static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2463 const char __user *user_buf,
2464 size_t count, loff_t *ppos)
2465{
2466 struct iwl_priv *priv = file->private_data;
2467 char buf[8];
2468 int buf_size;
2469
2470 memset(buf, 0, sizeof(buf));
2471 buf_size = min(count, sizeof(buf) - 1);
2472 if (copy_from_user(buf, user_buf, buf_size))
2473 return -EFAULT;
2474
2475 iwl_cmd_echo_test(priv);
2476 return count;
2477}
2478
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002479DEBUGFS_READ_FILE_OPS(rx_statistics);
2480DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002481DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002482DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2483DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2484DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002485DEBUGFS_READ_FILE_OPS(sensitivity);
2486DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002487DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002488DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2489DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002490DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002491DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002492DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002493DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002494DEBUGFS_READ_FILE_OPS(rxon_flags);
2495DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002496DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002497DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002498DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002499DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002500DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002501DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002502DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002503
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002504/*
2505 * Create the debugfs files and directories
2506 *
2507 */
2508int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2509{
Zhu Yi95b1a822008-05-29 16:34:50 +08002510 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002511 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002512
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002513 dir_drv = debugfs_create_dir(name, phyd);
2514 if (!dir_drv)
2515 return -ENOMEM;
2516
2517 priv->debugfs_dir = dir_drv;
2518
2519 dir_data = debugfs_create_dir("data", dir_drv);
2520 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002521 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002522 dir_rf = debugfs_create_dir("rf", dir_drv);
2523 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002524 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002525 dir_debug = debugfs_create_dir("debug", dir_drv);
2526 if (!dir_debug)
2527 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002528
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002529 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2530 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002531 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002532 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2533 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2534 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002535 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002536 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002537 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2538 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002539 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2540 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002541 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002542
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002543 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2544 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002545 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002546 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2547 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2548 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002549 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002550 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002551 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002552 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2553 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2554 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002555 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002556 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002557 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2558 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002559 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002560 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002561 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002562 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2563 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002564 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002565 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002566 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002567 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002568
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002569 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2570 &priv->disable_sens_cal);
2571 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2572 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002573
2574 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2575 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002576 return 0;
2577
2578err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002579 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002580 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002581 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002582}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002583
2584/**
2585 * Remove the debugfs files and directories
2586 *
2587 */
2588void iwl_dbgfs_unregister(struct iwl_priv *priv)
2589{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002590 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002591 return;
2592
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002593 debugfs_remove_recursive(priv->debugfs_dir);
2594 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002595}