blob: b7b1c04f2fba4c7b449d8106de5471b6548c1d2c [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;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800233 const struct fw_img *img;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800234 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700235
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800236 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800237 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
238 priv->dbgfs_sram_offset = 0x800000;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800239 if (!priv->ucode_loaded) {
240 IWL_ERR(priv, "No uCode has been loadded.\n");
241 return -EINVAL;
242 }
David Spinadel6dfa8d02012-03-10 13:00:14 -0800243 img = &priv->fw->img[priv->shrd->ucode_type];
244 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800245 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800246 len = priv->dbgfs_sram_len;
247
248 if (len == -4) {
249 device_format = true;
250 len = 4;
251 }
252
253 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800254 buf = kmalloc(bufsz, GFP_KERNEL);
255 if (!buf)
256 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800257
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800258 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800259 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800260 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800261 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800262
263 /* adjust sram address since reads are only on even u32 boundaries */
264 offset = priv->dbgfs_sram_offset & 0x3;
265 sram = priv->dbgfs_sram_offset & ~0x3;
266
267 /* read the first u32 from sram */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200268 val = iwl_read_targ_mem(trans(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800269
270 for (; len; len--) {
271 /* put the address at the start of every line */
272 if (i == 0)
273 pos += scnprintf(buf + pos, bufsz - pos,
274 "%08X: ", sram + offset);
275
276 if (device_format)
277 pos += scnprintf(buf + pos, bufsz - pos,
278 "%02x", (val >> (8 * (3 - offset))) & 0xff);
279 else
280 pos += scnprintf(buf + pos, bufsz - pos,
281 "%02x ", (val >> (8 * offset)) & 0xff);
282
283 /* if all bytes processed, read the next u32 from sram */
284 if (++offset == 4) {
285 sram += 4;
286 offset = 0;
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200287 val = iwl_read_targ_mem(trans(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700288 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800289
290 /* put in extra spaces and split lines for human readability */
291 if (++i == 16) {
292 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800293 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800294 } else if (!(i & 7)) {
295 pos += scnprintf(buf + pos, bufsz - pos, " ");
296 } else if (!(i & 3)) {
297 pos += scnprintf(buf + pos, bufsz - pos, " ");
298 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700299 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800300 if (i)
301 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700302
303 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800304 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700305 return ret;
306}
307
308static ssize_t iwl_dbgfs_sram_write(struct file *file,
309 const char __user *user_buf,
310 size_t count, loff_t *ppos)
311{
312 struct iwl_priv *priv = file->private_data;
313 char buf[64];
314 int buf_size;
315 u32 offset, len;
316
317 memset(buf, 0, sizeof(buf));
318 buf_size = min(count, sizeof(buf) - 1);
319 if (copy_from_user(buf, user_buf, buf_size))
320 return -EFAULT;
321
322 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800323 priv->dbgfs_sram_offset = offset;
324 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800325 } else if (sscanf(buf, "%x", &offset) == 1) {
326 priv->dbgfs_sram_offset = offset;
327 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700328 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800329 priv->dbgfs_sram_offset = 0;
330 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700331 }
332
333 return count;
334}
335
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700336static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
337 char __user *user_buf,
338 size_t count, loff_t *ppos)
339{
340 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800341 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700342
343 if (!priv->wowlan_sram)
344 return -ENODATA;
345
346 return simple_read_from_buffer(user_buf, count, ppos,
347 priv->wowlan_sram,
David Spinadel6dfa8d02012-03-10 13:00:14 -0800348 img->sec[IWL_UCODE_SECTION_DATA].len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700349}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700350static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
351 size_t count, loff_t *ppos)
352{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700353 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800354 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700355 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700356 char *buf;
357 int i, j, pos = 0;
358 ssize_t ret;
359 /* Add 30 for initial string */
360 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700361
362 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300363 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700364 return -ENOMEM;
365
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700366 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700367 priv->num_stations);
368
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700369 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700370 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700371 if (!station->used)
372 continue;
373 pos += scnprintf(buf + pos, bufsz - pos,
374 "station %d - addr: %pM, flags: %#x\n",
375 i, station->sta.sta.addr,
376 station->sta.station_flags_msk);
377 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200378 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700379
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700380 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200381 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700382 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200383 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700384 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700385 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700386
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700387 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700388 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700389 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700390 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700391 }
Johannes Bergda735112010-05-03 01:25:24 -0700392
393 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700394 }
395
396 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
397 kfree(buf);
398 return ret;
399}
400
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700401static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800402 char __user *user_buf,
403 size_t count,
404 loff_t *ppos)
405{
406 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700407 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800408 int pos = 0, ofs = 0, buf_size = 0;
409 const u8 *ptr;
410 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700411 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800412 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800413 buf_size = 4 * eeprom_len + 256;
414
415 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700416 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800417 return -ENODATA;
418 }
419
Don Fryab36eab2011-11-30 15:37:32 -0800420 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200421 if (!ptr) {
422 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
423 return -ENOMEM;
424 }
425
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800426 /* 4 characters for byte 0xYY */
427 buf = kzalloc(buf_size, GFP_KERNEL);
428 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800429 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800430 return -ENOMEM;
431 }
Don Fryab36eab2011-11-30 15:37:32 -0800432 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700433 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
434 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800435 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700436 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800437 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
438 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
439 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
440 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700441 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800442 if (buf_size - pos > 0)
443 buf[pos++] = '\n';
444 }
445
446 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
447 kfree(buf);
448 return ret;
449}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700450
Winkler, Tomasd366df52008-12-02 12:14:01 -0800451static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
452 size_t count, loff_t *ppos)
453{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700454 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800455 struct ieee80211_channel *channels = NULL;
456 const struct ieee80211_supported_band *supp_band = NULL;
457 int pos = 0, i, bufsz = PAGE_SIZE;
458 char *buf;
459 ssize_t ret;
460
Don Fry83626402012-03-07 09:52:37 -0800461 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800462 return -EAGAIN;
463
464 buf = kzalloc(bufsz, GFP_KERNEL);
465 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800466 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800467 return -ENOMEM;
468 }
469
470 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700471 if (supp_band) {
472 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800473
Winkler, Tomasd366df52008-12-02 12:14:01 -0800474 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700475 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
476 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800477
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700478 for (i = 0; i < supp_band->n_channels; i++)
479 pos += scnprintf(buf + pos, bufsz - pos,
480 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700481 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700482 channels[i].max_power,
483 channels[i].flags & IEEE80211_CHAN_RADAR ?
484 " (IEEE 802.11h required)" : "",
485 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
486 || (channels[i].flags &
487 IEEE80211_CHAN_RADAR)) ? "" :
488 ", IBSS",
489 channels[i].flags &
490 IEEE80211_CHAN_PASSIVE_SCAN ?
491 "passive only" : "active/passive");
492 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800493 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700494 if (supp_band) {
495 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800496
Winkler, Tomasd366df52008-12-02 12:14:01 -0800497 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700498 "Displaying %d channels in 5.2GHz band (802.11a)\n",
499 supp_band->n_channels);
500
501 for (i = 0; i < supp_band->n_channels; i++)
502 pos += scnprintf(buf + pos, bufsz - pos,
503 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700504 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700505 channels[i].max_power,
506 channels[i].flags & IEEE80211_CHAN_RADAR ?
507 " (IEEE 802.11h required)" : "",
508 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
509 || (channels[i].flags &
510 IEEE80211_CHAN_RADAR)) ? "" :
511 ", IBSS",
512 channels[i].flags &
513 IEEE80211_CHAN_PASSIVE_SCAN ?
514 "passive only" : "active/passive");
515 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800516 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
517 kfree(buf);
518 return ret;
519}
520
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700521static ssize_t iwl_dbgfs_status_read(struct file *file,
522 char __user *user_buf,
523 size_t count, loff_t *ppos) {
524
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700525 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700526 char buf[512];
527 int pos = 0;
528 const size_t bufsz = sizeof(buf);
529
530 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700531 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700532 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800533 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700534 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800535 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700536 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800537 test_bit(STATUS_ALIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700538 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800539 test_bit(STATUS_READY, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700540 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800541 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700542 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800543 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700544 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800545 test_bit(STATUS_STATISTICS, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700546 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800547 test_bit(STATUS_SCANNING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700548 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800549 test_bit(STATUS_SCAN_ABORTING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700550 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800551 test_bit(STATUS_SCAN_HW, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700552 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700553 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700554 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700555 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700556 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
557}
558
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700559static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700560 char __user *user_buf,
561 size_t count, loff_t *ppos) {
562
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700563 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700564
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700565 int pos = 0;
566 int cnt = 0;
567 char *buf;
568 int bufsz = 24 * 64; /* 24 items * 64 char per item */
569 ssize_t ret;
570
571 buf = kzalloc(bufsz, GFP_KERNEL);
572 if (!buf) {
573 IWL_ERR(priv, "Can not allocate Buffer\n");
574 return -ENOMEM;
575 }
576
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700577 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700578 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700579 pos += scnprintf(buf + pos, bufsz - pos,
580 "\tRx handler[%36s]:\t\t %u\n",
581 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700582 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700583 }
584
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700585 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
586 kfree(buf);
587 return ret;
588}
589
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700590static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700591 const char __user *user_buf,
592 size_t count, loff_t *ppos)
593{
594 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700595
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700596 char buf[8];
597 int buf_size;
598 u32 reset_flag;
599
600 memset(buf, 0, sizeof(buf));
601 buf_size = min(count, sizeof(buf) - 1);
602 if (copy_from_user(buf, user_buf, buf_size))
603 return -EFAULT;
604 if (sscanf(buf, "%x", &reset_flag) != 1)
605 return -EFAULT;
606 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700607 memset(&priv->rx_handlers_stats[0], 0,
608 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700609
610 return count;
611}
612
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700613static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
614 size_t count, loff_t *ppos)
615{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700616 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200617 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700618 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200619 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700620 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700621
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200622 for_each_context(priv, ctx) {
623 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
624 ctx->ctxid);
625 for (i = 0; i < AC_NUM; i++) {
626 pos += scnprintf(buf + pos, bufsz - pos,
627 "\tcw_min\tcw_max\taifsn\ttxop\n");
628 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700629 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200630 ctx->qos_data.def_qos_parm.ac[i].cw_min,
631 ctx->qos_data.def_qos_parm.ac[i].cw_max,
632 ctx->qos_data.def_qos_parm.ac[i].aifsn,
633 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
634 }
635 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700636 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800637 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700638}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700639
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700640static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
641 char __user *user_buf,
642 size_t count, loff_t *ppos)
643{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700644 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700645 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700646 struct iwl_tt_restriction *restriction;
647 char buf[100];
648 int pos = 0;
649 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700650
651 pos += scnprintf(buf + pos, bufsz - pos,
652 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700653 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700654 pos += scnprintf(buf + pos, bufsz - pos,
655 "Thermal Throttling State: %d\n",
656 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700657 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700658 restriction = tt->restriction + tt->state;
659 pos += scnprintf(buf + pos, bufsz - pos,
660 "Tx mode: %d\n",
661 restriction->tx_stream);
662 pos += scnprintf(buf + pos, bufsz - pos,
663 "Rx mode: %d\n",
664 restriction->rx_stream);
665 pos += scnprintf(buf + pos, bufsz - pos,
666 "HT mode: %d\n",
667 restriction->is_ht);
668 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800669 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700670}
671
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700672static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
673 const char __user *user_buf,
674 size_t count, loff_t *ppos)
675{
676 struct iwl_priv *priv = file->private_data;
677 char buf[8];
678 int buf_size;
679 int ht40;
680
681 memset(buf, 0, sizeof(buf));
682 buf_size = min(count, sizeof(buf) - 1);
683 if (copy_from_user(buf, user_buf, buf_size))
684 return -EFAULT;
685 if (sscanf(buf, "%d", &ht40) != 1)
686 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200687 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700688 priv->disable_ht40 = ht40 ? true : false;
689 else {
690 IWL_ERR(priv, "Sta associated with AP - "
691 "Change to 40MHz channel support is not allowed\n");
692 return -EINVAL;
693 }
694
695 return count;
696}
697
698static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
699 char __user *user_buf,
700 size_t count, loff_t *ppos)
701{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700702 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700703 char buf[100];
704 int pos = 0;
705 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700706
707 pos += scnprintf(buf + pos, bufsz - pos,
708 "11n 40MHz Mode: %s\n",
709 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800710 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700711}
712
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700713static ssize_t iwl_dbgfs_temperature_read(struct file *file,
714 char __user *user_buf,
715 size_t count, loff_t *ppos)
716{
717 struct iwl_priv *priv = file->private_data;
718 char buf[8];
719 int pos = 0;
720 const size_t bufsz = sizeof(buf);
721
722 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
723 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
724}
725
726
Johannes Berge312c242009-08-07 15:41:51 -0700727static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
728 const char __user *user_buf,
729 size_t count, loff_t *ppos)
730{
731 struct iwl_priv *priv = file->private_data;
732 char buf[8];
733 int buf_size;
734 int value;
735
736 memset(buf, 0, sizeof(buf));
737 buf_size = min(count, sizeof(buf) - 1);
738 if (copy_from_user(buf, user_buf, buf_size))
739 return -EFAULT;
740
741 if (sscanf(buf, "%d", &value) != 1)
742 return -EINVAL;
743
744 /*
745 * Our users expect 0 to be "CAM", but 0 isn't actually
746 * valid here. However, let's not confuse them and present
747 * IWL_POWER_INDEX_1 as "1", not "0".
748 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700749 if (value == 0)
750 return -EINVAL;
751 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700752 value -= 1;
753
754 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
755 return -EINVAL;
756
Don Fry83626402012-03-07 09:52:37 -0800757 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700758 return -EAGAIN;
759
Johannes Berge312c242009-08-07 15:41:51 -0700760 priv->power_data.debug_sleep_level_override = value;
761
Johannes Bergb1eea292012-03-06 13:30:42 -0800762 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700763 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800764 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700765
766 return count;
767}
768
769static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
770 char __user *user_buf,
771 size_t count, loff_t *ppos)
772{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700773 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700774 char buf[10];
775 int pos, value;
776 const size_t bufsz = sizeof(buf);
777
778 /* see the write function */
779 value = priv->power_data.debug_sleep_level_override;
780 if (value >= 0)
781 value += 1;
782
783 pos = scnprintf(buf, bufsz, "%d\n", value);
784 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
785}
786
787static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
788 char __user *user_buf,
789 size_t count, loff_t *ppos)
790{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700791 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700792 char buf[200];
793 int pos = 0, i;
794 const size_t bufsz = sizeof(buf);
795 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
796
797 pos += scnprintf(buf + pos, bufsz - pos,
798 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
799 pos += scnprintf(buf + pos, bufsz - pos,
800 "RX/TX timeout: %d/%d usec\n",
801 le32_to_cpu(cmd->rx_data_timeout),
802 le32_to_cpu(cmd->tx_data_timeout));
803 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
804 pos += scnprintf(buf + pos, bufsz - pos,
805 "sleep_interval[%d]: %d\n", i,
806 le32_to_cpu(cmd->sleep_interval[i]));
807
808 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
809}
810
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700811DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700812DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700813DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700814DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800815DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700816DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700817DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700818DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700819DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700820DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700821DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700822DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
823DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700824
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700825static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
826 char __user *user_buf,
827 size_t count, loff_t *ppos)
828{
829 struct iwl_priv *priv = file->private_data;
830 int pos = 0, ofs = 0;
831 int cnt = 0, entry;
832
833 char *buf;
834 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy1745e442012-03-09 11:13:40 -0800835 (cfg(priv)->base_params->num_of_queues * 32 * 8) + 400;
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700836 const u8 *ptr;
837 ssize_t ret;
838
839 buf = kzalloc(bufsz, GFP_KERNEL);
840 if (!buf) {
841 IWL_ERR(priv, "Can not allocate buffer\n");
842 return -ENOMEM;
843 }
Johannes Berga8bceb32012-03-05 11:24:30 -0800844 if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700845 ptr = priv->tx_traffic;
846 pos += scnprintf(buf + pos, bufsz - pos,
847 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
848 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
849 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
850 entry++, ofs += 16) {
851 pos += scnprintf(buf + pos, bufsz - pos,
852 "0x%.4x ", ofs);
853 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
854 buf + pos, bufsz - pos, 0);
855 pos += strlen(buf + pos);
856 if (bufsz - pos > 0)
857 buf[pos++] = '\n';
858 }
859 }
860 }
861
Johannes Berga8bceb32012-03-05 11:24:30 -0800862 if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700863 ptr = priv->rx_traffic;
864 pos += scnprintf(buf + pos, bufsz - pos,
865 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
866 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
867 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
868 entry++, ofs += 16) {
869 pos += scnprintf(buf + pos, bufsz - pos,
870 "0x%.4x ", ofs);
871 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
872 buf + pos, bufsz - pos, 0);
873 pos += strlen(buf + pos);
874 if (bufsz - pos > 0)
875 buf[pos++] = '\n';
876 }
877 }
878 }
879
880 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
881 kfree(buf);
882 return ret;
883}
884
885static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
886 const char __user *user_buf,
887 size_t count, loff_t *ppos)
888{
889 struct iwl_priv *priv = file->private_data;
890 char buf[8];
891 int buf_size;
892 int traffic_log;
893
894 memset(buf, 0, sizeof(buf));
895 buf_size = min(count, sizeof(buf) - 1);
896 if (copy_from_user(buf, user_buf, buf_size))
897 return -EFAULT;
898 if (sscanf(buf, "%d", &traffic_log) != 1)
899 return -EFAULT;
900 if (traffic_log == 0)
901 iwl_reset_traffic_log(priv);
902
903 return count;
904}
905
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700906static const char *fmt_value = " %-30s %10u\n";
907static const char *fmt_hex = " %-30s 0x%02X\n";
908static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
909static const char *fmt_header =
910 "%-32s current cumulative delta max\n";
911
912static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
913{
914 int p = 0;
915 u32 flag;
916
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800917 lockdep_assert_held(&priv->statistics.lock);
918
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700919 flag = le32_to_cpu(priv->statistics.flag);
920
921 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
922 if (flag & UCODE_STATISTICS_CLEAR_MSK)
923 p += scnprintf(buf + p, bufsz - p,
924 "\tStatistics have been cleared\n");
925 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
926 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
927 ? "2.4 GHz" : "5.2 GHz");
928 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
929 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
930 ? "enabled" : "disabled");
931
932 return p;
933}
934
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700935static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
936 char __user *user_buf,
937 size_t count, loff_t *ppos)
938{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700939 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700940 int pos = 0;
941 char *buf;
942 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
943 sizeof(struct statistics_rx_non_phy) * 40 +
944 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
945 ssize_t ret;
946 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
947 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
948 struct statistics_rx_non_phy *general, *accum_general;
949 struct statistics_rx_non_phy *delta_general, *max_general;
950 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
951
Don Fry83626402012-03-07 09:52:37 -0800952 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700953 return -EAGAIN;
954
955 buf = kzalloc(bufsz, GFP_KERNEL);
956 if (!buf) {
957 IWL_ERR(priv, "Can not allocate Buffer\n");
958 return -ENOMEM;
959 }
960
961 /*
962 * the statistic information display here is based on
963 * the last statistics notification from uCode
964 * might not reflect the current uCode activity
965 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800966 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700967 ofdm = &priv->statistics.rx_ofdm;
968 cck = &priv->statistics.rx_cck;
969 general = &priv->statistics.rx_non_phy;
970 ht = &priv->statistics.rx_ofdm_ht;
971 accum_ofdm = &priv->accum_stats.rx_ofdm;
972 accum_cck = &priv->accum_stats.rx_cck;
973 accum_general = &priv->accum_stats.rx_non_phy;
974 accum_ht = &priv->accum_stats.rx_ofdm_ht;
975 delta_ofdm = &priv->delta_stats.rx_ofdm;
976 delta_cck = &priv->delta_stats.rx_cck;
977 delta_general = &priv->delta_stats.rx_non_phy;
978 delta_ht = &priv->delta_stats.rx_ofdm_ht;
979 max_ofdm = &priv->max_delta_stats.rx_ofdm;
980 max_cck = &priv->max_delta_stats.rx_cck;
981 max_general = &priv->max_delta_stats.rx_non_phy;
982 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
983
984 pos += iwl_statistics_flag(priv, buf, bufsz);
985 pos += scnprintf(buf + pos, bufsz - pos,
986 fmt_header, "Statistics_Rx - OFDM:");
987 pos += scnprintf(buf + pos, bufsz - pos,
988 fmt_table, "ina_cnt:",
989 le32_to_cpu(ofdm->ina_cnt),
990 accum_ofdm->ina_cnt,
991 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
992 pos += scnprintf(buf + pos, bufsz - pos,
993 fmt_table, "fina_cnt:",
994 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
995 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
996 pos += scnprintf(buf + pos, bufsz - pos,
997 fmt_table, "plcp_err:",
998 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
999 delta_ofdm->plcp_err, max_ofdm->plcp_err);
1000 pos += scnprintf(buf + pos, bufsz - pos,
1001 fmt_table, "crc32_err:",
1002 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1003 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1004 pos += scnprintf(buf + pos, bufsz - pos,
1005 fmt_table, "overrun_err:",
1006 le32_to_cpu(ofdm->overrun_err),
1007 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1008 max_ofdm->overrun_err);
1009 pos += scnprintf(buf + pos, bufsz - pos,
1010 fmt_table, "early_overrun_err:",
1011 le32_to_cpu(ofdm->early_overrun_err),
1012 accum_ofdm->early_overrun_err,
1013 delta_ofdm->early_overrun_err,
1014 max_ofdm->early_overrun_err);
1015 pos += scnprintf(buf + pos, bufsz - pos,
1016 fmt_table, "crc32_good:",
1017 le32_to_cpu(ofdm->crc32_good),
1018 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1019 max_ofdm->crc32_good);
1020 pos += scnprintf(buf + pos, bufsz - pos,
1021 fmt_table, "false_alarm_cnt:",
1022 le32_to_cpu(ofdm->false_alarm_cnt),
1023 accum_ofdm->false_alarm_cnt,
1024 delta_ofdm->false_alarm_cnt,
1025 max_ofdm->false_alarm_cnt);
1026 pos += scnprintf(buf + pos, bufsz - pos,
1027 fmt_table, "fina_sync_err_cnt:",
1028 le32_to_cpu(ofdm->fina_sync_err_cnt),
1029 accum_ofdm->fina_sync_err_cnt,
1030 delta_ofdm->fina_sync_err_cnt,
1031 max_ofdm->fina_sync_err_cnt);
1032 pos += scnprintf(buf + pos, bufsz - pos,
1033 fmt_table, "sfd_timeout:",
1034 le32_to_cpu(ofdm->sfd_timeout),
1035 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1036 max_ofdm->sfd_timeout);
1037 pos += scnprintf(buf + pos, bufsz - pos,
1038 fmt_table, "fina_timeout:",
1039 le32_to_cpu(ofdm->fina_timeout),
1040 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1041 max_ofdm->fina_timeout);
1042 pos += scnprintf(buf + pos, bufsz - pos,
1043 fmt_table, "unresponded_rts:",
1044 le32_to_cpu(ofdm->unresponded_rts),
1045 accum_ofdm->unresponded_rts,
1046 delta_ofdm->unresponded_rts,
1047 max_ofdm->unresponded_rts);
1048 pos += scnprintf(buf + pos, bufsz - pos,
1049 fmt_table, "rxe_frame_lmt_ovrun:",
1050 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1051 accum_ofdm->rxe_frame_limit_overrun,
1052 delta_ofdm->rxe_frame_limit_overrun,
1053 max_ofdm->rxe_frame_limit_overrun);
1054 pos += scnprintf(buf + pos, bufsz - pos,
1055 fmt_table, "sent_ack_cnt:",
1056 le32_to_cpu(ofdm->sent_ack_cnt),
1057 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1058 max_ofdm->sent_ack_cnt);
1059 pos += scnprintf(buf + pos, bufsz - pos,
1060 fmt_table, "sent_cts_cnt:",
1061 le32_to_cpu(ofdm->sent_cts_cnt),
1062 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1063 max_ofdm->sent_cts_cnt);
1064 pos += scnprintf(buf + pos, bufsz - pos,
1065 fmt_table, "sent_ba_rsp_cnt:",
1066 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1067 accum_ofdm->sent_ba_rsp_cnt,
1068 delta_ofdm->sent_ba_rsp_cnt,
1069 max_ofdm->sent_ba_rsp_cnt);
1070 pos += scnprintf(buf + pos, bufsz - pos,
1071 fmt_table, "dsp_self_kill:",
1072 le32_to_cpu(ofdm->dsp_self_kill),
1073 accum_ofdm->dsp_self_kill,
1074 delta_ofdm->dsp_self_kill,
1075 max_ofdm->dsp_self_kill);
1076 pos += scnprintf(buf + pos, bufsz - pos,
1077 fmt_table, "mh_format_err:",
1078 le32_to_cpu(ofdm->mh_format_err),
1079 accum_ofdm->mh_format_err,
1080 delta_ofdm->mh_format_err,
1081 max_ofdm->mh_format_err);
1082 pos += scnprintf(buf + pos, bufsz - pos,
1083 fmt_table, "re_acq_main_rssi_sum:",
1084 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1085 accum_ofdm->re_acq_main_rssi_sum,
1086 delta_ofdm->re_acq_main_rssi_sum,
1087 max_ofdm->re_acq_main_rssi_sum);
1088
1089 pos += scnprintf(buf + pos, bufsz - pos,
1090 fmt_header, "Statistics_Rx - CCK:");
1091 pos += scnprintf(buf + pos, bufsz - pos,
1092 fmt_table, "ina_cnt:",
1093 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1094 delta_cck->ina_cnt, max_cck->ina_cnt);
1095 pos += scnprintf(buf + pos, bufsz - pos,
1096 fmt_table, "fina_cnt:",
1097 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1098 delta_cck->fina_cnt, max_cck->fina_cnt);
1099 pos += scnprintf(buf + pos, bufsz - pos,
1100 fmt_table, "plcp_err:",
1101 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1102 delta_cck->plcp_err, max_cck->plcp_err);
1103 pos += scnprintf(buf + pos, bufsz - pos,
1104 fmt_table, "crc32_err:",
1105 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1106 delta_cck->crc32_err, max_cck->crc32_err);
1107 pos += scnprintf(buf + pos, bufsz - pos,
1108 fmt_table, "overrun_err:",
1109 le32_to_cpu(cck->overrun_err),
1110 accum_cck->overrun_err, delta_cck->overrun_err,
1111 max_cck->overrun_err);
1112 pos += scnprintf(buf + pos, bufsz - pos,
1113 fmt_table, "early_overrun_err:",
1114 le32_to_cpu(cck->early_overrun_err),
1115 accum_cck->early_overrun_err,
1116 delta_cck->early_overrun_err,
1117 max_cck->early_overrun_err);
1118 pos += scnprintf(buf + pos, bufsz - pos,
1119 fmt_table, "crc32_good:",
1120 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1121 delta_cck->crc32_good, max_cck->crc32_good);
1122 pos += scnprintf(buf + pos, bufsz - pos,
1123 fmt_table, "false_alarm_cnt:",
1124 le32_to_cpu(cck->false_alarm_cnt),
1125 accum_cck->false_alarm_cnt,
1126 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1127 pos += scnprintf(buf + pos, bufsz - pos,
1128 fmt_table, "fina_sync_err_cnt:",
1129 le32_to_cpu(cck->fina_sync_err_cnt),
1130 accum_cck->fina_sync_err_cnt,
1131 delta_cck->fina_sync_err_cnt,
1132 max_cck->fina_sync_err_cnt);
1133 pos += scnprintf(buf + pos, bufsz - pos,
1134 fmt_table, "sfd_timeout:",
1135 le32_to_cpu(cck->sfd_timeout),
1136 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1137 max_cck->sfd_timeout);
1138 pos += scnprintf(buf + pos, bufsz - pos,
1139 fmt_table, "fina_timeout:",
1140 le32_to_cpu(cck->fina_timeout),
1141 accum_cck->fina_timeout, delta_cck->fina_timeout,
1142 max_cck->fina_timeout);
1143 pos += scnprintf(buf + pos, bufsz - pos,
1144 fmt_table, "unresponded_rts:",
1145 le32_to_cpu(cck->unresponded_rts),
1146 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1147 max_cck->unresponded_rts);
1148 pos += scnprintf(buf + pos, bufsz - pos,
1149 fmt_table, "rxe_frame_lmt_ovrun:",
1150 le32_to_cpu(cck->rxe_frame_limit_overrun),
1151 accum_cck->rxe_frame_limit_overrun,
1152 delta_cck->rxe_frame_limit_overrun,
1153 max_cck->rxe_frame_limit_overrun);
1154 pos += scnprintf(buf + pos, bufsz - pos,
1155 fmt_table, "sent_ack_cnt:",
1156 le32_to_cpu(cck->sent_ack_cnt),
1157 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1158 max_cck->sent_ack_cnt);
1159 pos += scnprintf(buf + pos, bufsz - pos,
1160 fmt_table, "sent_cts_cnt:",
1161 le32_to_cpu(cck->sent_cts_cnt),
1162 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1163 max_cck->sent_cts_cnt);
1164 pos += scnprintf(buf + pos, bufsz - pos,
1165 fmt_table, "sent_ba_rsp_cnt:",
1166 le32_to_cpu(cck->sent_ba_rsp_cnt),
1167 accum_cck->sent_ba_rsp_cnt,
1168 delta_cck->sent_ba_rsp_cnt,
1169 max_cck->sent_ba_rsp_cnt);
1170 pos += scnprintf(buf + pos, bufsz - pos,
1171 fmt_table, "dsp_self_kill:",
1172 le32_to_cpu(cck->dsp_self_kill),
1173 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1174 max_cck->dsp_self_kill);
1175 pos += scnprintf(buf + pos, bufsz - pos,
1176 fmt_table, "mh_format_err:",
1177 le32_to_cpu(cck->mh_format_err),
1178 accum_cck->mh_format_err, delta_cck->mh_format_err,
1179 max_cck->mh_format_err);
1180 pos += scnprintf(buf + pos, bufsz - pos,
1181 fmt_table, "re_acq_main_rssi_sum:",
1182 le32_to_cpu(cck->re_acq_main_rssi_sum),
1183 accum_cck->re_acq_main_rssi_sum,
1184 delta_cck->re_acq_main_rssi_sum,
1185 max_cck->re_acq_main_rssi_sum);
1186
1187 pos += scnprintf(buf + pos, bufsz - pos,
1188 fmt_header, "Statistics_Rx - GENERAL:");
1189 pos += scnprintf(buf + pos, bufsz - pos,
1190 fmt_table, "bogus_cts:",
1191 le32_to_cpu(general->bogus_cts),
1192 accum_general->bogus_cts, delta_general->bogus_cts,
1193 max_general->bogus_cts);
1194 pos += scnprintf(buf + pos, bufsz - pos,
1195 fmt_table, "bogus_ack:",
1196 le32_to_cpu(general->bogus_ack),
1197 accum_general->bogus_ack, delta_general->bogus_ack,
1198 max_general->bogus_ack);
1199 pos += scnprintf(buf + pos, bufsz - pos,
1200 fmt_table, "non_bssid_frames:",
1201 le32_to_cpu(general->non_bssid_frames),
1202 accum_general->non_bssid_frames,
1203 delta_general->non_bssid_frames,
1204 max_general->non_bssid_frames);
1205 pos += scnprintf(buf + pos, bufsz - pos,
1206 fmt_table, "filtered_frames:",
1207 le32_to_cpu(general->filtered_frames),
1208 accum_general->filtered_frames,
1209 delta_general->filtered_frames,
1210 max_general->filtered_frames);
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 fmt_table, "non_channel_beacons:",
1213 le32_to_cpu(general->non_channel_beacons),
1214 accum_general->non_channel_beacons,
1215 delta_general->non_channel_beacons,
1216 max_general->non_channel_beacons);
1217 pos += scnprintf(buf + pos, bufsz - pos,
1218 fmt_table, "channel_beacons:",
1219 le32_to_cpu(general->channel_beacons),
1220 accum_general->channel_beacons,
1221 delta_general->channel_beacons,
1222 max_general->channel_beacons);
1223 pos += scnprintf(buf + pos, bufsz - pos,
1224 fmt_table, "num_missed_bcon:",
1225 le32_to_cpu(general->num_missed_bcon),
1226 accum_general->num_missed_bcon,
1227 delta_general->num_missed_bcon,
1228 max_general->num_missed_bcon);
1229 pos += scnprintf(buf + pos, bufsz - pos,
1230 fmt_table, "adc_rx_saturation_time:",
1231 le32_to_cpu(general->adc_rx_saturation_time),
1232 accum_general->adc_rx_saturation_time,
1233 delta_general->adc_rx_saturation_time,
1234 max_general->adc_rx_saturation_time);
1235 pos += scnprintf(buf + pos, bufsz - pos,
1236 fmt_table, "ina_detect_search_tm:",
1237 le32_to_cpu(general->ina_detection_search_time),
1238 accum_general->ina_detection_search_time,
1239 delta_general->ina_detection_search_time,
1240 max_general->ina_detection_search_time);
1241 pos += scnprintf(buf + pos, bufsz - pos,
1242 fmt_table, "beacon_silence_rssi_a:",
1243 le32_to_cpu(general->beacon_silence_rssi_a),
1244 accum_general->beacon_silence_rssi_a,
1245 delta_general->beacon_silence_rssi_a,
1246 max_general->beacon_silence_rssi_a);
1247 pos += scnprintf(buf + pos, bufsz - pos,
1248 fmt_table, "beacon_silence_rssi_b:",
1249 le32_to_cpu(general->beacon_silence_rssi_b),
1250 accum_general->beacon_silence_rssi_b,
1251 delta_general->beacon_silence_rssi_b,
1252 max_general->beacon_silence_rssi_b);
1253 pos += scnprintf(buf + pos, bufsz - pos,
1254 fmt_table, "beacon_silence_rssi_c:",
1255 le32_to_cpu(general->beacon_silence_rssi_c),
1256 accum_general->beacon_silence_rssi_c,
1257 delta_general->beacon_silence_rssi_c,
1258 max_general->beacon_silence_rssi_c);
1259 pos += scnprintf(buf + pos, bufsz - pos,
1260 fmt_table, "interference_data_flag:",
1261 le32_to_cpu(general->interference_data_flag),
1262 accum_general->interference_data_flag,
1263 delta_general->interference_data_flag,
1264 max_general->interference_data_flag);
1265 pos += scnprintf(buf + pos, bufsz - pos,
1266 fmt_table, "channel_load:",
1267 le32_to_cpu(general->channel_load),
1268 accum_general->channel_load,
1269 delta_general->channel_load,
1270 max_general->channel_load);
1271 pos += scnprintf(buf + pos, bufsz - pos,
1272 fmt_table, "dsp_false_alarms:",
1273 le32_to_cpu(general->dsp_false_alarms),
1274 accum_general->dsp_false_alarms,
1275 delta_general->dsp_false_alarms,
1276 max_general->dsp_false_alarms);
1277 pos += scnprintf(buf + pos, bufsz - pos,
1278 fmt_table, "beacon_rssi_a:",
1279 le32_to_cpu(general->beacon_rssi_a),
1280 accum_general->beacon_rssi_a,
1281 delta_general->beacon_rssi_a,
1282 max_general->beacon_rssi_a);
1283 pos += scnprintf(buf + pos, bufsz - pos,
1284 fmt_table, "beacon_rssi_b:",
1285 le32_to_cpu(general->beacon_rssi_b),
1286 accum_general->beacon_rssi_b,
1287 delta_general->beacon_rssi_b,
1288 max_general->beacon_rssi_b);
1289 pos += scnprintf(buf + pos, bufsz - pos,
1290 fmt_table, "beacon_rssi_c:",
1291 le32_to_cpu(general->beacon_rssi_c),
1292 accum_general->beacon_rssi_c,
1293 delta_general->beacon_rssi_c,
1294 max_general->beacon_rssi_c);
1295 pos += scnprintf(buf + pos, bufsz - pos,
1296 fmt_table, "beacon_energy_a:",
1297 le32_to_cpu(general->beacon_energy_a),
1298 accum_general->beacon_energy_a,
1299 delta_general->beacon_energy_a,
1300 max_general->beacon_energy_a);
1301 pos += scnprintf(buf + pos, bufsz - pos,
1302 fmt_table, "beacon_energy_b:",
1303 le32_to_cpu(general->beacon_energy_b),
1304 accum_general->beacon_energy_b,
1305 delta_general->beacon_energy_b,
1306 max_general->beacon_energy_b);
1307 pos += scnprintf(buf + pos, bufsz - pos,
1308 fmt_table, "beacon_energy_c:",
1309 le32_to_cpu(general->beacon_energy_c),
1310 accum_general->beacon_energy_c,
1311 delta_general->beacon_energy_c,
1312 max_general->beacon_energy_c);
1313
1314 pos += scnprintf(buf + pos, bufsz - pos,
1315 fmt_header, "Statistics_Rx - OFDM_HT:");
1316 pos += scnprintf(buf + pos, bufsz - pos,
1317 fmt_table, "plcp_err:",
1318 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1319 delta_ht->plcp_err, max_ht->plcp_err);
1320 pos += scnprintf(buf + pos, bufsz - pos,
1321 fmt_table, "overrun_err:",
1322 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1323 delta_ht->overrun_err, max_ht->overrun_err);
1324 pos += scnprintf(buf + pos, bufsz - pos,
1325 fmt_table, "early_overrun_err:",
1326 le32_to_cpu(ht->early_overrun_err),
1327 accum_ht->early_overrun_err,
1328 delta_ht->early_overrun_err,
1329 max_ht->early_overrun_err);
1330 pos += scnprintf(buf + pos, bufsz - pos,
1331 fmt_table, "crc32_good:",
1332 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1333 delta_ht->crc32_good, max_ht->crc32_good);
1334 pos += scnprintf(buf + pos, bufsz - pos,
1335 fmt_table, "crc32_err:",
1336 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1337 delta_ht->crc32_err, max_ht->crc32_err);
1338 pos += scnprintf(buf + pos, bufsz - pos,
1339 fmt_table, "mh_format_err:",
1340 le32_to_cpu(ht->mh_format_err),
1341 accum_ht->mh_format_err,
1342 delta_ht->mh_format_err, max_ht->mh_format_err);
1343 pos += scnprintf(buf + pos, bufsz - pos,
1344 fmt_table, "agg_crc32_good:",
1345 le32_to_cpu(ht->agg_crc32_good),
1346 accum_ht->agg_crc32_good,
1347 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1348 pos += scnprintf(buf + pos, bufsz - pos,
1349 fmt_table, "agg_mpdu_cnt:",
1350 le32_to_cpu(ht->agg_mpdu_cnt),
1351 accum_ht->agg_mpdu_cnt,
1352 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1353 pos += scnprintf(buf + pos, bufsz - pos,
1354 fmt_table, "agg_cnt:",
1355 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1356 delta_ht->agg_cnt, max_ht->agg_cnt);
1357 pos += scnprintf(buf + pos, bufsz - pos,
1358 fmt_table, "unsupport_mcs:",
1359 le32_to_cpu(ht->unsupport_mcs),
1360 accum_ht->unsupport_mcs,
1361 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1362
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001363 spin_unlock_bh(&priv->statistics.lock);
1364
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001365 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1366 kfree(buf);
1367 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001368}
1369
1370static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1371 char __user *user_buf,
1372 size_t count, loff_t *ppos)
1373{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001374 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001375 int pos = 0;
1376 char *buf;
1377 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1378 ssize_t ret;
1379 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1380
Don Fry83626402012-03-07 09:52:37 -08001381 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001382 return -EAGAIN;
1383
1384 buf = kzalloc(bufsz, GFP_KERNEL);
1385 if (!buf) {
1386 IWL_ERR(priv, "Can not allocate Buffer\n");
1387 return -ENOMEM;
1388 }
1389
1390 /* the statistic information display here is based on
1391 * the last statistics notification from uCode
1392 * might not reflect the current uCode activity
1393 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001394 spin_lock_bh(&priv->statistics.lock);
1395
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001396 tx = &priv->statistics.tx;
1397 accum_tx = &priv->accum_stats.tx;
1398 delta_tx = &priv->delta_stats.tx;
1399 max_tx = &priv->max_delta_stats.tx;
1400
1401 pos += iwl_statistics_flag(priv, buf, bufsz);
1402 pos += scnprintf(buf + pos, bufsz - pos,
1403 fmt_header, "Statistics_Tx:");
1404 pos += scnprintf(buf + pos, bufsz - pos,
1405 fmt_table, "preamble:",
1406 le32_to_cpu(tx->preamble_cnt),
1407 accum_tx->preamble_cnt,
1408 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1409 pos += scnprintf(buf + pos, bufsz - pos,
1410 fmt_table, "rx_detected_cnt:",
1411 le32_to_cpu(tx->rx_detected_cnt),
1412 accum_tx->rx_detected_cnt,
1413 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1414 pos += scnprintf(buf + pos, bufsz - pos,
1415 fmt_table, "bt_prio_defer_cnt:",
1416 le32_to_cpu(tx->bt_prio_defer_cnt),
1417 accum_tx->bt_prio_defer_cnt,
1418 delta_tx->bt_prio_defer_cnt,
1419 max_tx->bt_prio_defer_cnt);
1420 pos += scnprintf(buf + pos, bufsz - pos,
1421 fmt_table, "bt_prio_kill_cnt:",
1422 le32_to_cpu(tx->bt_prio_kill_cnt),
1423 accum_tx->bt_prio_kill_cnt,
1424 delta_tx->bt_prio_kill_cnt,
1425 max_tx->bt_prio_kill_cnt);
1426 pos += scnprintf(buf + pos, bufsz - pos,
1427 fmt_table, "few_bytes_cnt:",
1428 le32_to_cpu(tx->few_bytes_cnt),
1429 accum_tx->few_bytes_cnt,
1430 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1431 pos += scnprintf(buf + pos, bufsz - pos,
1432 fmt_table, "cts_timeout:",
1433 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1434 delta_tx->cts_timeout, max_tx->cts_timeout);
1435 pos += scnprintf(buf + pos, bufsz - pos,
1436 fmt_table, "ack_timeout:",
1437 le32_to_cpu(tx->ack_timeout),
1438 accum_tx->ack_timeout,
1439 delta_tx->ack_timeout, max_tx->ack_timeout);
1440 pos += scnprintf(buf + pos, bufsz - pos,
1441 fmt_table, "expected_ack_cnt:",
1442 le32_to_cpu(tx->expected_ack_cnt),
1443 accum_tx->expected_ack_cnt,
1444 delta_tx->expected_ack_cnt,
1445 max_tx->expected_ack_cnt);
1446 pos += scnprintf(buf + pos, bufsz - pos,
1447 fmt_table, "actual_ack_cnt:",
1448 le32_to_cpu(tx->actual_ack_cnt),
1449 accum_tx->actual_ack_cnt,
1450 delta_tx->actual_ack_cnt,
1451 max_tx->actual_ack_cnt);
1452 pos += scnprintf(buf + pos, bufsz - pos,
1453 fmt_table, "dump_msdu_cnt:",
1454 le32_to_cpu(tx->dump_msdu_cnt),
1455 accum_tx->dump_msdu_cnt,
1456 delta_tx->dump_msdu_cnt,
1457 max_tx->dump_msdu_cnt);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 fmt_table, "abort_nxt_frame_mismatch:",
1460 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1461 accum_tx->burst_abort_next_frame_mismatch_cnt,
1462 delta_tx->burst_abort_next_frame_mismatch_cnt,
1463 max_tx->burst_abort_next_frame_mismatch_cnt);
1464 pos += scnprintf(buf + pos, bufsz - pos,
1465 fmt_table, "abort_missing_nxt_frame:",
1466 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1467 accum_tx->burst_abort_missing_next_frame_cnt,
1468 delta_tx->burst_abort_missing_next_frame_cnt,
1469 max_tx->burst_abort_missing_next_frame_cnt);
1470 pos += scnprintf(buf + pos, bufsz - pos,
1471 fmt_table, "cts_timeout_collision:",
1472 le32_to_cpu(tx->cts_timeout_collision),
1473 accum_tx->cts_timeout_collision,
1474 delta_tx->cts_timeout_collision,
1475 max_tx->cts_timeout_collision);
1476 pos += scnprintf(buf + pos, bufsz - pos,
1477 fmt_table, "ack_ba_timeout_collision:",
1478 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1479 accum_tx->ack_or_ba_timeout_collision,
1480 delta_tx->ack_or_ba_timeout_collision,
1481 max_tx->ack_or_ba_timeout_collision);
1482 pos += scnprintf(buf + pos, bufsz - pos,
1483 fmt_table, "agg ba_timeout:",
1484 le32_to_cpu(tx->agg.ba_timeout),
1485 accum_tx->agg.ba_timeout,
1486 delta_tx->agg.ba_timeout,
1487 max_tx->agg.ba_timeout);
1488 pos += scnprintf(buf + pos, bufsz - pos,
1489 fmt_table, "agg ba_resched_frames:",
1490 le32_to_cpu(tx->agg.ba_reschedule_frames),
1491 accum_tx->agg.ba_reschedule_frames,
1492 delta_tx->agg.ba_reschedule_frames,
1493 max_tx->agg.ba_reschedule_frames);
1494 pos += scnprintf(buf + pos, bufsz - pos,
1495 fmt_table, "agg scd_query_agg_frame:",
1496 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1497 accum_tx->agg.scd_query_agg_frame_cnt,
1498 delta_tx->agg.scd_query_agg_frame_cnt,
1499 max_tx->agg.scd_query_agg_frame_cnt);
1500 pos += scnprintf(buf + pos, bufsz - pos,
1501 fmt_table, "agg scd_query_no_agg:",
1502 le32_to_cpu(tx->agg.scd_query_no_agg),
1503 accum_tx->agg.scd_query_no_agg,
1504 delta_tx->agg.scd_query_no_agg,
1505 max_tx->agg.scd_query_no_agg);
1506 pos += scnprintf(buf + pos, bufsz - pos,
1507 fmt_table, "agg scd_query_agg:",
1508 le32_to_cpu(tx->agg.scd_query_agg),
1509 accum_tx->agg.scd_query_agg,
1510 delta_tx->agg.scd_query_agg,
1511 max_tx->agg.scd_query_agg);
1512 pos += scnprintf(buf + pos, bufsz - pos,
1513 fmt_table, "agg scd_query_mismatch:",
1514 le32_to_cpu(tx->agg.scd_query_mismatch),
1515 accum_tx->agg.scd_query_mismatch,
1516 delta_tx->agg.scd_query_mismatch,
1517 max_tx->agg.scd_query_mismatch);
1518 pos += scnprintf(buf + pos, bufsz - pos,
1519 fmt_table, "agg frame_not_ready:",
1520 le32_to_cpu(tx->agg.frame_not_ready),
1521 accum_tx->agg.frame_not_ready,
1522 delta_tx->agg.frame_not_ready,
1523 max_tx->agg.frame_not_ready);
1524 pos += scnprintf(buf + pos, bufsz - pos,
1525 fmt_table, "agg underrun:",
1526 le32_to_cpu(tx->agg.underrun),
1527 accum_tx->agg.underrun,
1528 delta_tx->agg.underrun, max_tx->agg.underrun);
1529 pos += scnprintf(buf + pos, bufsz - pos,
1530 fmt_table, "agg bt_prio_kill:",
1531 le32_to_cpu(tx->agg.bt_prio_kill),
1532 accum_tx->agg.bt_prio_kill,
1533 delta_tx->agg.bt_prio_kill,
1534 max_tx->agg.bt_prio_kill);
1535 pos += scnprintf(buf + pos, bufsz - pos,
1536 fmt_table, "agg rx_ba_rsp_cnt:",
1537 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1538 accum_tx->agg.rx_ba_rsp_cnt,
1539 delta_tx->agg.rx_ba_rsp_cnt,
1540 max_tx->agg.rx_ba_rsp_cnt);
1541
1542 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1543 pos += scnprintf(buf + pos, bufsz - pos,
1544 "tx power: (1/2 dB step)\n");
Johannes Berg7e79a392012-03-05 11:24:32 -08001545 if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1546 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001547 pos += scnprintf(buf + pos, bufsz - pos,
1548 fmt_hex, "antenna A:",
1549 tx->tx_power.ant_a);
Johannes Berg7e79a392012-03-05 11:24:32 -08001550 if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1551 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001552 pos += scnprintf(buf + pos, bufsz - pos,
1553 fmt_hex, "antenna B:",
1554 tx->tx_power.ant_b);
Johannes Berg7e79a392012-03-05 11:24:32 -08001555 if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1556 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001557 pos += scnprintf(buf + pos, bufsz - pos,
1558 fmt_hex, "antenna C:",
1559 tx->tx_power.ant_c);
1560 }
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001561
1562 spin_unlock_bh(&priv->statistics.lock);
1563
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001564 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1565 kfree(buf);
1566 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001567}
1568
1569static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1570 char __user *user_buf,
1571 size_t count, loff_t *ppos)
1572{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001573 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001574 int pos = 0;
1575 char *buf;
1576 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1577 ssize_t ret;
1578 struct statistics_general_common *general, *accum_general;
1579 struct statistics_general_common *delta_general, *max_general;
1580 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1581 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1582
Don Fry83626402012-03-07 09:52:37 -08001583 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001584 return -EAGAIN;
1585
1586 buf = kzalloc(bufsz, GFP_KERNEL);
1587 if (!buf) {
1588 IWL_ERR(priv, "Can not allocate Buffer\n");
1589 return -ENOMEM;
1590 }
1591
1592 /* the statistic information display here is based on
1593 * the last statistics notification from uCode
1594 * might not reflect the current uCode activity
1595 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001596
1597 spin_lock_bh(&priv->statistics.lock);
1598
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001599 general = &priv->statistics.common;
1600 dbg = &priv->statistics.common.dbg;
1601 div = &priv->statistics.common.div;
1602 accum_general = &priv->accum_stats.common;
1603 accum_dbg = &priv->accum_stats.common.dbg;
1604 accum_div = &priv->accum_stats.common.div;
1605 delta_general = &priv->delta_stats.common;
1606 max_general = &priv->max_delta_stats.common;
1607 delta_dbg = &priv->delta_stats.common.dbg;
1608 max_dbg = &priv->max_delta_stats.common.dbg;
1609 delta_div = &priv->delta_stats.common.div;
1610 max_div = &priv->max_delta_stats.common.div;
1611
1612 pos += iwl_statistics_flag(priv, buf, bufsz);
1613 pos += scnprintf(buf + pos, bufsz - pos,
1614 fmt_header, "Statistics_General:");
1615 pos += scnprintf(buf + pos, bufsz - pos,
1616 fmt_value, "temperature:",
1617 le32_to_cpu(general->temperature));
1618 pos += scnprintf(buf + pos, bufsz - pos,
1619 fmt_value, "temperature_m:",
1620 le32_to_cpu(general->temperature_m));
1621 pos += scnprintf(buf + pos, bufsz - pos,
1622 fmt_value, "ttl_timestamp:",
1623 le32_to_cpu(general->ttl_timestamp));
1624 pos += scnprintf(buf + pos, bufsz - pos,
1625 fmt_table, "burst_check:",
1626 le32_to_cpu(dbg->burst_check),
1627 accum_dbg->burst_check,
1628 delta_dbg->burst_check, max_dbg->burst_check);
1629 pos += scnprintf(buf + pos, bufsz - pos,
1630 fmt_table, "burst_count:",
1631 le32_to_cpu(dbg->burst_count),
1632 accum_dbg->burst_count,
1633 delta_dbg->burst_count, max_dbg->burst_count);
1634 pos += scnprintf(buf + pos, bufsz - pos,
1635 fmt_table, "wait_for_silence_timeout_count:",
1636 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1637 accum_dbg->wait_for_silence_timeout_cnt,
1638 delta_dbg->wait_for_silence_timeout_cnt,
1639 max_dbg->wait_for_silence_timeout_cnt);
1640 pos += scnprintf(buf + pos, bufsz - pos,
1641 fmt_table, "sleep_time:",
1642 le32_to_cpu(general->sleep_time),
1643 accum_general->sleep_time,
1644 delta_general->sleep_time, max_general->sleep_time);
1645 pos += scnprintf(buf + pos, bufsz - pos,
1646 fmt_table, "slots_out:",
1647 le32_to_cpu(general->slots_out),
1648 accum_general->slots_out,
1649 delta_general->slots_out, max_general->slots_out);
1650 pos += scnprintf(buf + pos, bufsz - pos,
1651 fmt_table, "slots_idle:",
1652 le32_to_cpu(general->slots_idle),
1653 accum_general->slots_idle,
1654 delta_general->slots_idle, max_general->slots_idle);
1655 pos += scnprintf(buf + pos, bufsz - pos,
1656 fmt_table, "tx_on_a:",
1657 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1658 delta_div->tx_on_a, max_div->tx_on_a);
1659 pos += scnprintf(buf + pos, bufsz - pos,
1660 fmt_table, "tx_on_b:",
1661 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1662 delta_div->tx_on_b, max_div->tx_on_b);
1663 pos += scnprintf(buf + pos, bufsz - pos,
1664 fmt_table, "exec_time:",
1665 le32_to_cpu(div->exec_time), accum_div->exec_time,
1666 delta_div->exec_time, max_div->exec_time);
1667 pos += scnprintf(buf + pos, bufsz - pos,
1668 fmt_table, "probe_time:",
1669 le32_to_cpu(div->probe_time), accum_div->probe_time,
1670 delta_div->probe_time, max_div->probe_time);
1671 pos += scnprintf(buf + pos, bufsz - pos,
1672 fmt_table, "rx_enable_counter:",
1673 le32_to_cpu(general->rx_enable_counter),
1674 accum_general->rx_enable_counter,
1675 delta_general->rx_enable_counter,
1676 max_general->rx_enable_counter);
1677 pos += scnprintf(buf + pos, bufsz - pos,
1678 fmt_table, "num_of_sos_states:",
1679 le32_to_cpu(general->num_of_sos_states),
1680 accum_general->num_of_sos_states,
1681 delta_general->num_of_sos_states,
1682 max_general->num_of_sos_states);
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001683
1684 spin_unlock_bh(&priv->statistics.lock);
1685
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001686 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1687 kfree(buf);
1688 return ret;
1689}
1690
1691static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1692 char __user *user_buf,
1693 size_t count, loff_t *ppos)
1694{
1695 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1696 int pos = 0;
1697 char *buf;
1698 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1699 ssize_t ret;
1700 struct statistics_bt_activity *bt, *accum_bt;
1701
Don Fry83626402012-03-07 09:52:37 -08001702 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001703 return -EAGAIN;
1704
1705 if (!priv->bt_enable_flag)
1706 return -EINVAL;
1707
1708 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001709 mutex_lock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001710 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001711 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001712
1713 if (ret) {
1714 IWL_ERR(priv,
1715 "Error sending statistics request: %zd\n", ret);
1716 return -EAGAIN;
1717 }
1718 buf = kzalloc(bufsz, GFP_KERNEL);
1719 if (!buf) {
1720 IWL_ERR(priv, "Can not allocate Buffer\n");
1721 return -ENOMEM;
1722 }
1723
1724 /*
1725 * the statistic information display here is based on
1726 * the last statistics notification from uCode
1727 * might not reflect the current uCode activity
1728 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001729
1730 spin_lock_bh(&priv->statistics.lock);
1731
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001732 bt = &priv->statistics.bt_activity;
1733 accum_bt = &priv->accum_stats.bt_activity;
1734
1735 pos += iwl_statistics_flag(priv, buf, bufsz);
1736 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1737 pos += scnprintf(buf + pos, bufsz - pos,
1738 "\t\t\tcurrent\t\t\taccumulative\n");
1739 pos += scnprintf(buf + pos, bufsz - pos,
1740 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1741 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1742 accum_bt->hi_priority_tx_req_cnt);
1743 pos += scnprintf(buf + pos, bufsz - pos,
1744 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1745 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1746 accum_bt->hi_priority_tx_denied_cnt);
1747 pos += scnprintf(buf + pos, bufsz - pos,
1748 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1749 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1750 accum_bt->lo_priority_tx_req_cnt);
1751 pos += scnprintf(buf + pos, bufsz - pos,
1752 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1753 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1754 accum_bt->lo_priority_tx_denied_cnt);
1755 pos += scnprintf(buf + pos, bufsz - pos,
1756 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1757 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1758 accum_bt->hi_priority_rx_req_cnt);
1759 pos += scnprintf(buf + pos, bufsz - pos,
1760 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1761 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1762 accum_bt->hi_priority_rx_denied_cnt);
1763 pos += scnprintf(buf + pos, bufsz - pos,
1764 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1765 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1766 accum_bt->lo_priority_rx_req_cnt);
1767 pos += scnprintf(buf + pos, bufsz - pos,
1768 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1769 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1770 accum_bt->lo_priority_rx_denied_cnt);
1771
1772 pos += scnprintf(buf + pos, bufsz - pos,
1773 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1774 le32_to_cpu(priv->statistics.num_bt_kills),
1775 priv->statistics.accum_num_bt_kills);
1776
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001777 spin_unlock_bh(&priv->statistics.lock);
1778
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001779 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1780 kfree(buf);
1781 return ret;
1782}
1783
1784static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1785 char __user *user_buf,
1786 size_t count, loff_t *ppos)
1787{
1788 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1789 int pos = 0;
1790 char *buf;
1791 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1792 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1793 ssize_t ret;
1794
Don Fry83626402012-03-07 09:52:37 -08001795 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001796 return -EAGAIN;
1797
1798 buf = kzalloc(bufsz, GFP_KERNEL);
1799 if (!buf) {
1800 IWL_ERR(priv, "Can not allocate Buffer\n");
1801 return -ENOMEM;
1802 }
1803
1804 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1805 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1806 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001807 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001808 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1809 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001810 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001811 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1812 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001813 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001814 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1815 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001816 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001817 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1818 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001819 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001820 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1821 iwl_get_tx_fail_reason(
1822 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001823 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001824 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1825 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001826 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001827 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1828 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001829 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001830 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1831 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001832 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001833 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1834 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001835 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001836 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1837 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001838 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001839 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1840 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001841 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001842 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1843 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001844 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001845 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1846 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001847 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001848 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1849 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001851 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1852 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001853 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001854 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1855 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001856 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001857 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1858 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001859 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001860 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1861 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001862 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001863 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1864 iwl_get_tx_fail_reason(
1865 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001866 priv->reply_tx_stats.insuff_cf_poll);
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_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001869 priv->reply_tx_stats.fail_hw_drop);
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_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001873 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001874 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001875 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001876
1877 pos += scnprintf(buf + pos, bufsz - pos,
1878 "\nStatistics_Agg_TX_Error:\n");
1879
1880 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1881 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001882 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001883 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1884 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001885 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001886 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1887 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001888 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001889 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1890 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001891 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001892 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1893 iwl_get_agg_tx_fail_reason(
1894 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001895 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001896 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1897 iwl_get_agg_tx_fail_reason(
1898 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001899 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001900 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1901 iwl_get_agg_tx_fail_reason(
1902 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001903 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001904 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1905 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001906 priv->reply_agg_tx_stats.scd_query);
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_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001910 priv->reply_agg_tx_stats.bad_crc32);
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_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001913 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001914 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1915 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001916 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001917 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1918 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001919 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001920 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001921 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001922
1923 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1924 kfree(buf);
1925 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001926}
1927
Wey-Yi Guy52259352009-08-07 15:41:43 -07001928static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1929 char __user *user_buf,
1930 size_t count, loff_t *ppos) {
1931
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001932 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001933 int pos = 0;
1934 int cnt = 0;
1935 char *buf;
1936 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1937 ssize_t ret;
1938 struct iwl_sensitivity_data *data;
1939
1940 data = &priv->sensitivity_data;
1941 buf = kzalloc(bufsz, GFP_KERNEL);
1942 if (!buf) {
1943 IWL_ERR(priv, "Can not allocate Buffer\n");
1944 return -ENOMEM;
1945 }
1946
1947 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1948 data->auto_corr_ofdm);
1949 pos += scnprintf(buf + pos, bufsz - pos,
1950 "auto_corr_ofdm_mrc:\t\t %u\n",
1951 data->auto_corr_ofdm_mrc);
1952 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1953 data->auto_corr_ofdm_x1);
1954 pos += scnprintf(buf + pos, bufsz - pos,
1955 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1956 data->auto_corr_ofdm_mrc_x1);
1957 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1958 data->auto_corr_cck);
1959 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1960 data->auto_corr_cck_mrc);
1961 pos += scnprintf(buf + pos, bufsz - pos,
1962 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1963 data->last_bad_plcp_cnt_ofdm);
1964 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1965 data->last_fa_cnt_ofdm);
1966 pos += scnprintf(buf + pos, bufsz - pos,
1967 "last_bad_plcp_cnt_cck:\t\t %u\n",
1968 data->last_bad_plcp_cnt_cck);
1969 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1970 data->last_fa_cnt_cck);
1971 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1972 data->nrg_curr_state);
1973 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1974 data->nrg_prev_state);
1975 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1976 for (cnt = 0; cnt < 10; cnt++) {
1977 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1978 data->nrg_value[cnt]);
1979 }
1980 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1981 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1982 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1983 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1984 data->nrg_silence_rssi[cnt]);
1985 }
1986 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1987 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1988 data->nrg_silence_ref);
1989 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1990 data->nrg_energy_idx);
1991 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1992 data->nrg_silence_idx);
1993 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1994 data->nrg_th_cck);
1995 pos += scnprintf(buf + pos, bufsz - pos,
1996 "nrg_auto_corr_silence_diff:\t %u\n",
1997 data->nrg_auto_corr_silence_diff);
1998 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1999 data->num_in_cck_no_fa);
2000 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
2001 data->nrg_th_ofdm);
2002
2003 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2004 kfree(buf);
2005 return ret;
2006}
2007
2008
2009static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2010 char __user *user_buf,
2011 size_t count, loff_t *ppos) {
2012
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002013 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002014 int pos = 0;
2015 int cnt = 0;
2016 char *buf;
2017 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2018 ssize_t ret;
2019 struct iwl_chain_noise_data *data;
2020
2021 data = &priv->chain_noise_data;
2022 buf = kzalloc(bufsz, GFP_KERNEL);
2023 if (!buf) {
2024 IWL_ERR(priv, "Can not allocate Buffer\n");
2025 return -ENOMEM;
2026 }
2027
2028 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2029 data->active_chains);
2030 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2031 data->chain_noise_a);
2032 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2033 data->chain_noise_b);
2034 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2035 data->chain_noise_c);
2036 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2037 data->chain_signal_a);
2038 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2039 data->chain_signal_b);
2040 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2041 data->chain_signal_c);
2042 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2043 data->beacon_count);
2044
2045 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2046 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2047 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2048 data->disconn_array[cnt]);
2049 }
2050 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2051 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2052 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2053 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2054 data->delta_gain_code[cnt]);
2055 }
2056 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2057 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2058 data->radio_write);
2059 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2060 data->state);
2061
2062 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2063 kfree(buf);
2064 return ret;
2065}
2066
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002067static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2068 char __user *user_buf,
2069 size_t count, loff_t *ppos)
2070{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002071 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002072 char buf[60];
2073 int pos = 0;
2074 const size_t bufsz = sizeof(buf);
2075 u32 pwrsave_status;
2076
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002077 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002078 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2079
2080 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2081 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2082 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2083 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2084 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2085 "error");
2086
2087 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2088}
2089
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002090static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002091 const char __user *user_buf,
2092 size_t count, loff_t *ppos)
2093{
2094 struct iwl_priv *priv = file->private_data;
2095 char buf[8];
2096 int buf_size;
2097 int clear;
2098
2099 memset(buf, 0, sizeof(buf));
2100 buf_size = min(count, sizeof(buf) - 1);
2101 if (copy_from_user(buf, user_buf, buf_size))
2102 return -EFAULT;
2103 if (sscanf(buf, "%d", &clear) != 1)
2104 return -EFAULT;
2105
2106 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08002107 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002108 iwl_send_statistics_request(priv, CMD_SYNC, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08002109 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002110
2111 return count;
2112}
2113
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002114static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2115 char __user *user_buf,
2116 size_t count, loff_t *ppos) {
2117
Joe Perches57674302010-07-12 13:50:06 -07002118 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002119 int pos = 0;
2120 char buf[128];
2121 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002122
2123 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2124 priv->event_log.ucode_trace ? "On" : "Off");
2125 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2126 priv->event_log.non_wraps_count);
2127 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2128 priv->event_log.wraps_once_count);
2129 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2130 priv->event_log.wraps_more_count);
2131
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002132 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002133}
2134
2135static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2136 const char __user *user_buf,
2137 size_t count, loff_t *ppos)
2138{
2139 struct iwl_priv *priv = file->private_data;
2140 char buf[8];
2141 int buf_size;
2142 int trace;
2143
2144 memset(buf, 0, sizeof(buf));
2145 buf_size = min(count, sizeof(buf) - 1);
2146 if (copy_from_user(buf, user_buf, buf_size))
2147 return -EFAULT;
2148 if (sscanf(buf, "%d", &trace) != 1)
2149 return -EFAULT;
2150
2151 if (trace) {
2152 priv->event_log.ucode_trace = true;
Don Fry83626402012-03-07 09:52:37 -08002153 if (iwl_is_alive(priv)) {
Johannes Berg98d4bf02012-01-13 11:56:11 +01002154 /* start collecting data now */
2155 mod_timer(&priv->ucode_trace, jiffies);
2156 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002157 } else {
2158 priv->event_log.ucode_trace = false;
2159 del_timer_sync(&priv->ucode_trace);
2160 }
2161
2162 return count;
2163}
2164
Johannes Berg60987202010-02-18 00:36:07 -08002165static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2166 char __user *user_buf,
2167 size_t count, loff_t *ppos) {
2168
Joe Perches57674302010-07-12 13:50:06 -07002169 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002170 int len = 0;
2171 char buf[20];
2172
Johannes Berg246ed352010-08-23 10:46:32 +02002173 len = sprintf(buf, "0x%04X\n",
2174 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002175 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2176}
2177
2178static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2179 char __user *user_buf,
2180 size_t count, loff_t *ppos) {
2181
Joe Perches57674302010-07-12 13:50:06 -07002182 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002183 int len = 0;
2184 char buf[20];
2185
2186 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002187 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002188 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2189}
2190
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002191static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2192 char __user *user_buf,
2193 size_t count, loff_t *ppos) {
2194
2195 struct iwl_priv *priv = file->private_data;
2196 int pos = 0;
2197 char buf[12];
2198 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002199
2200 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2201 priv->missed_beacon_threshold);
2202
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002203 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002204}
2205
2206static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2207 const char __user *user_buf,
2208 size_t count, loff_t *ppos)
2209{
2210 struct iwl_priv *priv = file->private_data;
2211 char buf[8];
2212 int buf_size;
2213 int missed;
2214
2215 memset(buf, 0, sizeof(buf));
2216 buf_size = min(count, sizeof(buf) - 1);
2217 if (copy_from_user(buf, user_buf, buf_size))
2218 return -EFAULT;
2219 if (sscanf(buf, "%d", &missed) != 1)
2220 return -EINVAL;
2221
2222 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2223 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2224 priv->missed_beacon_threshold =
2225 IWL_MISSED_BEACON_THRESHOLD_DEF;
2226 else
2227 priv->missed_beacon_threshold = missed;
2228
2229 return count;
2230}
2231
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002232static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2233 char __user *user_buf,
2234 size_t count, loff_t *ppos) {
2235
Joe Perches57674302010-07-12 13:50:06 -07002236 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002237 int pos = 0;
2238 char buf[12];
2239 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002240
2241 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002242 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002243
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002244 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002245}
2246
2247static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2248 const char __user *user_buf,
2249 size_t count, loff_t *ppos) {
2250
2251 struct iwl_priv *priv = file->private_data;
2252 char buf[8];
2253 int buf_size;
2254 int plcp;
2255
2256 memset(buf, 0, sizeof(buf));
2257 buf_size = min(count, sizeof(buf) - 1);
2258 if (copy_from_user(buf, user_buf, buf_size))
2259 return -EFAULT;
2260 if (sscanf(buf, "%d", &plcp) != 1)
2261 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002262 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002263 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002264 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002265 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002266 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002267 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002268 return count;
2269}
2270
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002271static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2272 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002273 size_t count, loff_t *ppos)
2274{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002275 struct iwl_priv *priv = file->private_data;
2276 int i, pos = 0;
2277 char buf[300];
2278 const size_t bufsz = sizeof(buf);
2279 struct iwl_force_reset *force_reset;
2280
2281 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2282 force_reset = &priv->force_reset[i];
2283 pos += scnprintf(buf + pos, bufsz - pos,
2284 "Force reset method %d\n", i);
2285 pos += scnprintf(buf + pos, bufsz - pos,
2286 "\tnumber of reset request: %d\n",
2287 force_reset->reset_request_count);
2288 pos += scnprintf(buf + pos, bufsz - pos,
2289 "\tnumber of reset request success: %d\n",
2290 force_reset->reset_success_count);
2291 pos += scnprintf(buf + pos, bufsz - pos,
2292 "\tnumber of reset request reject: %d\n",
2293 force_reset->reset_reject_count);
2294 pos += scnprintf(buf + pos, bufsz - pos,
2295 "\treset duration: %lu\n",
2296 force_reset->reset_duration);
2297 }
2298 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2299}
2300
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002301static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2302 const char __user *user_buf,
2303 size_t count, loff_t *ppos) {
2304
2305 struct iwl_priv *priv = file->private_data;
2306 char buf[8];
2307 int buf_size;
2308 int reset, ret;
2309
2310 memset(buf, 0, sizeof(buf));
2311 buf_size = min(count, sizeof(buf) - 1);
2312 if (copy_from_user(buf, user_buf, buf_size))
2313 return -EFAULT;
2314 if (sscanf(buf, "%d", &reset) != 1)
2315 return -EINVAL;
2316 switch (reset) {
2317 case IWL_RF_RESET:
2318 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002319 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002320 break;
2321 default:
2322 return -EINVAL;
2323 }
2324 return ret ? ret : count;
2325}
2326
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002327static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2328 const char __user *user_buf,
2329 size_t count, loff_t *ppos) {
2330
2331 struct iwl_priv *priv = file->private_data;
2332 char buf[8];
2333 int buf_size;
2334 int flush;
2335
2336 memset(buf, 0, sizeof(buf));
2337 buf_size = min(count, sizeof(buf) - 1);
2338 if (copy_from_user(buf, user_buf, buf_size))
2339 return -EFAULT;
2340 if (sscanf(buf, "%d", &flush) != 1)
2341 return -EINVAL;
2342
Don Fry83626402012-03-07 09:52:37 -08002343 if (iwl_is_rfkill(priv))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002344 return -EFAULT;
2345
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002346 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002347
2348 return count;
2349}
2350
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002351static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002352 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002353 size_t count, loff_t *ppos)
2354{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002355 struct iwl_priv *priv = file->private_data;
2356 char buf[8];
2357 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002358 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002359
2360 memset(buf, 0, sizeof(buf));
2361 buf_size = min(count, sizeof(buf) - 1);
2362 if (copy_from_user(buf, user_buf, buf_size))
2363 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002364 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002365 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002366 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2367 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002368
Johannes Berge7a09432012-03-06 13:30:54 -08002369 hw_params(priv).wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002370 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002371 return count;
2372}
2373
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002374static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2375 char __user *user_buf,
2376 size_t count, loff_t *ppos) {
2377
2378 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2379 int pos = 0;
2380 char buf[200];
2381 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002382
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002383 if (!priv->bt_enable_flag) {
2384 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002385 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002386 }
2387 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2388 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002389 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2390 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2391 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2392 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002393 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002394 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002395 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2396 priv->bt_ch_announce, priv->kill_ack_mask,
2397 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002398
2399 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2400 switch (priv->bt_traffic_load) {
2401 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2402 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2403 break;
2404 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2405 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2406 break;
2407 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2408 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2409 break;
2410 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2411 default:
2412 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2413 break;
2414 }
2415
Johannes Berg08960de2011-04-05 09:41:53 -07002416 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002417}
2418
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002419static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2420 char __user *user_buf,
2421 size_t count, loff_t *ppos)
2422{
2423 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2424
2425 int pos = 0;
2426 char buf[40];
2427 const size_t bufsz = sizeof(buf);
2428
Don Fry38622412011-12-16 07:07:36 -08002429 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002430 pos += scnprintf(buf + pos, bufsz - pos,
2431 "use %s for aggregation\n",
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002432 (hw_params(priv).use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002433 "rts/cts" : "cts-to-self");
2434 else
2435 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2436
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002437 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2438}
2439
2440static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2441 const char __user *user_buf,
2442 size_t count, loff_t *ppos) {
2443
2444 struct iwl_priv *priv = file->private_data;
2445 char buf[8];
2446 int buf_size;
2447 int rts;
2448
Don Fry38622412011-12-16 07:07:36 -08002449 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002450 return -EINVAL;
2451
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002452 memset(buf, 0, sizeof(buf));
2453 buf_size = min(count, sizeof(buf) - 1);
2454 if (copy_from_user(buf, user_buf, buf_size))
2455 return -EFAULT;
2456 if (sscanf(buf, "%d", &rts) != 1)
2457 return -EINVAL;
2458 if (rts)
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002459 hw_params(priv).use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002460 else
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002461 hw_params(priv).use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002462 return count;
2463}
2464
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002465static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2466 const char __user *user_buf,
2467 size_t count, loff_t *ppos)
2468{
2469 struct iwl_priv *priv = file->private_data;
2470 char buf[8];
2471 int buf_size;
2472
2473 memset(buf, 0, sizeof(buf));
2474 buf_size = min(count, sizeof(buf) - 1);
2475 if (copy_from_user(buf, user_buf, buf_size))
2476 return -EFAULT;
2477
2478 iwl_cmd_echo_test(priv);
2479 return count;
2480}
2481
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002482DEBUGFS_READ_FILE_OPS(rx_statistics);
2483DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002484DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002485DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2486DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2487DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002488DEBUGFS_READ_FILE_OPS(sensitivity);
2489DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002490DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002491DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2492DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002493DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002494DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002495DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002496DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002497DEBUGFS_READ_FILE_OPS(rxon_flags);
2498DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002499DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002500DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002501DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002502DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002503DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002504DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002505DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002506
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002507/*
2508 * Create the debugfs files and directories
2509 *
2510 */
2511int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2512{
Zhu Yi95b1a822008-05-29 16:34:50 +08002513 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002514 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002515
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002516 dir_drv = debugfs_create_dir(name, phyd);
2517 if (!dir_drv)
2518 return -ENOMEM;
2519
2520 priv->debugfs_dir = dir_drv;
2521
2522 dir_data = debugfs_create_dir("data", dir_drv);
2523 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002524 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002525 dir_rf = debugfs_create_dir("rf", dir_drv);
2526 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002527 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002528 dir_debug = debugfs_create_dir("debug", dir_drv);
2529 if (!dir_debug)
2530 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002531
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002532 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2533 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002534 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002535 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2536 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2537 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002538 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002539 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002540 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2541 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002542 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2543 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002544 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002545
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002546 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2547 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002548 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002549 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2550 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2551 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002552 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002553 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002554 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002555 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2556 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2557 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002558 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002559 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002560 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2561 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002562 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002563 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002564 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002565 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2566 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002567 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002568 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002569 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002570 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002571
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002572 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2573 &priv->disable_sens_cal);
2574 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2575 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002576
2577 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2578 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002579 return 0;
2580
2581err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002582 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002583 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002584 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002585}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002586
2587/**
2588 * Remove the debugfs files and directories
2589 *
2590 */
2591void iwl_dbgfs_unregister(struct iwl_priv *priv)
2592{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002593 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002594 return;
2595
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002596 debugfs_remove_recursive(priv->debugfs_dir);
2597 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002598}