blob: 89cb9a7a3b56e8a384e39395dd1383b2d220c550 [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08005 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Tomas Winkler712b6cf2008-03-12 16:58:52 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h>
35#include <net/mac80211.h>
36
37
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070039#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070040#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070041#include "iwl-io.h"
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -070042#include "iwl-agn.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070043
44/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080045#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
46 if (!debugfs_create_file(#name, mode, parent, priv, \
47 &iwl_dbgfs_##name##_ops)) \
48 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070049} while (0)
50
Johannes Berg4c84a8f2010-01-22 14:22:54 -080051#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
52 struct dentry *__tmp; \
53 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
54 parent, ptr); \
55 if (IS_ERR(__tmp) || !__tmp) \
56 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070057} while (0)
58
Johannes Berg4c84a8f2010-01-22 14:22:54 -080059#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
60 struct dentry *__tmp; \
61 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
62 parent, ptr); \
63 if (IS_ERR(__tmp) || !__tmp) \
64 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080065} while (0)
66
Johannes Bergca934b62011-09-15 11:46:48 -070067#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
68 struct dentry *__tmp; \
69 __tmp = debugfs_create_u32(#name, mode, \
70 parent, ptr); \
71 if (IS_ERR(__tmp) || !__tmp) \
72 goto err; \
73} while (0)
74
Tomas Winkler712b6cf2008-03-12 16:58:52 -070075/* file operation */
76#define DEBUGFS_READ_FUNC(name) \
77static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
78 char __user *user_buf, \
79 size_t count, loff_t *ppos);
80
81#define DEBUGFS_WRITE_FUNC(name) \
82static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
83 const char __user *user_buf, \
84 size_t count, loff_t *ppos);
85
86
87static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
88{
89 file->private_data = inode->i_private;
90 return 0;
91}
92
93#define DEBUGFS_READ_FILE_OPS(name) \
94 DEBUGFS_READ_FUNC(name); \
95static const struct file_operations iwl_dbgfs_##name##_ops = { \
96 .read = iwl_dbgfs_##name##_read, \
97 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020098 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070099};
100
Ester Kummer189a2b52008-05-15 13:54:18 +0800101#define DEBUGFS_WRITE_FILE_OPS(name) \
102 DEBUGFS_WRITE_FUNC(name); \
103static const struct file_operations iwl_dbgfs_##name##_ops = { \
104 .write = iwl_dbgfs_##name##_write, \
105 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200106 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800107};
108
109
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700110#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
111 DEBUGFS_READ_FUNC(name); \
112 DEBUGFS_WRITE_FUNC(name); \
113static const struct file_operations iwl_dbgfs_##name##_ops = { \
114 .write = iwl_dbgfs_##name##_write, \
115 .read = iwl_dbgfs_##name##_read, \
116 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200117 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700118};
119
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
121 char __user *user_buf,
122 size_t count, loff_t *ppos) {
123
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700124 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700125 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700126 int pos = 0;
127
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700128 int cnt;
129 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800130 const size_t bufsz = 100 +
131 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700132 buf = kzalloc(bufsz, GFP_KERNEL);
133 if (!buf)
134 return -ENOMEM;
135 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
136 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
137 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800138 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700139 get_mgmt_string(cnt),
140 priv->tx_stats.mgmt[cnt]);
141 }
142 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
143 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
144 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800145 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700146 get_ctrl_string(cnt),
147 priv->tx_stats.ctrl[cnt]);
148 }
149 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
150 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
151 priv->tx_stats.data_cnt);
152 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
153 priv->tx_stats.data_bytes);
154 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
155 kfree(buf);
156 return ret;
157}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700158
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800159static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700160 const char __user *user_buf,
161 size_t count, loff_t *ppos)
162{
163 struct iwl_priv *priv = file->private_data;
164 u32 clear_flag;
165 char buf[8];
166 int buf_size;
167
168 memset(buf, 0, sizeof(buf));
169 buf_size = min(count, sizeof(buf) - 1);
170 if (copy_from_user(buf, user_buf, buf_size))
171 return -EFAULT;
172 if (sscanf(buf, "%x", &clear_flag) != 1)
173 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800174 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700175
176 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700177}
178
179static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
180 char __user *user_buf,
181 size_t count, loff_t *ppos) {
182
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700183 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700184 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700185 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700186 int cnt;
187 ssize_t ret;
188 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800189 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700190 buf = kzalloc(bufsz, GFP_KERNEL);
191 if (!buf)
192 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700193
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700194 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
195 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
196 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800197 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700198 get_mgmt_string(cnt),
199 priv->rx_stats.mgmt[cnt]);
200 }
201 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
202 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
203 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800204 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700205 get_ctrl_string(cnt),
206 priv->rx_stats.ctrl[cnt]);
207 }
208 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
209 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
210 priv->rx_stats.data_cnt);
211 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
212 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700213
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700214 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
215 kfree(buf);
216 return ret;
217}
218
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700219static ssize_t iwl_dbgfs_sram_read(struct file *file,
220 char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
Jay Sternberg24834d22011-01-11 15:41:00 -0800223 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800224 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700225 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800226 int i = 0;
227 bool device_format = false;
228 int offset = 0;
229 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700230 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800231 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700232 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800233 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700234
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800235 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800236 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
237 priv->dbgfs_sram_offset = 0x800000;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800238 if (!priv->ucode_loaded) {
239 IWL_ERR(priv, "No uCode has been loadded.\n");
240 return -EINVAL;
241 }
242 if (priv->shrd->ucode_type == IWL_UCODE_INIT) {
Johannes Berg0692fe42012-03-06 13:30:37 -0800243 priv->dbgfs_sram_len = priv->fw->ucode_init.data.len;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800244 } else if (priv->shrd->ucode_type == IWL_UCODE_REGULAR) {
Johannes Berg0692fe42012-03-06 13:30:37 -0800245 priv->dbgfs_sram_len = priv->fw->ucode_rt.data.len;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800246 } else if (priv->shrd->ucode_type == IWL_UCODE_WOWLAN) {
247 priv->dbgfs_sram_len = priv->fw->ucode_wowlan.data.len;
248 } else {
249 IWL_ERR(priv, "Unsupported type of uCode loaded?"
250 " that shouldn't happen.\n");
251 return -EINVAL;
252 }
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800253 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800254 len = priv->dbgfs_sram_len;
255
256 if (len == -4) {
257 device_format = true;
258 len = 4;
259 }
260
261 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800262 buf = kmalloc(bufsz, GFP_KERNEL);
263 if (!buf)
264 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800265
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800266 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800267 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800268 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800269 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800270
271 /* adjust sram address since reads are only on even u32 boundaries */
272 offset = priv->dbgfs_sram_offset & 0x3;
273 sram = priv->dbgfs_sram_offset & ~0x3;
274
275 /* read the first u32 from sram */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200276 val = iwl_read_targ_mem(trans(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800277
278 for (; len; len--) {
279 /* put the address at the start of every line */
280 if (i == 0)
281 pos += scnprintf(buf + pos, bufsz - pos,
282 "%08X: ", sram + offset);
283
284 if (device_format)
285 pos += scnprintf(buf + pos, bufsz - pos,
286 "%02x", (val >> (8 * (3 - offset))) & 0xff);
287 else
288 pos += scnprintf(buf + pos, bufsz - pos,
289 "%02x ", (val >> (8 * offset)) & 0xff);
290
291 /* if all bytes processed, read the next u32 from sram */
292 if (++offset == 4) {
293 sram += 4;
294 offset = 0;
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200295 val = iwl_read_targ_mem(trans(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700296 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800297
298 /* put in extra spaces and split lines for human readability */
299 if (++i == 16) {
300 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800301 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800302 } else if (!(i & 7)) {
303 pos += scnprintf(buf + pos, bufsz - pos, " ");
304 } else if (!(i & 3)) {
305 pos += scnprintf(buf + pos, bufsz - pos, " ");
306 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700307 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800308 if (i)
309 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700310
311 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800312 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700313 return ret;
314}
315
316static ssize_t iwl_dbgfs_sram_write(struct file *file,
317 const char __user *user_buf,
318 size_t count, loff_t *ppos)
319{
320 struct iwl_priv *priv = file->private_data;
321 char buf[64];
322 int buf_size;
323 u32 offset, len;
324
325 memset(buf, 0, sizeof(buf));
326 buf_size = min(count, sizeof(buf) - 1);
327 if (copy_from_user(buf, user_buf, buf_size))
328 return -EFAULT;
329
330 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800331 priv->dbgfs_sram_offset = offset;
332 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800333 } else if (sscanf(buf, "%x", &offset) == 1) {
334 priv->dbgfs_sram_offset = offset;
335 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700336 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800337 priv->dbgfs_sram_offset = 0;
338 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700339 }
340
341 return count;
342}
343
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700344static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
345 char __user *user_buf,
346 size_t count, loff_t *ppos)
347{
348 struct iwl_priv *priv = file->private_data;
349
350 if (!priv->wowlan_sram)
351 return -ENODATA;
352
353 return simple_read_from_buffer(user_buf, count, ppos,
354 priv->wowlan_sram,
Johannes Berg0692fe42012-03-06 13:30:37 -0800355 priv->fw->ucode_wowlan.data.len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700356}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700357static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
358 size_t count, loff_t *ppos)
359{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700360 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800361 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700362 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700363 char *buf;
364 int i, j, pos = 0;
365 ssize_t ret;
366 /* Add 30 for initial string */
367 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700368
369 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300370 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700371 return -ENOMEM;
372
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700373 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700374 priv->num_stations);
375
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700376 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700377 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700378 if (!station->used)
379 continue;
380 pos += scnprintf(buf + pos, bufsz - pos,
381 "station %d - addr: %pM, flags: %#x\n",
382 i, station->sta.sta.addr,
383 station->sta.station_flags_msk);
384 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200385 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700386
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700387 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200388 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700389 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200390 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700391 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700392 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700393
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700394 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700395 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700396 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700397 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700398 }
Johannes Bergda735112010-05-03 01:25:24 -0700399
400 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700401 }
402
403 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
404 kfree(buf);
405 return ret;
406}
407
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700408static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800409 char __user *user_buf,
410 size_t count,
411 loff_t *ppos)
412{
413 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700414 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800415 int pos = 0, ofs = 0, buf_size = 0;
416 const u8 *ptr;
417 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700418 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800419 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800420 buf_size = 4 * eeprom_len + 256;
421
422 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700423 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800424 return -ENODATA;
425 }
426
Don Fryab36eab2011-11-30 15:37:32 -0800427 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200428 if (!ptr) {
429 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
430 return -ENOMEM;
431 }
432
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800433 /* 4 characters for byte 0xYY */
434 buf = kzalloc(buf_size, GFP_KERNEL);
435 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800436 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800437 return -ENOMEM;
438 }
Don Fryab36eab2011-11-30 15:37:32 -0800439 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700440 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
441 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800442 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700443 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800444 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
445 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
446 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
447 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700448 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800449 if (buf_size - pos > 0)
450 buf[pos++] = '\n';
451 }
452
453 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
454 kfree(buf);
455 return ret;
456}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700457
Winkler, Tomasd366df52008-12-02 12:14:01 -0800458static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
459 size_t count, loff_t *ppos)
460{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700461 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800462 struct ieee80211_channel *channels = NULL;
463 const struct ieee80211_supported_band *supp_band = NULL;
464 int pos = 0, i, bufsz = PAGE_SIZE;
465 char *buf;
466 ssize_t ret;
467
Don Fry83626402012-03-07 09:52:37 -0800468 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800469 return -EAGAIN;
470
471 buf = kzalloc(bufsz, GFP_KERNEL);
472 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800473 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800474 return -ENOMEM;
475 }
476
477 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700478 if (supp_band) {
479 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800480
Winkler, Tomasd366df52008-12-02 12:14:01 -0800481 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700482 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
483 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800484
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700485 for (i = 0; i < supp_band->n_channels; i++)
486 pos += scnprintf(buf + pos, bufsz - pos,
487 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700488 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700489 channels[i].max_power,
490 channels[i].flags & IEEE80211_CHAN_RADAR ?
491 " (IEEE 802.11h required)" : "",
492 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
493 || (channels[i].flags &
494 IEEE80211_CHAN_RADAR)) ? "" :
495 ", IBSS",
496 channels[i].flags &
497 IEEE80211_CHAN_PASSIVE_SCAN ?
498 "passive only" : "active/passive");
499 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800500 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700501 if (supp_band) {
502 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800503
Winkler, Tomasd366df52008-12-02 12:14:01 -0800504 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700505 "Displaying %d channels in 5.2GHz band (802.11a)\n",
506 supp_band->n_channels);
507
508 for (i = 0; i < supp_band->n_channels; i++)
509 pos += scnprintf(buf + pos, bufsz - pos,
510 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700511 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700512 channels[i].max_power,
513 channels[i].flags & IEEE80211_CHAN_RADAR ?
514 " (IEEE 802.11h required)" : "",
515 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
516 || (channels[i].flags &
517 IEEE80211_CHAN_RADAR)) ? "" :
518 ", IBSS",
519 channels[i].flags &
520 IEEE80211_CHAN_PASSIVE_SCAN ?
521 "passive only" : "active/passive");
522 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800523 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
524 kfree(buf);
525 return ret;
526}
527
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700528static ssize_t iwl_dbgfs_status_read(struct file *file,
529 char __user *user_buf,
530 size_t count, loff_t *ppos) {
531
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700532 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700533 char buf[512];
534 int pos = 0;
535 const size_t bufsz = sizeof(buf);
536
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700538 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800540 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800542 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800544 test_bit(STATUS_ALIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800546 test_bit(STATUS_READY, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800548 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800550 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800552 test_bit(STATUS_STATISTICS, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700553 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800554 test_bit(STATUS_SCANNING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700555 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800556 test_bit(STATUS_SCAN_ABORTING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700557 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800558 test_bit(STATUS_SCAN_HW, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700559 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700560 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700561 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700562 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700563 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
564}
565
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700566static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700567 char __user *user_buf,
568 size_t count, loff_t *ppos) {
569
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700570 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700571
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700572 int pos = 0;
573 int cnt = 0;
574 char *buf;
575 int bufsz = 24 * 64; /* 24 items * 64 char per item */
576 ssize_t ret;
577
578 buf = kzalloc(bufsz, GFP_KERNEL);
579 if (!buf) {
580 IWL_ERR(priv, "Can not allocate Buffer\n");
581 return -ENOMEM;
582 }
583
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700584 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700585 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700586 pos += scnprintf(buf + pos, bufsz - pos,
587 "\tRx handler[%36s]:\t\t %u\n",
588 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700589 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700590 }
591
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700592 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
593 kfree(buf);
594 return ret;
595}
596
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700597static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700598 const char __user *user_buf,
599 size_t count, loff_t *ppos)
600{
601 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700602
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700603 char buf[8];
604 int buf_size;
605 u32 reset_flag;
606
607 memset(buf, 0, sizeof(buf));
608 buf_size = min(count, sizeof(buf) - 1);
609 if (copy_from_user(buf, user_buf, buf_size))
610 return -EFAULT;
611 if (sscanf(buf, "%x", &reset_flag) != 1)
612 return -EFAULT;
613 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700614 memset(&priv->rx_handlers_stats[0], 0,
615 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700616
617 return count;
618}
619
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700620static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
621 size_t count, loff_t *ppos)
622{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700623 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200624 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700625 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200626 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700627 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700628
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200629 for_each_context(priv, ctx) {
630 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
631 ctx->ctxid);
632 for (i = 0; i < AC_NUM; i++) {
633 pos += scnprintf(buf + pos, bufsz - pos,
634 "\tcw_min\tcw_max\taifsn\ttxop\n");
635 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700636 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200637 ctx->qos_data.def_qos_parm.ac[i].cw_min,
638 ctx->qos_data.def_qos_parm.ac[i].cw_max,
639 ctx->qos_data.def_qos_parm.ac[i].aifsn,
640 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
641 }
642 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700643 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800644 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700645}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700646
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700647static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
648 char __user *user_buf,
649 size_t count, loff_t *ppos)
650{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700651 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700652 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700653 struct iwl_tt_restriction *restriction;
654 char buf[100];
655 int pos = 0;
656 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700657
658 pos += scnprintf(buf + pos, bufsz - pos,
659 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700660 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700661 pos += scnprintf(buf + pos, bufsz - pos,
662 "Thermal Throttling State: %d\n",
663 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700664 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700665 restriction = tt->restriction + tt->state;
666 pos += scnprintf(buf + pos, bufsz - pos,
667 "Tx mode: %d\n",
668 restriction->tx_stream);
669 pos += scnprintf(buf + pos, bufsz - pos,
670 "Rx mode: %d\n",
671 restriction->rx_stream);
672 pos += scnprintf(buf + pos, bufsz - pos,
673 "HT mode: %d\n",
674 restriction->is_ht);
675 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800676 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700677}
678
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700679static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
680 const char __user *user_buf,
681 size_t count, loff_t *ppos)
682{
683 struct iwl_priv *priv = file->private_data;
684 char buf[8];
685 int buf_size;
686 int ht40;
687
688 memset(buf, 0, sizeof(buf));
689 buf_size = min(count, sizeof(buf) - 1);
690 if (copy_from_user(buf, user_buf, buf_size))
691 return -EFAULT;
692 if (sscanf(buf, "%d", &ht40) != 1)
693 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200694 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700695 priv->disable_ht40 = ht40 ? true : false;
696 else {
697 IWL_ERR(priv, "Sta associated with AP - "
698 "Change to 40MHz channel support is not allowed\n");
699 return -EINVAL;
700 }
701
702 return count;
703}
704
705static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
706 char __user *user_buf,
707 size_t count, loff_t *ppos)
708{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700709 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700710 char buf[100];
711 int pos = 0;
712 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700713
714 pos += scnprintf(buf + pos, bufsz - pos,
715 "11n 40MHz Mode: %s\n",
716 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800717 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700718}
719
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700720static ssize_t iwl_dbgfs_temperature_read(struct file *file,
721 char __user *user_buf,
722 size_t count, loff_t *ppos)
723{
724 struct iwl_priv *priv = file->private_data;
725 char buf[8];
726 int pos = 0;
727 const size_t bufsz = sizeof(buf);
728
729 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
730 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
731}
732
733
Johannes Berge312c242009-08-07 15:41:51 -0700734static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
735 const char __user *user_buf,
736 size_t count, loff_t *ppos)
737{
738 struct iwl_priv *priv = file->private_data;
739 char buf[8];
740 int buf_size;
741 int value;
742
743 memset(buf, 0, sizeof(buf));
744 buf_size = min(count, sizeof(buf) - 1);
745 if (copy_from_user(buf, user_buf, buf_size))
746 return -EFAULT;
747
748 if (sscanf(buf, "%d", &value) != 1)
749 return -EINVAL;
750
751 /*
752 * Our users expect 0 to be "CAM", but 0 isn't actually
753 * valid here. However, let's not confuse them and present
754 * IWL_POWER_INDEX_1 as "1", not "0".
755 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700756 if (value == 0)
757 return -EINVAL;
758 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700759 value -= 1;
760
761 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
762 return -EINVAL;
763
Don Fry83626402012-03-07 09:52:37 -0800764 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700765 return -EAGAIN;
766
Johannes Berge312c242009-08-07 15:41:51 -0700767 priv->power_data.debug_sleep_level_override = value;
768
Johannes Bergb1eea292012-03-06 13:30:42 -0800769 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700770 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800771 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700772
773 return count;
774}
775
776static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
777 char __user *user_buf,
778 size_t count, loff_t *ppos)
779{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700780 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700781 char buf[10];
782 int pos, value;
783 const size_t bufsz = sizeof(buf);
784
785 /* see the write function */
786 value = priv->power_data.debug_sleep_level_override;
787 if (value >= 0)
788 value += 1;
789
790 pos = scnprintf(buf, bufsz, "%d\n", value);
791 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
792}
793
794static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
795 char __user *user_buf,
796 size_t count, loff_t *ppos)
797{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700798 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700799 char buf[200];
800 int pos = 0, i;
801 const size_t bufsz = sizeof(buf);
802 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
803
804 pos += scnprintf(buf + pos, bufsz - pos,
805 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
806 pos += scnprintf(buf + pos, bufsz - pos,
807 "RX/TX timeout: %d/%d usec\n",
808 le32_to_cpu(cmd->rx_data_timeout),
809 le32_to_cpu(cmd->tx_data_timeout));
810 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
811 pos += scnprintf(buf + pos, bufsz - pos,
812 "sleep_interval[%d]: %d\n", i,
813 le32_to_cpu(cmd->sleep_interval[i]));
814
815 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
816}
817
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700818DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700819DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700820DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700821DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800822DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700823DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700824DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700825DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700826DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700827DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700828DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700829DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
830DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700831
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700832static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
833 char __user *user_buf,
834 size_t count, loff_t *ppos)
835{
836 struct iwl_priv *priv = file->private_data;
837 int pos = 0, ofs = 0;
838 int cnt = 0, entry;
839
840 char *buf;
841 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy1745e442012-03-09 11:13:40 -0800842 (cfg(priv)->base_params->num_of_queues * 32 * 8) + 400;
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700843 const u8 *ptr;
844 ssize_t ret;
845
846 buf = kzalloc(bufsz, GFP_KERNEL);
847 if (!buf) {
848 IWL_ERR(priv, "Can not allocate buffer\n");
849 return -ENOMEM;
850 }
Johannes Berga8bceb32012-03-05 11:24:30 -0800851 if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700852 ptr = priv->tx_traffic;
853 pos += scnprintf(buf + pos, bufsz - pos,
854 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
855 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
856 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
857 entry++, ofs += 16) {
858 pos += scnprintf(buf + pos, bufsz - pos,
859 "0x%.4x ", ofs);
860 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
861 buf + pos, bufsz - pos, 0);
862 pos += strlen(buf + pos);
863 if (bufsz - pos > 0)
864 buf[pos++] = '\n';
865 }
866 }
867 }
868
Johannes Berga8bceb32012-03-05 11:24:30 -0800869 if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700870 ptr = priv->rx_traffic;
871 pos += scnprintf(buf + pos, bufsz - pos,
872 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
873 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
874 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
875 entry++, ofs += 16) {
876 pos += scnprintf(buf + pos, bufsz - pos,
877 "0x%.4x ", ofs);
878 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
879 buf + pos, bufsz - pos, 0);
880 pos += strlen(buf + pos);
881 if (bufsz - pos > 0)
882 buf[pos++] = '\n';
883 }
884 }
885 }
886
887 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
888 kfree(buf);
889 return ret;
890}
891
892static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
893 const char __user *user_buf,
894 size_t count, loff_t *ppos)
895{
896 struct iwl_priv *priv = file->private_data;
897 char buf[8];
898 int buf_size;
899 int traffic_log;
900
901 memset(buf, 0, sizeof(buf));
902 buf_size = min(count, sizeof(buf) - 1);
903 if (copy_from_user(buf, user_buf, buf_size))
904 return -EFAULT;
905 if (sscanf(buf, "%d", &traffic_log) != 1)
906 return -EFAULT;
907 if (traffic_log == 0)
908 iwl_reset_traffic_log(priv);
909
910 return count;
911}
912
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700913static const char *fmt_value = " %-30s %10u\n";
914static const char *fmt_hex = " %-30s 0x%02X\n";
915static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
916static const char *fmt_header =
917 "%-32s current cumulative delta max\n";
918
919static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
920{
921 int p = 0;
922 u32 flag;
923
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800924 lockdep_assert_held(&priv->statistics.lock);
925
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700926 flag = le32_to_cpu(priv->statistics.flag);
927
928 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
929 if (flag & UCODE_STATISTICS_CLEAR_MSK)
930 p += scnprintf(buf + p, bufsz - p,
931 "\tStatistics have been cleared\n");
932 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
933 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
934 ? "2.4 GHz" : "5.2 GHz");
935 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
936 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
937 ? "enabled" : "disabled");
938
939 return p;
940}
941
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700942static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
943 char __user *user_buf,
944 size_t count, loff_t *ppos)
945{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700946 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700947 int pos = 0;
948 char *buf;
949 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
950 sizeof(struct statistics_rx_non_phy) * 40 +
951 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
952 ssize_t ret;
953 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
954 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
955 struct statistics_rx_non_phy *general, *accum_general;
956 struct statistics_rx_non_phy *delta_general, *max_general;
957 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
958
Don Fry83626402012-03-07 09:52:37 -0800959 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700960 return -EAGAIN;
961
962 buf = kzalloc(bufsz, GFP_KERNEL);
963 if (!buf) {
964 IWL_ERR(priv, "Can not allocate Buffer\n");
965 return -ENOMEM;
966 }
967
968 /*
969 * the statistic information display here is based on
970 * the last statistics notification from uCode
971 * might not reflect the current uCode activity
972 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800973 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700974 ofdm = &priv->statistics.rx_ofdm;
975 cck = &priv->statistics.rx_cck;
976 general = &priv->statistics.rx_non_phy;
977 ht = &priv->statistics.rx_ofdm_ht;
978 accum_ofdm = &priv->accum_stats.rx_ofdm;
979 accum_cck = &priv->accum_stats.rx_cck;
980 accum_general = &priv->accum_stats.rx_non_phy;
981 accum_ht = &priv->accum_stats.rx_ofdm_ht;
982 delta_ofdm = &priv->delta_stats.rx_ofdm;
983 delta_cck = &priv->delta_stats.rx_cck;
984 delta_general = &priv->delta_stats.rx_non_phy;
985 delta_ht = &priv->delta_stats.rx_ofdm_ht;
986 max_ofdm = &priv->max_delta_stats.rx_ofdm;
987 max_cck = &priv->max_delta_stats.rx_cck;
988 max_general = &priv->max_delta_stats.rx_non_phy;
989 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
990
991 pos += iwl_statistics_flag(priv, buf, bufsz);
992 pos += scnprintf(buf + pos, bufsz - pos,
993 fmt_header, "Statistics_Rx - OFDM:");
994 pos += scnprintf(buf + pos, bufsz - pos,
995 fmt_table, "ina_cnt:",
996 le32_to_cpu(ofdm->ina_cnt),
997 accum_ofdm->ina_cnt,
998 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
999 pos += scnprintf(buf + pos, bufsz - pos,
1000 fmt_table, "fina_cnt:",
1001 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
1002 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
1003 pos += scnprintf(buf + pos, bufsz - pos,
1004 fmt_table, "plcp_err:",
1005 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
1006 delta_ofdm->plcp_err, max_ofdm->plcp_err);
1007 pos += scnprintf(buf + pos, bufsz - pos,
1008 fmt_table, "crc32_err:",
1009 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1010 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1011 pos += scnprintf(buf + pos, bufsz - pos,
1012 fmt_table, "overrun_err:",
1013 le32_to_cpu(ofdm->overrun_err),
1014 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1015 max_ofdm->overrun_err);
1016 pos += scnprintf(buf + pos, bufsz - pos,
1017 fmt_table, "early_overrun_err:",
1018 le32_to_cpu(ofdm->early_overrun_err),
1019 accum_ofdm->early_overrun_err,
1020 delta_ofdm->early_overrun_err,
1021 max_ofdm->early_overrun_err);
1022 pos += scnprintf(buf + pos, bufsz - pos,
1023 fmt_table, "crc32_good:",
1024 le32_to_cpu(ofdm->crc32_good),
1025 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1026 max_ofdm->crc32_good);
1027 pos += scnprintf(buf + pos, bufsz - pos,
1028 fmt_table, "false_alarm_cnt:",
1029 le32_to_cpu(ofdm->false_alarm_cnt),
1030 accum_ofdm->false_alarm_cnt,
1031 delta_ofdm->false_alarm_cnt,
1032 max_ofdm->false_alarm_cnt);
1033 pos += scnprintf(buf + pos, bufsz - pos,
1034 fmt_table, "fina_sync_err_cnt:",
1035 le32_to_cpu(ofdm->fina_sync_err_cnt),
1036 accum_ofdm->fina_sync_err_cnt,
1037 delta_ofdm->fina_sync_err_cnt,
1038 max_ofdm->fina_sync_err_cnt);
1039 pos += scnprintf(buf + pos, bufsz - pos,
1040 fmt_table, "sfd_timeout:",
1041 le32_to_cpu(ofdm->sfd_timeout),
1042 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1043 max_ofdm->sfd_timeout);
1044 pos += scnprintf(buf + pos, bufsz - pos,
1045 fmt_table, "fina_timeout:",
1046 le32_to_cpu(ofdm->fina_timeout),
1047 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1048 max_ofdm->fina_timeout);
1049 pos += scnprintf(buf + pos, bufsz - pos,
1050 fmt_table, "unresponded_rts:",
1051 le32_to_cpu(ofdm->unresponded_rts),
1052 accum_ofdm->unresponded_rts,
1053 delta_ofdm->unresponded_rts,
1054 max_ofdm->unresponded_rts);
1055 pos += scnprintf(buf + pos, bufsz - pos,
1056 fmt_table, "rxe_frame_lmt_ovrun:",
1057 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1058 accum_ofdm->rxe_frame_limit_overrun,
1059 delta_ofdm->rxe_frame_limit_overrun,
1060 max_ofdm->rxe_frame_limit_overrun);
1061 pos += scnprintf(buf + pos, bufsz - pos,
1062 fmt_table, "sent_ack_cnt:",
1063 le32_to_cpu(ofdm->sent_ack_cnt),
1064 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1065 max_ofdm->sent_ack_cnt);
1066 pos += scnprintf(buf + pos, bufsz - pos,
1067 fmt_table, "sent_cts_cnt:",
1068 le32_to_cpu(ofdm->sent_cts_cnt),
1069 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1070 max_ofdm->sent_cts_cnt);
1071 pos += scnprintf(buf + pos, bufsz - pos,
1072 fmt_table, "sent_ba_rsp_cnt:",
1073 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1074 accum_ofdm->sent_ba_rsp_cnt,
1075 delta_ofdm->sent_ba_rsp_cnt,
1076 max_ofdm->sent_ba_rsp_cnt);
1077 pos += scnprintf(buf + pos, bufsz - pos,
1078 fmt_table, "dsp_self_kill:",
1079 le32_to_cpu(ofdm->dsp_self_kill),
1080 accum_ofdm->dsp_self_kill,
1081 delta_ofdm->dsp_self_kill,
1082 max_ofdm->dsp_self_kill);
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 fmt_table, "mh_format_err:",
1085 le32_to_cpu(ofdm->mh_format_err),
1086 accum_ofdm->mh_format_err,
1087 delta_ofdm->mh_format_err,
1088 max_ofdm->mh_format_err);
1089 pos += scnprintf(buf + pos, bufsz - pos,
1090 fmt_table, "re_acq_main_rssi_sum:",
1091 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1092 accum_ofdm->re_acq_main_rssi_sum,
1093 delta_ofdm->re_acq_main_rssi_sum,
1094 max_ofdm->re_acq_main_rssi_sum);
1095
1096 pos += scnprintf(buf + pos, bufsz - pos,
1097 fmt_header, "Statistics_Rx - CCK:");
1098 pos += scnprintf(buf + pos, bufsz - pos,
1099 fmt_table, "ina_cnt:",
1100 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1101 delta_cck->ina_cnt, max_cck->ina_cnt);
1102 pos += scnprintf(buf + pos, bufsz - pos,
1103 fmt_table, "fina_cnt:",
1104 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1105 delta_cck->fina_cnt, max_cck->fina_cnt);
1106 pos += scnprintf(buf + pos, bufsz - pos,
1107 fmt_table, "plcp_err:",
1108 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1109 delta_cck->plcp_err, max_cck->plcp_err);
1110 pos += scnprintf(buf + pos, bufsz - pos,
1111 fmt_table, "crc32_err:",
1112 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1113 delta_cck->crc32_err, max_cck->crc32_err);
1114 pos += scnprintf(buf + pos, bufsz - pos,
1115 fmt_table, "overrun_err:",
1116 le32_to_cpu(cck->overrun_err),
1117 accum_cck->overrun_err, delta_cck->overrun_err,
1118 max_cck->overrun_err);
1119 pos += scnprintf(buf + pos, bufsz - pos,
1120 fmt_table, "early_overrun_err:",
1121 le32_to_cpu(cck->early_overrun_err),
1122 accum_cck->early_overrun_err,
1123 delta_cck->early_overrun_err,
1124 max_cck->early_overrun_err);
1125 pos += scnprintf(buf + pos, bufsz - pos,
1126 fmt_table, "crc32_good:",
1127 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1128 delta_cck->crc32_good, max_cck->crc32_good);
1129 pos += scnprintf(buf + pos, bufsz - pos,
1130 fmt_table, "false_alarm_cnt:",
1131 le32_to_cpu(cck->false_alarm_cnt),
1132 accum_cck->false_alarm_cnt,
1133 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1134 pos += scnprintf(buf + pos, bufsz - pos,
1135 fmt_table, "fina_sync_err_cnt:",
1136 le32_to_cpu(cck->fina_sync_err_cnt),
1137 accum_cck->fina_sync_err_cnt,
1138 delta_cck->fina_sync_err_cnt,
1139 max_cck->fina_sync_err_cnt);
1140 pos += scnprintf(buf + pos, bufsz - pos,
1141 fmt_table, "sfd_timeout:",
1142 le32_to_cpu(cck->sfd_timeout),
1143 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1144 max_cck->sfd_timeout);
1145 pos += scnprintf(buf + pos, bufsz - pos,
1146 fmt_table, "fina_timeout:",
1147 le32_to_cpu(cck->fina_timeout),
1148 accum_cck->fina_timeout, delta_cck->fina_timeout,
1149 max_cck->fina_timeout);
1150 pos += scnprintf(buf + pos, bufsz - pos,
1151 fmt_table, "unresponded_rts:",
1152 le32_to_cpu(cck->unresponded_rts),
1153 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1154 max_cck->unresponded_rts);
1155 pos += scnprintf(buf + pos, bufsz - pos,
1156 fmt_table, "rxe_frame_lmt_ovrun:",
1157 le32_to_cpu(cck->rxe_frame_limit_overrun),
1158 accum_cck->rxe_frame_limit_overrun,
1159 delta_cck->rxe_frame_limit_overrun,
1160 max_cck->rxe_frame_limit_overrun);
1161 pos += scnprintf(buf + pos, bufsz - pos,
1162 fmt_table, "sent_ack_cnt:",
1163 le32_to_cpu(cck->sent_ack_cnt),
1164 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1165 max_cck->sent_ack_cnt);
1166 pos += scnprintf(buf + pos, bufsz - pos,
1167 fmt_table, "sent_cts_cnt:",
1168 le32_to_cpu(cck->sent_cts_cnt),
1169 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1170 max_cck->sent_cts_cnt);
1171 pos += scnprintf(buf + pos, bufsz - pos,
1172 fmt_table, "sent_ba_rsp_cnt:",
1173 le32_to_cpu(cck->sent_ba_rsp_cnt),
1174 accum_cck->sent_ba_rsp_cnt,
1175 delta_cck->sent_ba_rsp_cnt,
1176 max_cck->sent_ba_rsp_cnt);
1177 pos += scnprintf(buf + pos, bufsz - pos,
1178 fmt_table, "dsp_self_kill:",
1179 le32_to_cpu(cck->dsp_self_kill),
1180 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1181 max_cck->dsp_self_kill);
1182 pos += scnprintf(buf + pos, bufsz - pos,
1183 fmt_table, "mh_format_err:",
1184 le32_to_cpu(cck->mh_format_err),
1185 accum_cck->mh_format_err, delta_cck->mh_format_err,
1186 max_cck->mh_format_err);
1187 pos += scnprintf(buf + pos, bufsz - pos,
1188 fmt_table, "re_acq_main_rssi_sum:",
1189 le32_to_cpu(cck->re_acq_main_rssi_sum),
1190 accum_cck->re_acq_main_rssi_sum,
1191 delta_cck->re_acq_main_rssi_sum,
1192 max_cck->re_acq_main_rssi_sum);
1193
1194 pos += scnprintf(buf + pos, bufsz - pos,
1195 fmt_header, "Statistics_Rx - GENERAL:");
1196 pos += scnprintf(buf + pos, bufsz - pos,
1197 fmt_table, "bogus_cts:",
1198 le32_to_cpu(general->bogus_cts),
1199 accum_general->bogus_cts, delta_general->bogus_cts,
1200 max_general->bogus_cts);
1201 pos += scnprintf(buf + pos, bufsz - pos,
1202 fmt_table, "bogus_ack:",
1203 le32_to_cpu(general->bogus_ack),
1204 accum_general->bogus_ack, delta_general->bogus_ack,
1205 max_general->bogus_ack);
1206 pos += scnprintf(buf + pos, bufsz - pos,
1207 fmt_table, "non_bssid_frames:",
1208 le32_to_cpu(general->non_bssid_frames),
1209 accum_general->non_bssid_frames,
1210 delta_general->non_bssid_frames,
1211 max_general->non_bssid_frames);
1212 pos += scnprintf(buf + pos, bufsz - pos,
1213 fmt_table, "filtered_frames:",
1214 le32_to_cpu(general->filtered_frames),
1215 accum_general->filtered_frames,
1216 delta_general->filtered_frames,
1217 max_general->filtered_frames);
1218 pos += scnprintf(buf + pos, bufsz - pos,
1219 fmt_table, "non_channel_beacons:",
1220 le32_to_cpu(general->non_channel_beacons),
1221 accum_general->non_channel_beacons,
1222 delta_general->non_channel_beacons,
1223 max_general->non_channel_beacons);
1224 pos += scnprintf(buf + pos, bufsz - pos,
1225 fmt_table, "channel_beacons:",
1226 le32_to_cpu(general->channel_beacons),
1227 accum_general->channel_beacons,
1228 delta_general->channel_beacons,
1229 max_general->channel_beacons);
1230 pos += scnprintf(buf + pos, bufsz - pos,
1231 fmt_table, "num_missed_bcon:",
1232 le32_to_cpu(general->num_missed_bcon),
1233 accum_general->num_missed_bcon,
1234 delta_general->num_missed_bcon,
1235 max_general->num_missed_bcon);
1236 pos += scnprintf(buf + pos, bufsz - pos,
1237 fmt_table, "adc_rx_saturation_time:",
1238 le32_to_cpu(general->adc_rx_saturation_time),
1239 accum_general->adc_rx_saturation_time,
1240 delta_general->adc_rx_saturation_time,
1241 max_general->adc_rx_saturation_time);
1242 pos += scnprintf(buf + pos, bufsz - pos,
1243 fmt_table, "ina_detect_search_tm:",
1244 le32_to_cpu(general->ina_detection_search_time),
1245 accum_general->ina_detection_search_time,
1246 delta_general->ina_detection_search_time,
1247 max_general->ina_detection_search_time);
1248 pos += scnprintf(buf + pos, bufsz - pos,
1249 fmt_table, "beacon_silence_rssi_a:",
1250 le32_to_cpu(general->beacon_silence_rssi_a),
1251 accum_general->beacon_silence_rssi_a,
1252 delta_general->beacon_silence_rssi_a,
1253 max_general->beacon_silence_rssi_a);
1254 pos += scnprintf(buf + pos, bufsz - pos,
1255 fmt_table, "beacon_silence_rssi_b:",
1256 le32_to_cpu(general->beacon_silence_rssi_b),
1257 accum_general->beacon_silence_rssi_b,
1258 delta_general->beacon_silence_rssi_b,
1259 max_general->beacon_silence_rssi_b);
1260 pos += scnprintf(buf + pos, bufsz - pos,
1261 fmt_table, "beacon_silence_rssi_c:",
1262 le32_to_cpu(general->beacon_silence_rssi_c),
1263 accum_general->beacon_silence_rssi_c,
1264 delta_general->beacon_silence_rssi_c,
1265 max_general->beacon_silence_rssi_c);
1266 pos += scnprintf(buf + pos, bufsz - pos,
1267 fmt_table, "interference_data_flag:",
1268 le32_to_cpu(general->interference_data_flag),
1269 accum_general->interference_data_flag,
1270 delta_general->interference_data_flag,
1271 max_general->interference_data_flag);
1272 pos += scnprintf(buf + pos, bufsz - pos,
1273 fmt_table, "channel_load:",
1274 le32_to_cpu(general->channel_load),
1275 accum_general->channel_load,
1276 delta_general->channel_load,
1277 max_general->channel_load);
1278 pos += scnprintf(buf + pos, bufsz - pos,
1279 fmt_table, "dsp_false_alarms:",
1280 le32_to_cpu(general->dsp_false_alarms),
1281 accum_general->dsp_false_alarms,
1282 delta_general->dsp_false_alarms,
1283 max_general->dsp_false_alarms);
1284 pos += scnprintf(buf + pos, bufsz - pos,
1285 fmt_table, "beacon_rssi_a:",
1286 le32_to_cpu(general->beacon_rssi_a),
1287 accum_general->beacon_rssi_a,
1288 delta_general->beacon_rssi_a,
1289 max_general->beacon_rssi_a);
1290 pos += scnprintf(buf + pos, bufsz - pos,
1291 fmt_table, "beacon_rssi_b:",
1292 le32_to_cpu(general->beacon_rssi_b),
1293 accum_general->beacon_rssi_b,
1294 delta_general->beacon_rssi_b,
1295 max_general->beacon_rssi_b);
1296 pos += scnprintf(buf + pos, bufsz - pos,
1297 fmt_table, "beacon_rssi_c:",
1298 le32_to_cpu(general->beacon_rssi_c),
1299 accum_general->beacon_rssi_c,
1300 delta_general->beacon_rssi_c,
1301 max_general->beacon_rssi_c);
1302 pos += scnprintf(buf + pos, bufsz - pos,
1303 fmt_table, "beacon_energy_a:",
1304 le32_to_cpu(general->beacon_energy_a),
1305 accum_general->beacon_energy_a,
1306 delta_general->beacon_energy_a,
1307 max_general->beacon_energy_a);
1308 pos += scnprintf(buf + pos, bufsz - pos,
1309 fmt_table, "beacon_energy_b:",
1310 le32_to_cpu(general->beacon_energy_b),
1311 accum_general->beacon_energy_b,
1312 delta_general->beacon_energy_b,
1313 max_general->beacon_energy_b);
1314 pos += scnprintf(buf + pos, bufsz - pos,
1315 fmt_table, "beacon_energy_c:",
1316 le32_to_cpu(general->beacon_energy_c),
1317 accum_general->beacon_energy_c,
1318 delta_general->beacon_energy_c,
1319 max_general->beacon_energy_c);
1320
1321 pos += scnprintf(buf + pos, bufsz - pos,
1322 fmt_header, "Statistics_Rx - OFDM_HT:");
1323 pos += scnprintf(buf + pos, bufsz - pos,
1324 fmt_table, "plcp_err:",
1325 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1326 delta_ht->plcp_err, max_ht->plcp_err);
1327 pos += scnprintf(buf + pos, bufsz - pos,
1328 fmt_table, "overrun_err:",
1329 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1330 delta_ht->overrun_err, max_ht->overrun_err);
1331 pos += scnprintf(buf + pos, bufsz - pos,
1332 fmt_table, "early_overrun_err:",
1333 le32_to_cpu(ht->early_overrun_err),
1334 accum_ht->early_overrun_err,
1335 delta_ht->early_overrun_err,
1336 max_ht->early_overrun_err);
1337 pos += scnprintf(buf + pos, bufsz - pos,
1338 fmt_table, "crc32_good:",
1339 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1340 delta_ht->crc32_good, max_ht->crc32_good);
1341 pos += scnprintf(buf + pos, bufsz - pos,
1342 fmt_table, "crc32_err:",
1343 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1344 delta_ht->crc32_err, max_ht->crc32_err);
1345 pos += scnprintf(buf + pos, bufsz - pos,
1346 fmt_table, "mh_format_err:",
1347 le32_to_cpu(ht->mh_format_err),
1348 accum_ht->mh_format_err,
1349 delta_ht->mh_format_err, max_ht->mh_format_err);
1350 pos += scnprintf(buf + pos, bufsz - pos,
1351 fmt_table, "agg_crc32_good:",
1352 le32_to_cpu(ht->agg_crc32_good),
1353 accum_ht->agg_crc32_good,
1354 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1355 pos += scnprintf(buf + pos, bufsz - pos,
1356 fmt_table, "agg_mpdu_cnt:",
1357 le32_to_cpu(ht->agg_mpdu_cnt),
1358 accum_ht->agg_mpdu_cnt,
1359 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1360 pos += scnprintf(buf + pos, bufsz - pos,
1361 fmt_table, "agg_cnt:",
1362 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1363 delta_ht->agg_cnt, max_ht->agg_cnt);
1364 pos += scnprintf(buf + pos, bufsz - pos,
1365 fmt_table, "unsupport_mcs:",
1366 le32_to_cpu(ht->unsupport_mcs),
1367 accum_ht->unsupport_mcs,
1368 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1369
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001370 spin_unlock_bh(&priv->statistics.lock);
1371
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001372 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1373 kfree(buf);
1374 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001375}
1376
1377static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1378 char __user *user_buf,
1379 size_t count, loff_t *ppos)
1380{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001381 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001382 int pos = 0;
1383 char *buf;
1384 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1385 ssize_t ret;
1386 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1387
Don Fry83626402012-03-07 09:52:37 -08001388 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001389 return -EAGAIN;
1390
1391 buf = kzalloc(bufsz, GFP_KERNEL);
1392 if (!buf) {
1393 IWL_ERR(priv, "Can not allocate Buffer\n");
1394 return -ENOMEM;
1395 }
1396
1397 /* the statistic information display here is based on
1398 * the last statistics notification from uCode
1399 * might not reflect the current uCode activity
1400 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001401 spin_lock_bh(&priv->statistics.lock);
1402
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001403 tx = &priv->statistics.tx;
1404 accum_tx = &priv->accum_stats.tx;
1405 delta_tx = &priv->delta_stats.tx;
1406 max_tx = &priv->max_delta_stats.tx;
1407
1408 pos += iwl_statistics_flag(priv, buf, bufsz);
1409 pos += scnprintf(buf + pos, bufsz - pos,
1410 fmt_header, "Statistics_Tx:");
1411 pos += scnprintf(buf + pos, bufsz - pos,
1412 fmt_table, "preamble:",
1413 le32_to_cpu(tx->preamble_cnt),
1414 accum_tx->preamble_cnt,
1415 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1416 pos += scnprintf(buf + pos, bufsz - pos,
1417 fmt_table, "rx_detected_cnt:",
1418 le32_to_cpu(tx->rx_detected_cnt),
1419 accum_tx->rx_detected_cnt,
1420 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1421 pos += scnprintf(buf + pos, bufsz - pos,
1422 fmt_table, "bt_prio_defer_cnt:",
1423 le32_to_cpu(tx->bt_prio_defer_cnt),
1424 accum_tx->bt_prio_defer_cnt,
1425 delta_tx->bt_prio_defer_cnt,
1426 max_tx->bt_prio_defer_cnt);
1427 pos += scnprintf(buf + pos, bufsz - pos,
1428 fmt_table, "bt_prio_kill_cnt:",
1429 le32_to_cpu(tx->bt_prio_kill_cnt),
1430 accum_tx->bt_prio_kill_cnt,
1431 delta_tx->bt_prio_kill_cnt,
1432 max_tx->bt_prio_kill_cnt);
1433 pos += scnprintf(buf + pos, bufsz - pos,
1434 fmt_table, "few_bytes_cnt:",
1435 le32_to_cpu(tx->few_bytes_cnt),
1436 accum_tx->few_bytes_cnt,
1437 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1438 pos += scnprintf(buf + pos, bufsz - pos,
1439 fmt_table, "cts_timeout:",
1440 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1441 delta_tx->cts_timeout, max_tx->cts_timeout);
1442 pos += scnprintf(buf + pos, bufsz - pos,
1443 fmt_table, "ack_timeout:",
1444 le32_to_cpu(tx->ack_timeout),
1445 accum_tx->ack_timeout,
1446 delta_tx->ack_timeout, max_tx->ack_timeout);
1447 pos += scnprintf(buf + pos, bufsz - pos,
1448 fmt_table, "expected_ack_cnt:",
1449 le32_to_cpu(tx->expected_ack_cnt),
1450 accum_tx->expected_ack_cnt,
1451 delta_tx->expected_ack_cnt,
1452 max_tx->expected_ack_cnt);
1453 pos += scnprintf(buf + pos, bufsz - pos,
1454 fmt_table, "actual_ack_cnt:",
1455 le32_to_cpu(tx->actual_ack_cnt),
1456 accum_tx->actual_ack_cnt,
1457 delta_tx->actual_ack_cnt,
1458 max_tx->actual_ack_cnt);
1459 pos += scnprintf(buf + pos, bufsz - pos,
1460 fmt_table, "dump_msdu_cnt:",
1461 le32_to_cpu(tx->dump_msdu_cnt),
1462 accum_tx->dump_msdu_cnt,
1463 delta_tx->dump_msdu_cnt,
1464 max_tx->dump_msdu_cnt);
1465 pos += scnprintf(buf + pos, bufsz - pos,
1466 fmt_table, "abort_nxt_frame_mismatch:",
1467 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1468 accum_tx->burst_abort_next_frame_mismatch_cnt,
1469 delta_tx->burst_abort_next_frame_mismatch_cnt,
1470 max_tx->burst_abort_next_frame_mismatch_cnt);
1471 pos += scnprintf(buf + pos, bufsz - pos,
1472 fmt_table, "abort_missing_nxt_frame:",
1473 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1474 accum_tx->burst_abort_missing_next_frame_cnt,
1475 delta_tx->burst_abort_missing_next_frame_cnt,
1476 max_tx->burst_abort_missing_next_frame_cnt);
1477 pos += scnprintf(buf + pos, bufsz - pos,
1478 fmt_table, "cts_timeout_collision:",
1479 le32_to_cpu(tx->cts_timeout_collision),
1480 accum_tx->cts_timeout_collision,
1481 delta_tx->cts_timeout_collision,
1482 max_tx->cts_timeout_collision);
1483 pos += scnprintf(buf + pos, bufsz - pos,
1484 fmt_table, "ack_ba_timeout_collision:",
1485 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1486 accum_tx->ack_or_ba_timeout_collision,
1487 delta_tx->ack_or_ba_timeout_collision,
1488 max_tx->ack_or_ba_timeout_collision);
1489 pos += scnprintf(buf + pos, bufsz - pos,
1490 fmt_table, "agg ba_timeout:",
1491 le32_to_cpu(tx->agg.ba_timeout),
1492 accum_tx->agg.ba_timeout,
1493 delta_tx->agg.ba_timeout,
1494 max_tx->agg.ba_timeout);
1495 pos += scnprintf(buf + pos, bufsz - pos,
1496 fmt_table, "agg ba_resched_frames:",
1497 le32_to_cpu(tx->agg.ba_reschedule_frames),
1498 accum_tx->agg.ba_reschedule_frames,
1499 delta_tx->agg.ba_reschedule_frames,
1500 max_tx->agg.ba_reschedule_frames);
1501 pos += scnprintf(buf + pos, bufsz - pos,
1502 fmt_table, "agg scd_query_agg_frame:",
1503 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1504 accum_tx->agg.scd_query_agg_frame_cnt,
1505 delta_tx->agg.scd_query_agg_frame_cnt,
1506 max_tx->agg.scd_query_agg_frame_cnt);
1507 pos += scnprintf(buf + pos, bufsz - pos,
1508 fmt_table, "agg scd_query_no_agg:",
1509 le32_to_cpu(tx->agg.scd_query_no_agg),
1510 accum_tx->agg.scd_query_no_agg,
1511 delta_tx->agg.scd_query_no_agg,
1512 max_tx->agg.scd_query_no_agg);
1513 pos += scnprintf(buf + pos, bufsz - pos,
1514 fmt_table, "agg scd_query_agg:",
1515 le32_to_cpu(tx->agg.scd_query_agg),
1516 accum_tx->agg.scd_query_agg,
1517 delta_tx->agg.scd_query_agg,
1518 max_tx->agg.scd_query_agg);
1519 pos += scnprintf(buf + pos, bufsz - pos,
1520 fmt_table, "agg scd_query_mismatch:",
1521 le32_to_cpu(tx->agg.scd_query_mismatch),
1522 accum_tx->agg.scd_query_mismatch,
1523 delta_tx->agg.scd_query_mismatch,
1524 max_tx->agg.scd_query_mismatch);
1525 pos += scnprintf(buf + pos, bufsz - pos,
1526 fmt_table, "agg frame_not_ready:",
1527 le32_to_cpu(tx->agg.frame_not_ready),
1528 accum_tx->agg.frame_not_ready,
1529 delta_tx->agg.frame_not_ready,
1530 max_tx->agg.frame_not_ready);
1531 pos += scnprintf(buf + pos, bufsz - pos,
1532 fmt_table, "agg underrun:",
1533 le32_to_cpu(tx->agg.underrun),
1534 accum_tx->agg.underrun,
1535 delta_tx->agg.underrun, max_tx->agg.underrun);
1536 pos += scnprintf(buf + pos, bufsz - pos,
1537 fmt_table, "agg bt_prio_kill:",
1538 le32_to_cpu(tx->agg.bt_prio_kill),
1539 accum_tx->agg.bt_prio_kill,
1540 delta_tx->agg.bt_prio_kill,
1541 max_tx->agg.bt_prio_kill);
1542 pos += scnprintf(buf + pos, bufsz - pos,
1543 fmt_table, "agg rx_ba_rsp_cnt:",
1544 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1545 accum_tx->agg.rx_ba_rsp_cnt,
1546 delta_tx->agg.rx_ba_rsp_cnt,
1547 max_tx->agg.rx_ba_rsp_cnt);
1548
1549 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1550 pos += scnprintf(buf + pos, bufsz - pos,
1551 "tx power: (1/2 dB step)\n");
Johannes Berg7e79a392012-03-05 11:24:32 -08001552 if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1553 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001554 pos += scnprintf(buf + pos, bufsz - pos,
1555 fmt_hex, "antenna A:",
1556 tx->tx_power.ant_a);
Johannes Berg7e79a392012-03-05 11:24:32 -08001557 if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1558 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001559 pos += scnprintf(buf + pos, bufsz - pos,
1560 fmt_hex, "antenna B:",
1561 tx->tx_power.ant_b);
Johannes Berg7e79a392012-03-05 11:24:32 -08001562 if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1563 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001564 pos += scnprintf(buf + pos, bufsz - pos,
1565 fmt_hex, "antenna C:",
1566 tx->tx_power.ant_c);
1567 }
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001568
1569 spin_unlock_bh(&priv->statistics.lock);
1570
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001571 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1572 kfree(buf);
1573 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001574}
1575
1576static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1577 char __user *user_buf,
1578 size_t count, loff_t *ppos)
1579{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001580 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001581 int pos = 0;
1582 char *buf;
1583 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1584 ssize_t ret;
1585 struct statistics_general_common *general, *accum_general;
1586 struct statistics_general_common *delta_general, *max_general;
1587 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1588 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1589
Don Fry83626402012-03-07 09:52:37 -08001590 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001591 return -EAGAIN;
1592
1593 buf = kzalloc(bufsz, GFP_KERNEL);
1594 if (!buf) {
1595 IWL_ERR(priv, "Can not allocate Buffer\n");
1596 return -ENOMEM;
1597 }
1598
1599 /* the statistic information display here is based on
1600 * the last statistics notification from uCode
1601 * might not reflect the current uCode activity
1602 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001603
1604 spin_lock_bh(&priv->statistics.lock);
1605
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001606 general = &priv->statistics.common;
1607 dbg = &priv->statistics.common.dbg;
1608 div = &priv->statistics.common.div;
1609 accum_general = &priv->accum_stats.common;
1610 accum_dbg = &priv->accum_stats.common.dbg;
1611 accum_div = &priv->accum_stats.common.div;
1612 delta_general = &priv->delta_stats.common;
1613 max_general = &priv->max_delta_stats.common;
1614 delta_dbg = &priv->delta_stats.common.dbg;
1615 max_dbg = &priv->max_delta_stats.common.dbg;
1616 delta_div = &priv->delta_stats.common.div;
1617 max_div = &priv->max_delta_stats.common.div;
1618
1619 pos += iwl_statistics_flag(priv, buf, bufsz);
1620 pos += scnprintf(buf + pos, bufsz - pos,
1621 fmt_header, "Statistics_General:");
1622 pos += scnprintf(buf + pos, bufsz - pos,
1623 fmt_value, "temperature:",
1624 le32_to_cpu(general->temperature));
1625 pos += scnprintf(buf + pos, bufsz - pos,
1626 fmt_value, "temperature_m:",
1627 le32_to_cpu(general->temperature_m));
1628 pos += scnprintf(buf + pos, bufsz - pos,
1629 fmt_value, "ttl_timestamp:",
1630 le32_to_cpu(general->ttl_timestamp));
1631 pos += scnprintf(buf + pos, bufsz - pos,
1632 fmt_table, "burst_check:",
1633 le32_to_cpu(dbg->burst_check),
1634 accum_dbg->burst_check,
1635 delta_dbg->burst_check, max_dbg->burst_check);
1636 pos += scnprintf(buf + pos, bufsz - pos,
1637 fmt_table, "burst_count:",
1638 le32_to_cpu(dbg->burst_count),
1639 accum_dbg->burst_count,
1640 delta_dbg->burst_count, max_dbg->burst_count);
1641 pos += scnprintf(buf + pos, bufsz - pos,
1642 fmt_table, "wait_for_silence_timeout_count:",
1643 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1644 accum_dbg->wait_for_silence_timeout_cnt,
1645 delta_dbg->wait_for_silence_timeout_cnt,
1646 max_dbg->wait_for_silence_timeout_cnt);
1647 pos += scnprintf(buf + pos, bufsz - pos,
1648 fmt_table, "sleep_time:",
1649 le32_to_cpu(general->sleep_time),
1650 accum_general->sleep_time,
1651 delta_general->sleep_time, max_general->sleep_time);
1652 pos += scnprintf(buf + pos, bufsz - pos,
1653 fmt_table, "slots_out:",
1654 le32_to_cpu(general->slots_out),
1655 accum_general->slots_out,
1656 delta_general->slots_out, max_general->slots_out);
1657 pos += scnprintf(buf + pos, bufsz - pos,
1658 fmt_table, "slots_idle:",
1659 le32_to_cpu(general->slots_idle),
1660 accum_general->slots_idle,
1661 delta_general->slots_idle, max_general->slots_idle);
1662 pos += scnprintf(buf + pos, bufsz - pos,
1663 fmt_table, "tx_on_a:",
1664 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1665 delta_div->tx_on_a, max_div->tx_on_a);
1666 pos += scnprintf(buf + pos, bufsz - pos,
1667 fmt_table, "tx_on_b:",
1668 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1669 delta_div->tx_on_b, max_div->tx_on_b);
1670 pos += scnprintf(buf + pos, bufsz - pos,
1671 fmt_table, "exec_time:",
1672 le32_to_cpu(div->exec_time), accum_div->exec_time,
1673 delta_div->exec_time, max_div->exec_time);
1674 pos += scnprintf(buf + pos, bufsz - pos,
1675 fmt_table, "probe_time:",
1676 le32_to_cpu(div->probe_time), accum_div->probe_time,
1677 delta_div->probe_time, max_div->probe_time);
1678 pos += scnprintf(buf + pos, bufsz - pos,
1679 fmt_table, "rx_enable_counter:",
1680 le32_to_cpu(general->rx_enable_counter),
1681 accum_general->rx_enable_counter,
1682 delta_general->rx_enable_counter,
1683 max_general->rx_enable_counter);
1684 pos += scnprintf(buf + pos, bufsz - pos,
1685 fmt_table, "num_of_sos_states:",
1686 le32_to_cpu(general->num_of_sos_states),
1687 accum_general->num_of_sos_states,
1688 delta_general->num_of_sos_states,
1689 max_general->num_of_sos_states);
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001690
1691 spin_unlock_bh(&priv->statistics.lock);
1692
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001693 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1694 kfree(buf);
1695 return ret;
1696}
1697
1698static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1699 char __user *user_buf,
1700 size_t count, loff_t *ppos)
1701{
1702 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1703 int pos = 0;
1704 char *buf;
1705 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1706 ssize_t ret;
1707 struct statistics_bt_activity *bt, *accum_bt;
1708
Don Fry83626402012-03-07 09:52:37 -08001709 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001710 return -EAGAIN;
1711
1712 if (!priv->bt_enable_flag)
1713 return -EINVAL;
1714
1715 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001716 mutex_lock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001717 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001718 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001719
1720 if (ret) {
1721 IWL_ERR(priv,
1722 "Error sending statistics request: %zd\n", ret);
1723 return -EAGAIN;
1724 }
1725 buf = kzalloc(bufsz, GFP_KERNEL);
1726 if (!buf) {
1727 IWL_ERR(priv, "Can not allocate Buffer\n");
1728 return -ENOMEM;
1729 }
1730
1731 /*
1732 * the statistic information display here is based on
1733 * the last statistics notification from uCode
1734 * might not reflect the current uCode activity
1735 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001736
1737 spin_lock_bh(&priv->statistics.lock);
1738
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001739 bt = &priv->statistics.bt_activity;
1740 accum_bt = &priv->accum_stats.bt_activity;
1741
1742 pos += iwl_statistics_flag(priv, buf, bufsz);
1743 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1744 pos += scnprintf(buf + pos, bufsz - pos,
1745 "\t\t\tcurrent\t\t\taccumulative\n");
1746 pos += scnprintf(buf + pos, bufsz - pos,
1747 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1748 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1749 accum_bt->hi_priority_tx_req_cnt);
1750 pos += scnprintf(buf + pos, bufsz - pos,
1751 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1752 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1753 accum_bt->hi_priority_tx_denied_cnt);
1754 pos += scnprintf(buf + pos, bufsz - pos,
1755 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1756 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1757 accum_bt->lo_priority_tx_req_cnt);
1758 pos += scnprintf(buf + pos, bufsz - pos,
1759 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1760 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1761 accum_bt->lo_priority_tx_denied_cnt);
1762 pos += scnprintf(buf + pos, bufsz - pos,
1763 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1764 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1765 accum_bt->hi_priority_rx_req_cnt);
1766 pos += scnprintf(buf + pos, bufsz - pos,
1767 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1768 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1769 accum_bt->hi_priority_rx_denied_cnt);
1770 pos += scnprintf(buf + pos, bufsz - pos,
1771 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1772 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1773 accum_bt->lo_priority_rx_req_cnt);
1774 pos += scnprintf(buf + pos, bufsz - pos,
1775 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1776 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1777 accum_bt->lo_priority_rx_denied_cnt);
1778
1779 pos += scnprintf(buf + pos, bufsz - pos,
1780 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1781 le32_to_cpu(priv->statistics.num_bt_kills),
1782 priv->statistics.accum_num_bt_kills);
1783
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001784 spin_unlock_bh(&priv->statistics.lock);
1785
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001786 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1787 kfree(buf);
1788 return ret;
1789}
1790
1791static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1792 char __user *user_buf,
1793 size_t count, loff_t *ppos)
1794{
1795 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1796 int pos = 0;
1797 char *buf;
1798 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1799 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1800 ssize_t ret;
1801
Don Fry83626402012-03-07 09:52:37 -08001802 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001803 return -EAGAIN;
1804
1805 buf = kzalloc(bufsz, GFP_KERNEL);
1806 if (!buf) {
1807 IWL_ERR(priv, "Can not allocate Buffer\n");
1808 return -ENOMEM;
1809 }
1810
1811 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1812 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1813 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001814 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001815 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1816 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001817 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001818 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1819 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001820 priv->reply_tx_stats.pp_bt_prio);
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_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001823 priv->reply_tx_stats.pp_quiet_period);
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_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001826 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001827 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1828 iwl_get_tx_fail_reason(
1829 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001830 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001831 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1832 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001833 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001834 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1835 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001836 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001837 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1838 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001839 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001840 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1841 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001842 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001843 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1844 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001845 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001846 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1847 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001848 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001849 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1850 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001851 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001852 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1853 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001854 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001855 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1856 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001857 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001858 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1859 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001860 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001861 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1862 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001863 priv->reply_tx_stats.frag_drop);
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_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001866 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001867 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1868 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001869 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001870 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1871 iwl_get_tx_fail_reason(
1872 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001873 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001874 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1875 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001876 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001877 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1878 iwl_get_tx_fail_reason(
1879 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001880 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001881 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001882 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001883
1884 pos += scnprintf(buf + pos, bufsz - pos,
1885 "\nStatistics_Agg_TX_Error:\n");
1886
1887 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1888 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001889 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001890 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1891 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001892 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001893 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1894 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001895 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001896 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1897 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001898 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001899 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1900 iwl_get_agg_tx_fail_reason(
1901 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001902 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001903 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1904 iwl_get_agg_tx_fail_reason(
1905 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001906 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001907 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1908 iwl_get_agg_tx_fail_reason(
1909 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001910 priv->reply_agg_tx_stats.last_sent_bt_kill);
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_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001913 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001914 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1915 iwl_get_agg_tx_fail_reason(
1916 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001917 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001918 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1919 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001920 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001921 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1922 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001923 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001924 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1925 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001926 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001927 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001928 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001929
1930 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1931 kfree(buf);
1932 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001933}
1934
Wey-Yi Guy52259352009-08-07 15:41:43 -07001935static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1936 char __user *user_buf,
1937 size_t count, loff_t *ppos) {
1938
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001939 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001940 int pos = 0;
1941 int cnt = 0;
1942 char *buf;
1943 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1944 ssize_t ret;
1945 struct iwl_sensitivity_data *data;
1946
1947 data = &priv->sensitivity_data;
1948 buf = kzalloc(bufsz, GFP_KERNEL);
1949 if (!buf) {
1950 IWL_ERR(priv, "Can not allocate Buffer\n");
1951 return -ENOMEM;
1952 }
1953
1954 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1955 data->auto_corr_ofdm);
1956 pos += scnprintf(buf + pos, bufsz - pos,
1957 "auto_corr_ofdm_mrc:\t\t %u\n",
1958 data->auto_corr_ofdm_mrc);
1959 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1960 data->auto_corr_ofdm_x1);
1961 pos += scnprintf(buf + pos, bufsz - pos,
1962 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1963 data->auto_corr_ofdm_mrc_x1);
1964 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1965 data->auto_corr_cck);
1966 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1967 data->auto_corr_cck_mrc);
1968 pos += scnprintf(buf + pos, bufsz - pos,
1969 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1970 data->last_bad_plcp_cnt_ofdm);
1971 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1972 data->last_fa_cnt_ofdm);
1973 pos += scnprintf(buf + pos, bufsz - pos,
1974 "last_bad_plcp_cnt_cck:\t\t %u\n",
1975 data->last_bad_plcp_cnt_cck);
1976 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1977 data->last_fa_cnt_cck);
1978 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1979 data->nrg_curr_state);
1980 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1981 data->nrg_prev_state);
1982 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1983 for (cnt = 0; cnt < 10; cnt++) {
1984 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1985 data->nrg_value[cnt]);
1986 }
1987 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1988 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1989 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1990 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1991 data->nrg_silence_rssi[cnt]);
1992 }
1993 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1994 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1995 data->nrg_silence_ref);
1996 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1997 data->nrg_energy_idx);
1998 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1999 data->nrg_silence_idx);
2000 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
2001 data->nrg_th_cck);
2002 pos += scnprintf(buf + pos, bufsz - pos,
2003 "nrg_auto_corr_silence_diff:\t %u\n",
2004 data->nrg_auto_corr_silence_diff);
2005 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
2006 data->num_in_cck_no_fa);
2007 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
2008 data->nrg_th_ofdm);
2009
2010 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2011 kfree(buf);
2012 return ret;
2013}
2014
2015
2016static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2017 char __user *user_buf,
2018 size_t count, loff_t *ppos) {
2019
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002020 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002021 int pos = 0;
2022 int cnt = 0;
2023 char *buf;
2024 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2025 ssize_t ret;
2026 struct iwl_chain_noise_data *data;
2027
2028 data = &priv->chain_noise_data;
2029 buf = kzalloc(bufsz, GFP_KERNEL);
2030 if (!buf) {
2031 IWL_ERR(priv, "Can not allocate Buffer\n");
2032 return -ENOMEM;
2033 }
2034
2035 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2036 data->active_chains);
2037 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2038 data->chain_noise_a);
2039 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2040 data->chain_noise_b);
2041 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2042 data->chain_noise_c);
2043 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2044 data->chain_signal_a);
2045 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2046 data->chain_signal_b);
2047 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2048 data->chain_signal_c);
2049 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2050 data->beacon_count);
2051
2052 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2053 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2054 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2055 data->disconn_array[cnt]);
2056 }
2057 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2058 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2059 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2060 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2061 data->delta_gain_code[cnt]);
2062 }
2063 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2064 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2065 data->radio_write);
2066 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2067 data->state);
2068
2069 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2070 kfree(buf);
2071 return ret;
2072}
2073
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002074static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2075 char __user *user_buf,
2076 size_t count, loff_t *ppos)
2077{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002078 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002079 char buf[60];
2080 int pos = 0;
2081 const size_t bufsz = sizeof(buf);
2082 u32 pwrsave_status;
2083
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002084 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002085 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2086
2087 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2088 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2089 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2090 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2091 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2092 "error");
2093
2094 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2095}
2096
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002097static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002098 const char __user *user_buf,
2099 size_t count, loff_t *ppos)
2100{
2101 struct iwl_priv *priv = file->private_data;
2102 char buf[8];
2103 int buf_size;
2104 int clear;
2105
2106 memset(buf, 0, sizeof(buf));
2107 buf_size = min(count, sizeof(buf) - 1);
2108 if (copy_from_user(buf, user_buf, buf_size))
2109 return -EFAULT;
2110 if (sscanf(buf, "%d", &clear) != 1)
2111 return -EFAULT;
2112
2113 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08002114 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002115 iwl_send_statistics_request(priv, CMD_SYNC, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08002116 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002117
2118 return count;
2119}
2120
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002121static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2122 char __user *user_buf,
2123 size_t count, loff_t *ppos) {
2124
Joe Perches57674302010-07-12 13:50:06 -07002125 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002126 int pos = 0;
2127 char buf[128];
2128 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002129
2130 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2131 priv->event_log.ucode_trace ? "On" : "Off");
2132 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2133 priv->event_log.non_wraps_count);
2134 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2135 priv->event_log.wraps_once_count);
2136 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2137 priv->event_log.wraps_more_count);
2138
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002139 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002140}
2141
2142static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2143 const char __user *user_buf,
2144 size_t count, loff_t *ppos)
2145{
2146 struct iwl_priv *priv = file->private_data;
2147 char buf[8];
2148 int buf_size;
2149 int trace;
2150
2151 memset(buf, 0, sizeof(buf));
2152 buf_size = min(count, sizeof(buf) - 1);
2153 if (copy_from_user(buf, user_buf, buf_size))
2154 return -EFAULT;
2155 if (sscanf(buf, "%d", &trace) != 1)
2156 return -EFAULT;
2157
2158 if (trace) {
2159 priv->event_log.ucode_trace = true;
Don Fry83626402012-03-07 09:52:37 -08002160 if (iwl_is_alive(priv)) {
Johannes Berg98d4bf02012-01-13 11:56:11 +01002161 /* start collecting data now */
2162 mod_timer(&priv->ucode_trace, jiffies);
2163 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002164 } else {
2165 priv->event_log.ucode_trace = false;
2166 del_timer_sync(&priv->ucode_trace);
2167 }
2168
2169 return count;
2170}
2171
Johannes Berg60987202010-02-18 00:36:07 -08002172static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2173 char __user *user_buf,
2174 size_t count, loff_t *ppos) {
2175
Joe Perches57674302010-07-12 13:50:06 -07002176 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002177 int len = 0;
2178 char buf[20];
2179
Johannes Berg246ed352010-08-23 10:46:32 +02002180 len = sprintf(buf, "0x%04X\n",
2181 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002182 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2183}
2184
2185static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2186 char __user *user_buf,
2187 size_t count, loff_t *ppos) {
2188
Joe Perches57674302010-07-12 13:50:06 -07002189 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002190 int len = 0;
2191 char buf[20];
2192
2193 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002194 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002195 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2196}
2197
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002198static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2199 char __user *user_buf,
2200 size_t count, loff_t *ppos) {
2201
2202 struct iwl_priv *priv = file->private_data;
2203 int pos = 0;
2204 char buf[12];
2205 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002206
2207 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2208 priv->missed_beacon_threshold);
2209
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002210 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002211}
2212
2213static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2214 const char __user *user_buf,
2215 size_t count, loff_t *ppos)
2216{
2217 struct iwl_priv *priv = file->private_data;
2218 char buf[8];
2219 int buf_size;
2220 int missed;
2221
2222 memset(buf, 0, sizeof(buf));
2223 buf_size = min(count, sizeof(buf) - 1);
2224 if (copy_from_user(buf, user_buf, buf_size))
2225 return -EFAULT;
2226 if (sscanf(buf, "%d", &missed) != 1)
2227 return -EINVAL;
2228
2229 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2230 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2231 priv->missed_beacon_threshold =
2232 IWL_MISSED_BEACON_THRESHOLD_DEF;
2233 else
2234 priv->missed_beacon_threshold = missed;
2235
2236 return count;
2237}
2238
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002239static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2240 char __user *user_buf,
2241 size_t count, loff_t *ppos) {
2242
Joe Perches57674302010-07-12 13:50:06 -07002243 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002244 int pos = 0;
2245 char buf[12];
2246 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002247
2248 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002249 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002250
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002251 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002252}
2253
2254static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2255 const char __user *user_buf,
2256 size_t count, loff_t *ppos) {
2257
2258 struct iwl_priv *priv = file->private_data;
2259 char buf[8];
2260 int buf_size;
2261 int plcp;
2262
2263 memset(buf, 0, sizeof(buf));
2264 buf_size = min(count, sizeof(buf) - 1);
2265 if (copy_from_user(buf, user_buf, buf_size))
2266 return -EFAULT;
2267 if (sscanf(buf, "%d", &plcp) != 1)
2268 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002269 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002270 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002271 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002272 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002273 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002274 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002275 return count;
2276}
2277
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002278static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2279 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002280 size_t count, loff_t *ppos)
2281{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002282 struct iwl_priv *priv = file->private_data;
2283 int i, pos = 0;
2284 char buf[300];
2285 const size_t bufsz = sizeof(buf);
2286 struct iwl_force_reset *force_reset;
2287
2288 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2289 force_reset = &priv->force_reset[i];
2290 pos += scnprintf(buf + pos, bufsz - pos,
2291 "Force reset method %d\n", i);
2292 pos += scnprintf(buf + pos, bufsz - pos,
2293 "\tnumber of reset request: %d\n",
2294 force_reset->reset_request_count);
2295 pos += scnprintf(buf + pos, bufsz - pos,
2296 "\tnumber of reset request success: %d\n",
2297 force_reset->reset_success_count);
2298 pos += scnprintf(buf + pos, bufsz - pos,
2299 "\tnumber of reset request reject: %d\n",
2300 force_reset->reset_reject_count);
2301 pos += scnprintf(buf + pos, bufsz - pos,
2302 "\treset duration: %lu\n",
2303 force_reset->reset_duration);
2304 }
2305 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2306}
2307
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002308static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2309 const char __user *user_buf,
2310 size_t count, loff_t *ppos) {
2311
2312 struct iwl_priv *priv = file->private_data;
2313 char buf[8];
2314 int buf_size;
2315 int reset, ret;
2316
2317 memset(buf, 0, sizeof(buf));
2318 buf_size = min(count, sizeof(buf) - 1);
2319 if (copy_from_user(buf, user_buf, buf_size))
2320 return -EFAULT;
2321 if (sscanf(buf, "%d", &reset) != 1)
2322 return -EINVAL;
2323 switch (reset) {
2324 case IWL_RF_RESET:
2325 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002326 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002327 break;
2328 default:
2329 return -EINVAL;
2330 }
2331 return ret ? ret : count;
2332}
2333
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002334static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2335 const char __user *user_buf,
2336 size_t count, loff_t *ppos) {
2337
2338 struct iwl_priv *priv = file->private_data;
2339 char buf[8];
2340 int buf_size;
2341 int flush;
2342
2343 memset(buf, 0, sizeof(buf));
2344 buf_size = min(count, sizeof(buf) - 1);
2345 if (copy_from_user(buf, user_buf, buf_size))
2346 return -EFAULT;
2347 if (sscanf(buf, "%d", &flush) != 1)
2348 return -EINVAL;
2349
Don Fry83626402012-03-07 09:52:37 -08002350 if (iwl_is_rfkill(priv))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002351 return -EFAULT;
2352
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002353 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002354
2355 return count;
2356}
2357
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002358static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002359 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002360 size_t count, loff_t *ppos)
2361{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002362 struct iwl_priv *priv = file->private_data;
2363 char buf[8];
2364 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002365 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002366
2367 memset(buf, 0, sizeof(buf));
2368 buf_size = min(count, sizeof(buf) - 1);
2369 if (copy_from_user(buf, user_buf, buf_size))
2370 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002371 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002372 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002373 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2374 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002375
Johannes Berge7a09432012-03-06 13:30:54 -08002376 hw_params(priv).wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002377 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002378 return count;
2379}
2380
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002381static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2382 char __user *user_buf,
2383 size_t count, loff_t *ppos) {
2384
2385 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2386 int pos = 0;
2387 char buf[200];
2388 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002389
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002390 if (!priv->bt_enable_flag) {
2391 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002392 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002393 }
2394 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2395 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002396 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2397 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2398 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2399 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002400 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002401 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002402 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2403 priv->bt_ch_announce, priv->kill_ack_mask,
2404 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002405
2406 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2407 switch (priv->bt_traffic_load) {
2408 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2409 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2410 break;
2411 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2412 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2413 break;
2414 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2415 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2416 break;
2417 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2418 default:
2419 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2420 break;
2421 }
2422
Johannes Berg08960de2011-04-05 09:41:53 -07002423 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002424}
2425
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002426static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2427 char __user *user_buf,
2428 size_t count, loff_t *ppos)
2429{
2430 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2431
2432 int pos = 0;
2433 char buf[40];
2434 const size_t bufsz = sizeof(buf);
2435
Don Fry38622412011-12-16 07:07:36 -08002436 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002437 pos += scnprintf(buf + pos, bufsz - pos,
2438 "use %s for aggregation\n",
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002439 (hw_params(priv).use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002440 "rts/cts" : "cts-to-self");
2441 else
2442 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2443
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002444 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2445}
2446
2447static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2448 const char __user *user_buf,
2449 size_t count, loff_t *ppos) {
2450
2451 struct iwl_priv *priv = file->private_data;
2452 char buf[8];
2453 int buf_size;
2454 int rts;
2455
Don Fry38622412011-12-16 07:07:36 -08002456 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002457 return -EINVAL;
2458
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002459 memset(buf, 0, sizeof(buf));
2460 buf_size = min(count, sizeof(buf) - 1);
2461 if (copy_from_user(buf, user_buf, buf_size))
2462 return -EFAULT;
2463 if (sscanf(buf, "%d", &rts) != 1)
2464 return -EINVAL;
2465 if (rts)
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002466 hw_params(priv).use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002467 else
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002468 hw_params(priv).use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002469 return count;
2470}
2471
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002472static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2473 const char __user *user_buf,
2474 size_t count, loff_t *ppos)
2475{
2476 struct iwl_priv *priv = file->private_data;
2477 char buf[8];
2478 int buf_size;
2479
2480 memset(buf, 0, sizeof(buf));
2481 buf_size = min(count, sizeof(buf) - 1);
2482 if (copy_from_user(buf, user_buf, buf_size))
2483 return -EFAULT;
2484
2485 iwl_cmd_echo_test(priv);
2486 return count;
2487}
2488
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002489DEBUGFS_READ_FILE_OPS(rx_statistics);
2490DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002491DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002492DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2493DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2494DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002495DEBUGFS_READ_FILE_OPS(sensitivity);
2496DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002497DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002498DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2499DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002500DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002501DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002502DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002503DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002504DEBUGFS_READ_FILE_OPS(rxon_flags);
2505DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002506DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002507DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002508DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002509DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002510DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002511DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002512DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002513
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002514/*
2515 * Create the debugfs files and directories
2516 *
2517 */
2518int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2519{
Zhu Yi95b1a822008-05-29 16:34:50 +08002520 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002521 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002522
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002523 dir_drv = debugfs_create_dir(name, phyd);
2524 if (!dir_drv)
2525 return -ENOMEM;
2526
2527 priv->debugfs_dir = dir_drv;
2528
2529 dir_data = debugfs_create_dir("data", dir_drv);
2530 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002531 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002532 dir_rf = debugfs_create_dir("rf", dir_drv);
2533 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002534 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002535 dir_debug = debugfs_create_dir("debug", dir_drv);
2536 if (!dir_debug)
2537 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002538
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002539 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2540 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002541 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002542 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2543 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2544 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002545 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002546 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002547 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2548 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002549 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2550 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002551 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002552
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002553 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2554 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002555 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002556 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2557 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2558 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002559 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002560 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002561 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002562 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2563 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2564 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002565 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002566 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002567 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2568 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002569 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002570 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002571 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002572 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2573 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002574 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002575 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002576 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002577 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002578
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002579 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2580 &priv->disable_sens_cal);
2581 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2582 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002583
2584 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2585 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002586 return 0;
2587
2588err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002589 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002590 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002591 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002592}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002593
2594/**
2595 * Remove the debugfs files and directories
2596 *
2597 */
2598void iwl_dbgfs_unregister(struct iwl_priv *priv)
2599{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002600 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002601 return;
2602
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002603 debugfs_remove_recursive(priv->debugfs_dir);
2604 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002605}