blob: 2bbaebd99ad42a4a8c057838eead058088686dc0 [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08005 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
Tomas Winkler712b6cf2008-03-12 16:58:52 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h>
35#include <net/mac80211.h>
36
37
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070039#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070040#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070041#include "iwl-io.h"
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -070042#include "iwl-agn.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070043
44/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080045#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
46 if (!debugfs_create_file(#name, mode, parent, priv, \
47 &iwl_dbgfs_##name##_ops)) \
48 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070049} while (0)
50
Johannes Berg4c84a8f2010-01-22 14:22:54 -080051#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
52 struct dentry *__tmp; \
53 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
54 parent, ptr); \
55 if (IS_ERR(__tmp) || !__tmp) \
56 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070057} while (0)
58
Johannes Berg4c84a8f2010-01-22 14:22:54 -080059#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
60 struct dentry *__tmp; \
61 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
62 parent, ptr); \
63 if (IS_ERR(__tmp) || !__tmp) \
64 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080065} while (0)
66
Johannes Bergca934b62011-09-15 11:46:48 -070067#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
68 struct dentry *__tmp; \
69 __tmp = debugfs_create_u32(#name, mode, \
70 parent, ptr); \
71 if (IS_ERR(__tmp) || !__tmp) \
72 goto err; \
73} while (0)
74
Tomas Winkler712b6cf2008-03-12 16:58:52 -070075/* file operation */
76#define DEBUGFS_READ_FUNC(name) \
77static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
78 char __user *user_buf, \
79 size_t count, loff_t *ppos);
80
81#define DEBUGFS_WRITE_FUNC(name) \
82static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
83 const char __user *user_buf, \
84 size_t count, loff_t *ppos);
85
86
Tomas Winkler712b6cf2008-03-12 16:58:52 -070087#define DEBUGFS_READ_FILE_OPS(name) \
88 DEBUGFS_READ_FUNC(name); \
89static const struct file_operations iwl_dbgfs_##name##_ops = { \
90 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070091 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020092 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070093};
94
Ester Kummer189a2b52008-05-15 13:54:18 +080095#define DEBUGFS_WRITE_FILE_OPS(name) \
96 DEBUGFS_WRITE_FUNC(name); \
97static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
Stephen Boyd234e3402012-04-05 14:25:11 -070099 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200100 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800101};
102
103
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700104#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
105 DEBUGFS_READ_FUNC(name); \
106 DEBUGFS_WRITE_FUNC(name); \
107static const struct file_operations iwl_dbgfs_##name##_ops = { \
108 .write = iwl_dbgfs_##name##_write, \
109 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -0700110 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200111 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700112};
113
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700114static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
115 char __user *user_buf,
116 size_t count, loff_t *ppos) {
117
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700118 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700119 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700120 int pos = 0;
121
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700122 int cnt;
123 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800124 const size_t bufsz = 100 +
125 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700126 buf = kzalloc(bufsz, GFP_KERNEL);
127 if (!buf)
128 return -ENOMEM;
129 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
130 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
131 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800132 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700133 get_mgmt_string(cnt),
134 priv->tx_stats.mgmt[cnt]);
135 }
136 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
137 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
138 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800139 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700140 get_ctrl_string(cnt),
141 priv->tx_stats.ctrl[cnt]);
142 }
143 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
144 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
145 priv->tx_stats.data_cnt);
146 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
147 priv->tx_stats.data_bytes);
148 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
149 kfree(buf);
150 return ret;
151}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700152
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800153static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700154 const char __user *user_buf,
155 size_t count, loff_t *ppos)
156{
157 struct iwl_priv *priv = file->private_data;
158 u32 clear_flag;
159 char buf[8];
160 int buf_size;
161
162 memset(buf, 0, sizeof(buf));
163 buf_size = min(count, sizeof(buf) - 1);
164 if (copy_from_user(buf, user_buf, buf_size))
165 return -EFAULT;
166 if (sscanf(buf, "%x", &clear_flag) != 1)
167 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800168 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700169
170 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700171}
172
173static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
174 char __user *user_buf,
175 size_t count, loff_t *ppos) {
176
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700177 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700178 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700179 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700180 int cnt;
181 ssize_t ret;
182 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800183 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700184 buf = kzalloc(bufsz, GFP_KERNEL);
185 if (!buf)
186 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700187
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700188 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
189 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
190 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800191 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700192 get_mgmt_string(cnt),
193 priv->rx_stats.mgmt[cnt]);
194 }
195 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
196 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
197 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800198 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700199 get_ctrl_string(cnt),
200 priv->rx_stats.ctrl[cnt]);
201 }
202 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
203 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
204 priv->rx_stats.data_cnt);
205 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
206 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700207
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700208 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
209 kfree(buf);
210 return ret;
211}
212
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700213static ssize_t iwl_dbgfs_sram_read(struct file *file,
214 char __user *user_buf,
215 size_t count, loff_t *ppos)
216{
Jay Sternberg24834d22011-01-11 15:41:00 -0800217 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800218 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700219 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800220 int i = 0;
221 bool device_format = false;
222 int offset = 0;
223 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700224 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800225 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700226 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800227 const struct fw_img *img;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800228 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700229
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800230 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800231 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
232 priv->dbgfs_sram_offset = 0x800000;
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800233 if (!priv->ucode_loaded) {
234 IWL_ERR(priv, "No uCode has been loadded.\n");
235 return -EINVAL;
236 }
David Spinadel6dfa8d02012-03-10 13:00:14 -0800237 img = &priv->fw->img[priv->shrd->ucode_type];
238 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800239 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800240 len = priv->dbgfs_sram_len;
241
242 if (len == -4) {
243 device_format = true;
244 len = 4;
245 }
246
247 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800248 buf = kmalloc(bufsz, GFP_KERNEL);
249 if (!buf)
250 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800251
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800252 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800253 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800254 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800255 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800256
257 /* adjust sram address since reads are only on even u32 boundaries */
258 offset = priv->dbgfs_sram_offset & 0x3;
259 sram = priv->dbgfs_sram_offset & ~0x3;
260
261 /* read the first u32 from sram */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200262 val = iwl_read_targ_mem(trans(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800263
264 for (; len; len--) {
265 /* put the address at the start of every line */
266 if (i == 0)
267 pos += scnprintf(buf + pos, bufsz - pos,
268 "%08X: ", sram + offset);
269
270 if (device_format)
271 pos += scnprintf(buf + pos, bufsz - pos,
272 "%02x", (val >> (8 * (3 - offset))) & 0xff);
273 else
274 pos += scnprintf(buf + pos, bufsz - pos,
275 "%02x ", (val >> (8 * offset)) & 0xff);
276
277 /* if all bytes processed, read the next u32 from sram */
278 if (++offset == 4) {
279 sram += 4;
280 offset = 0;
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200281 val = iwl_read_targ_mem(trans(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700282 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800283
284 /* put in extra spaces and split lines for human readability */
285 if (++i == 16) {
286 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800287 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800288 } else if (!(i & 7)) {
289 pos += scnprintf(buf + pos, bufsz - pos, " ");
290 } else if (!(i & 3)) {
291 pos += scnprintf(buf + pos, bufsz - pos, " ");
292 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700293 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800294 if (i)
295 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700296
297 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800298 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700299 return ret;
300}
301
302static ssize_t iwl_dbgfs_sram_write(struct file *file,
303 const char __user *user_buf,
304 size_t count, loff_t *ppos)
305{
306 struct iwl_priv *priv = file->private_data;
307 char buf[64];
308 int buf_size;
309 u32 offset, len;
310
311 memset(buf, 0, sizeof(buf));
312 buf_size = min(count, sizeof(buf) - 1);
313 if (copy_from_user(buf, user_buf, buf_size))
314 return -EFAULT;
315
316 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800317 priv->dbgfs_sram_offset = offset;
318 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800319 } else if (sscanf(buf, "%x", &offset) == 1) {
320 priv->dbgfs_sram_offset = offset;
321 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700322 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800323 priv->dbgfs_sram_offset = 0;
324 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700325 }
326
327 return count;
328}
329
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700330static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
331 char __user *user_buf,
332 size_t count, loff_t *ppos)
333{
334 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800335 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700336
337 if (!priv->wowlan_sram)
338 return -ENODATA;
339
340 return simple_read_from_buffer(user_buf, count, ppos,
341 priv->wowlan_sram,
David Spinadel6dfa8d02012-03-10 13:00:14 -0800342 img->sec[IWL_UCODE_SECTION_DATA].len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700343}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700344static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
345 size_t count, loff_t *ppos)
346{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700347 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800348 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700349 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700350 char *buf;
351 int i, j, pos = 0;
352 ssize_t ret;
353 /* Add 30 for initial string */
354 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700355
356 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300357 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700358 return -ENOMEM;
359
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700360 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700361 priv->num_stations);
362
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700363 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700364 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700365 if (!station->used)
366 continue;
367 pos += scnprintf(buf + pos, bufsz - pos,
368 "station %d - addr: %pM, flags: %#x\n",
369 i, station->sta.sta.addr,
370 station->sta.station_flags_msk);
371 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200372 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700373
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700374 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200375 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700376 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200377 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700378 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700379 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700380
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700381 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700382 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700383 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700384 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700385 }
Johannes Bergda735112010-05-03 01:25:24 -0700386
387 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700388 }
389
390 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
391 kfree(buf);
392 return ret;
393}
394
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700395static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800396 char __user *user_buf,
397 size_t count,
398 loff_t *ppos)
399{
400 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700401 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800402 int pos = 0, ofs = 0, buf_size = 0;
403 const u8 *ptr;
404 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700405 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800406 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800407 buf_size = 4 * eeprom_len + 256;
408
409 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700410 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800411 return -ENODATA;
412 }
413
Don Fryab36eab2011-11-30 15:37:32 -0800414 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200415 if (!ptr) {
416 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
417 return -ENOMEM;
418 }
419
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800420 /* 4 characters for byte 0xYY */
421 buf = kzalloc(buf_size, GFP_KERNEL);
422 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800423 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800424 return -ENOMEM;
425 }
Don Fryab36eab2011-11-30 15:37:32 -0800426 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700427 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
428 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800429 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700430 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800431 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
432 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
433 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
434 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700435 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800436 if (buf_size - pos > 0)
437 buf[pos++] = '\n';
438 }
439
440 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
441 kfree(buf);
442 return ret;
443}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700444
Winkler, Tomasd366df52008-12-02 12:14:01 -0800445static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
446 size_t count, loff_t *ppos)
447{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700448 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800449 struct ieee80211_channel *channels = NULL;
450 const struct ieee80211_supported_band *supp_band = NULL;
451 int pos = 0, i, bufsz = PAGE_SIZE;
452 char *buf;
453 ssize_t ret;
454
Don Fry83626402012-03-07 09:52:37 -0800455 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800456 return -EAGAIN;
457
458 buf = kzalloc(bufsz, GFP_KERNEL);
459 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800460 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800461 return -ENOMEM;
462 }
463
464 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700465 if (supp_band) {
466 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800467
Winkler, Tomasd366df52008-12-02 12:14:01 -0800468 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700469 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
470 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800471
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700472 for (i = 0; i < supp_band->n_channels; i++)
473 pos += scnprintf(buf + pos, bufsz - pos,
474 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700475 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700476 channels[i].max_power,
477 channels[i].flags & IEEE80211_CHAN_RADAR ?
478 " (IEEE 802.11h required)" : "",
479 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
480 || (channels[i].flags &
481 IEEE80211_CHAN_RADAR)) ? "" :
482 ", IBSS",
483 channels[i].flags &
484 IEEE80211_CHAN_PASSIVE_SCAN ?
485 "passive only" : "active/passive");
486 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800487 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700488 if (supp_band) {
489 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800490
Winkler, Tomasd366df52008-12-02 12:14:01 -0800491 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700492 "Displaying %d channels in 5.2GHz band (802.11a)\n",
493 supp_band->n_channels);
494
495 for (i = 0; i < supp_band->n_channels; i++)
496 pos += scnprintf(buf + pos, bufsz - pos,
497 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700498 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700499 channels[i].max_power,
500 channels[i].flags & IEEE80211_CHAN_RADAR ?
501 " (IEEE 802.11h required)" : "",
502 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
503 || (channels[i].flags &
504 IEEE80211_CHAN_RADAR)) ? "" :
505 ", IBSS",
506 channels[i].flags &
507 IEEE80211_CHAN_PASSIVE_SCAN ?
508 "passive only" : "active/passive");
509 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800510 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
511 kfree(buf);
512 return ret;
513}
514
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700515static ssize_t iwl_dbgfs_status_read(struct file *file,
516 char __user *user_buf,
517 size_t count, loff_t *ppos) {
518
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700519 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700520 char buf[512];
521 int pos = 0;
522 const size_t bufsz = sizeof(buf);
523
524 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700525 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700526 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800527 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700528 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800529 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700530 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800531 test_bit(STATUS_ALIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700532 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800533 test_bit(STATUS_READY, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700534 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800535 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700536 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800537 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700538 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800539 test_bit(STATUS_STATISTICS, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700540 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800541 test_bit(STATUS_SCANNING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700542 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800543 test_bit(STATUS_SCAN_ABORTING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700544 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800545 test_bit(STATUS_SCAN_HW, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700546 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700547 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700548 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700549 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700550 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
551}
552
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700553static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700554 char __user *user_buf,
555 size_t count, loff_t *ppos) {
556
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700557 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700558
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700559 int pos = 0;
560 int cnt = 0;
561 char *buf;
562 int bufsz = 24 * 64; /* 24 items * 64 char per item */
563 ssize_t ret;
564
565 buf = kzalloc(bufsz, GFP_KERNEL);
566 if (!buf) {
567 IWL_ERR(priv, "Can not allocate Buffer\n");
568 return -ENOMEM;
569 }
570
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700571 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700572 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700573 pos += scnprintf(buf + pos, bufsz - pos,
574 "\tRx handler[%36s]:\t\t %u\n",
575 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700576 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700577 }
578
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700579 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
580 kfree(buf);
581 return ret;
582}
583
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700584static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700585 const char __user *user_buf,
586 size_t count, loff_t *ppos)
587{
588 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700589
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700590 char buf[8];
591 int buf_size;
592 u32 reset_flag;
593
594 memset(buf, 0, sizeof(buf));
595 buf_size = min(count, sizeof(buf) - 1);
596 if (copy_from_user(buf, user_buf, buf_size))
597 return -EFAULT;
598 if (sscanf(buf, "%x", &reset_flag) != 1)
599 return -EFAULT;
600 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700601 memset(&priv->rx_handlers_stats[0], 0,
602 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700603
604 return count;
605}
606
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700607static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
608 size_t count, loff_t *ppos)
609{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700610 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200611 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700612 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200613 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700614 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700615
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200616 for_each_context(priv, ctx) {
617 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
618 ctx->ctxid);
619 for (i = 0; i < AC_NUM; i++) {
620 pos += scnprintf(buf + pos, bufsz - pos,
621 "\tcw_min\tcw_max\taifsn\ttxop\n");
622 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700623 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200624 ctx->qos_data.def_qos_parm.ac[i].cw_min,
625 ctx->qos_data.def_qos_parm.ac[i].cw_max,
626 ctx->qos_data.def_qos_parm.ac[i].aifsn,
627 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
628 }
629 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700630 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800631 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700632}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700633
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700634static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
635 char __user *user_buf,
636 size_t count, loff_t *ppos)
637{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700638 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700639 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700640 struct iwl_tt_restriction *restriction;
641 char buf[100];
642 int pos = 0;
643 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700644
645 pos += scnprintf(buf + pos, bufsz - pos,
646 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700647 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700648 pos += scnprintf(buf + pos, bufsz - pos,
649 "Thermal Throttling State: %d\n",
650 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700651 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700652 restriction = tt->restriction + tt->state;
653 pos += scnprintf(buf + pos, bufsz - pos,
654 "Tx mode: %d\n",
655 restriction->tx_stream);
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "Rx mode: %d\n",
658 restriction->rx_stream);
659 pos += scnprintf(buf + pos, bufsz - pos,
660 "HT mode: %d\n",
661 restriction->is_ht);
662 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800663 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700664}
665
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700666static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
667 const char __user *user_buf,
668 size_t count, loff_t *ppos)
669{
670 struct iwl_priv *priv = file->private_data;
671 char buf[8];
672 int buf_size;
673 int ht40;
674
675 memset(buf, 0, sizeof(buf));
676 buf_size = min(count, sizeof(buf) - 1);
677 if (copy_from_user(buf, user_buf, buf_size))
678 return -EFAULT;
679 if (sscanf(buf, "%d", &ht40) != 1)
680 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200681 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700682 priv->disable_ht40 = ht40 ? true : false;
683 else {
684 IWL_ERR(priv, "Sta associated with AP - "
685 "Change to 40MHz channel support is not allowed\n");
686 return -EINVAL;
687 }
688
689 return count;
690}
691
692static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
693 char __user *user_buf,
694 size_t count, loff_t *ppos)
695{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700696 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700697 char buf[100];
698 int pos = 0;
699 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700700
701 pos += scnprintf(buf + pos, bufsz - pos,
702 "11n 40MHz Mode: %s\n",
703 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800704 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700705}
706
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700707static ssize_t iwl_dbgfs_temperature_read(struct file *file,
708 char __user *user_buf,
709 size_t count, loff_t *ppos)
710{
711 struct iwl_priv *priv = file->private_data;
712 char buf[8];
713 int pos = 0;
714 const size_t bufsz = sizeof(buf);
715
716 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
717 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
718}
719
720
Johannes Berge312c242009-08-07 15:41:51 -0700721static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
722 const char __user *user_buf,
723 size_t count, loff_t *ppos)
724{
725 struct iwl_priv *priv = file->private_data;
726 char buf[8];
727 int buf_size;
728 int value;
729
730 memset(buf, 0, sizeof(buf));
731 buf_size = min(count, sizeof(buf) - 1);
732 if (copy_from_user(buf, user_buf, buf_size))
733 return -EFAULT;
734
735 if (sscanf(buf, "%d", &value) != 1)
736 return -EINVAL;
737
738 /*
739 * Our users expect 0 to be "CAM", but 0 isn't actually
740 * valid here. However, let's not confuse them and present
741 * IWL_POWER_INDEX_1 as "1", not "0".
742 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700743 if (value == 0)
744 return -EINVAL;
745 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700746 value -= 1;
747
748 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
749 return -EINVAL;
750
Don Fry83626402012-03-07 09:52:37 -0800751 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700752 return -EAGAIN;
753
Johannes Berge312c242009-08-07 15:41:51 -0700754 priv->power_data.debug_sleep_level_override = value;
755
Johannes Bergb1eea292012-03-06 13:30:42 -0800756 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700757 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800758 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700759
760 return count;
761}
762
763static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
764 char __user *user_buf,
765 size_t count, loff_t *ppos)
766{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700767 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700768 char buf[10];
769 int pos, value;
770 const size_t bufsz = sizeof(buf);
771
772 /* see the write function */
773 value = priv->power_data.debug_sleep_level_override;
774 if (value >= 0)
775 value += 1;
776
777 pos = scnprintf(buf, bufsz, "%d\n", value);
778 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
779}
780
781static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
782 char __user *user_buf,
783 size_t count, loff_t *ppos)
784{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700785 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700786 char buf[200];
787 int pos = 0, i;
788 const size_t bufsz = sizeof(buf);
789 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
790
791 pos += scnprintf(buf + pos, bufsz - pos,
792 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
793 pos += scnprintf(buf + pos, bufsz - pos,
794 "RX/TX timeout: %d/%d usec\n",
795 le32_to_cpu(cmd->rx_data_timeout),
796 le32_to_cpu(cmd->tx_data_timeout));
797 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
798 pos += scnprintf(buf + pos, bufsz - pos,
799 "sleep_interval[%d]: %d\n", i,
800 le32_to_cpu(cmd->sleep_interval[i]));
801
802 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
803}
804
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700805DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700806DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700807DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700808DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800809DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700810DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700811DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700812DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700813DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700814DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700815DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700816DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
817DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700818
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700819static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
820 char __user *user_buf,
821 size_t count, loff_t *ppos)
822{
823 struct iwl_priv *priv = file->private_data;
824 int pos = 0, ofs = 0;
825 int cnt = 0, entry;
826
827 char *buf;
828 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy1745e442012-03-09 11:13:40 -0800829 (cfg(priv)->base_params->num_of_queues * 32 * 8) + 400;
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700830 const u8 *ptr;
831 ssize_t ret;
832
833 buf = kzalloc(bufsz, GFP_KERNEL);
834 if (!buf) {
835 IWL_ERR(priv, "Can not allocate buffer\n");
836 return -ENOMEM;
837 }
Johannes Berga8bceb32012-03-05 11:24:30 -0800838 if (priv->tx_traffic && iwl_have_debug_level(IWL_DL_TX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700839 ptr = priv->tx_traffic;
840 pos += scnprintf(buf + pos, bufsz - pos,
841 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
842 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
843 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
844 entry++, ofs += 16) {
845 pos += scnprintf(buf + pos, bufsz - pos,
846 "0x%.4x ", ofs);
847 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
848 buf + pos, bufsz - pos, 0);
849 pos += strlen(buf + pos);
850 if (bufsz - pos > 0)
851 buf[pos++] = '\n';
852 }
853 }
854 }
855
Johannes Berga8bceb32012-03-05 11:24:30 -0800856 if (priv->rx_traffic && iwl_have_debug_level(IWL_DL_RX)) {
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700857 ptr = priv->rx_traffic;
858 pos += scnprintf(buf + pos, bufsz - pos,
859 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
860 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
861 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
862 entry++, ofs += 16) {
863 pos += scnprintf(buf + pos, bufsz - pos,
864 "0x%.4x ", ofs);
865 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
866 buf + pos, bufsz - pos, 0);
867 pos += strlen(buf + pos);
868 if (bufsz - pos > 0)
869 buf[pos++] = '\n';
870 }
871 }
872 }
873
874 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
875 kfree(buf);
876 return ret;
877}
878
879static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
880 const char __user *user_buf,
881 size_t count, loff_t *ppos)
882{
883 struct iwl_priv *priv = file->private_data;
884 char buf[8];
885 int buf_size;
886 int traffic_log;
887
888 memset(buf, 0, sizeof(buf));
889 buf_size = min(count, sizeof(buf) - 1);
890 if (copy_from_user(buf, user_buf, buf_size))
891 return -EFAULT;
892 if (sscanf(buf, "%d", &traffic_log) != 1)
893 return -EFAULT;
894 if (traffic_log == 0)
895 iwl_reset_traffic_log(priv);
896
897 return count;
898}
899
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700900static const char *fmt_value = " %-30s %10u\n";
901static const char *fmt_hex = " %-30s 0x%02X\n";
902static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
903static const char *fmt_header =
904 "%-32s current cumulative delta max\n";
905
906static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
907{
908 int p = 0;
909 u32 flag;
910
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800911 lockdep_assert_held(&priv->statistics.lock);
912
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700913 flag = le32_to_cpu(priv->statistics.flag);
914
915 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
916 if (flag & UCODE_STATISTICS_CLEAR_MSK)
917 p += scnprintf(buf + p, bufsz - p,
918 "\tStatistics have been cleared\n");
919 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
920 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
921 ? "2.4 GHz" : "5.2 GHz");
922 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
923 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
924 ? "enabled" : "disabled");
925
926 return p;
927}
928
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700929static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
930 char __user *user_buf,
931 size_t count, loff_t *ppos)
932{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700933 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700934 int pos = 0;
935 char *buf;
936 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
937 sizeof(struct statistics_rx_non_phy) * 40 +
938 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
939 ssize_t ret;
940 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
941 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
942 struct statistics_rx_non_phy *general, *accum_general;
943 struct statistics_rx_non_phy *delta_general, *max_general;
944 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
945
Don Fry83626402012-03-07 09:52:37 -0800946 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700947 return -EAGAIN;
948
949 buf = kzalloc(bufsz, GFP_KERNEL);
950 if (!buf) {
951 IWL_ERR(priv, "Can not allocate Buffer\n");
952 return -ENOMEM;
953 }
954
955 /*
956 * the statistic information display here is based on
957 * the last statistics notification from uCode
958 * might not reflect the current uCode activity
959 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800960 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700961 ofdm = &priv->statistics.rx_ofdm;
962 cck = &priv->statistics.rx_cck;
963 general = &priv->statistics.rx_non_phy;
964 ht = &priv->statistics.rx_ofdm_ht;
965 accum_ofdm = &priv->accum_stats.rx_ofdm;
966 accum_cck = &priv->accum_stats.rx_cck;
967 accum_general = &priv->accum_stats.rx_non_phy;
968 accum_ht = &priv->accum_stats.rx_ofdm_ht;
969 delta_ofdm = &priv->delta_stats.rx_ofdm;
970 delta_cck = &priv->delta_stats.rx_cck;
971 delta_general = &priv->delta_stats.rx_non_phy;
972 delta_ht = &priv->delta_stats.rx_ofdm_ht;
973 max_ofdm = &priv->max_delta_stats.rx_ofdm;
974 max_cck = &priv->max_delta_stats.rx_cck;
975 max_general = &priv->max_delta_stats.rx_non_phy;
976 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
977
978 pos += iwl_statistics_flag(priv, buf, bufsz);
979 pos += scnprintf(buf + pos, bufsz - pos,
980 fmt_header, "Statistics_Rx - OFDM:");
981 pos += scnprintf(buf + pos, bufsz - pos,
982 fmt_table, "ina_cnt:",
983 le32_to_cpu(ofdm->ina_cnt),
984 accum_ofdm->ina_cnt,
985 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
986 pos += scnprintf(buf + pos, bufsz - pos,
987 fmt_table, "fina_cnt:",
988 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
989 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
990 pos += scnprintf(buf + pos, bufsz - pos,
991 fmt_table, "plcp_err:",
992 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
993 delta_ofdm->plcp_err, max_ofdm->plcp_err);
994 pos += scnprintf(buf + pos, bufsz - pos,
995 fmt_table, "crc32_err:",
996 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
997 delta_ofdm->crc32_err, max_ofdm->crc32_err);
998 pos += scnprintf(buf + pos, bufsz - pos,
999 fmt_table, "overrun_err:",
1000 le32_to_cpu(ofdm->overrun_err),
1001 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1002 max_ofdm->overrun_err);
1003 pos += scnprintf(buf + pos, bufsz - pos,
1004 fmt_table, "early_overrun_err:",
1005 le32_to_cpu(ofdm->early_overrun_err),
1006 accum_ofdm->early_overrun_err,
1007 delta_ofdm->early_overrun_err,
1008 max_ofdm->early_overrun_err);
1009 pos += scnprintf(buf + pos, bufsz - pos,
1010 fmt_table, "crc32_good:",
1011 le32_to_cpu(ofdm->crc32_good),
1012 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1013 max_ofdm->crc32_good);
1014 pos += scnprintf(buf + pos, bufsz - pos,
1015 fmt_table, "false_alarm_cnt:",
1016 le32_to_cpu(ofdm->false_alarm_cnt),
1017 accum_ofdm->false_alarm_cnt,
1018 delta_ofdm->false_alarm_cnt,
1019 max_ofdm->false_alarm_cnt);
1020 pos += scnprintf(buf + pos, bufsz - pos,
1021 fmt_table, "fina_sync_err_cnt:",
1022 le32_to_cpu(ofdm->fina_sync_err_cnt),
1023 accum_ofdm->fina_sync_err_cnt,
1024 delta_ofdm->fina_sync_err_cnt,
1025 max_ofdm->fina_sync_err_cnt);
1026 pos += scnprintf(buf + pos, bufsz - pos,
1027 fmt_table, "sfd_timeout:",
1028 le32_to_cpu(ofdm->sfd_timeout),
1029 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1030 max_ofdm->sfd_timeout);
1031 pos += scnprintf(buf + pos, bufsz - pos,
1032 fmt_table, "fina_timeout:",
1033 le32_to_cpu(ofdm->fina_timeout),
1034 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1035 max_ofdm->fina_timeout);
1036 pos += scnprintf(buf + pos, bufsz - pos,
1037 fmt_table, "unresponded_rts:",
1038 le32_to_cpu(ofdm->unresponded_rts),
1039 accum_ofdm->unresponded_rts,
1040 delta_ofdm->unresponded_rts,
1041 max_ofdm->unresponded_rts);
1042 pos += scnprintf(buf + pos, bufsz - pos,
1043 fmt_table, "rxe_frame_lmt_ovrun:",
1044 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1045 accum_ofdm->rxe_frame_limit_overrun,
1046 delta_ofdm->rxe_frame_limit_overrun,
1047 max_ofdm->rxe_frame_limit_overrun);
1048 pos += scnprintf(buf + pos, bufsz - pos,
1049 fmt_table, "sent_ack_cnt:",
1050 le32_to_cpu(ofdm->sent_ack_cnt),
1051 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1052 max_ofdm->sent_ack_cnt);
1053 pos += scnprintf(buf + pos, bufsz - pos,
1054 fmt_table, "sent_cts_cnt:",
1055 le32_to_cpu(ofdm->sent_cts_cnt),
1056 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1057 max_ofdm->sent_cts_cnt);
1058 pos += scnprintf(buf + pos, bufsz - pos,
1059 fmt_table, "sent_ba_rsp_cnt:",
1060 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1061 accum_ofdm->sent_ba_rsp_cnt,
1062 delta_ofdm->sent_ba_rsp_cnt,
1063 max_ofdm->sent_ba_rsp_cnt);
1064 pos += scnprintf(buf + pos, bufsz - pos,
1065 fmt_table, "dsp_self_kill:",
1066 le32_to_cpu(ofdm->dsp_self_kill),
1067 accum_ofdm->dsp_self_kill,
1068 delta_ofdm->dsp_self_kill,
1069 max_ofdm->dsp_self_kill);
1070 pos += scnprintf(buf + pos, bufsz - pos,
1071 fmt_table, "mh_format_err:",
1072 le32_to_cpu(ofdm->mh_format_err),
1073 accum_ofdm->mh_format_err,
1074 delta_ofdm->mh_format_err,
1075 max_ofdm->mh_format_err);
1076 pos += scnprintf(buf + pos, bufsz - pos,
1077 fmt_table, "re_acq_main_rssi_sum:",
1078 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1079 accum_ofdm->re_acq_main_rssi_sum,
1080 delta_ofdm->re_acq_main_rssi_sum,
1081 max_ofdm->re_acq_main_rssi_sum);
1082
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 fmt_header, "Statistics_Rx - CCK:");
1085 pos += scnprintf(buf + pos, bufsz - pos,
1086 fmt_table, "ina_cnt:",
1087 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1088 delta_cck->ina_cnt, max_cck->ina_cnt);
1089 pos += scnprintf(buf + pos, bufsz - pos,
1090 fmt_table, "fina_cnt:",
1091 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1092 delta_cck->fina_cnt, max_cck->fina_cnt);
1093 pos += scnprintf(buf + pos, bufsz - pos,
1094 fmt_table, "plcp_err:",
1095 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1096 delta_cck->plcp_err, max_cck->plcp_err);
1097 pos += scnprintf(buf + pos, bufsz - pos,
1098 fmt_table, "crc32_err:",
1099 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1100 delta_cck->crc32_err, max_cck->crc32_err);
1101 pos += scnprintf(buf + pos, bufsz - pos,
1102 fmt_table, "overrun_err:",
1103 le32_to_cpu(cck->overrun_err),
1104 accum_cck->overrun_err, delta_cck->overrun_err,
1105 max_cck->overrun_err);
1106 pos += scnprintf(buf + pos, bufsz - pos,
1107 fmt_table, "early_overrun_err:",
1108 le32_to_cpu(cck->early_overrun_err),
1109 accum_cck->early_overrun_err,
1110 delta_cck->early_overrun_err,
1111 max_cck->early_overrun_err);
1112 pos += scnprintf(buf + pos, bufsz - pos,
1113 fmt_table, "crc32_good:",
1114 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1115 delta_cck->crc32_good, max_cck->crc32_good);
1116 pos += scnprintf(buf + pos, bufsz - pos,
1117 fmt_table, "false_alarm_cnt:",
1118 le32_to_cpu(cck->false_alarm_cnt),
1119 accum_cck->false_alarm_cnt,
1120 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1121 pos += scnprintf(buf + pos, bufsz - pos,
1122 fmt_table, "fina_sync_err_cnt:",
1123 le32_to_cpu(cck->fina_sync_err_cnt),
1124 accum_cck->fina_sync_err_cnt,
1125 delta_cck->fina_sync_err_cnt,
1126 max_cck->fina_sync_err_cnt);
1127 pos += scnprintf(buf + pos, bufsz - pos,
1128 fmt_table, "sfd_timeout:",
1129 le32_to_cpu(cck->sfd_timeout),
1130 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1131 max_cck->sfd_timeout);
1132 pos += scnprintf(buf + pos, bufsz - pos,
1133 fmt_table, "fina_timeout:",
1134 le32_to_cpu(cck->fina_timeout),
1135 accum_cck->fina_timeout, delta_cck->fina_timeout,
1136 max_cck->fina_timeout);
1137 pos += scnprintf(buf + pos, bufsz - pos,
1138 fmt_table, "unresponded_rts:",
1139 le32_to_cpu(cck->unresponded_rts),
1140 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1141 max_cck->unresponded_rts);
1142 pos += scnprintf(buf + pos, bufsz - pos,
1143 fmt_table, "rxe_frame_lmt_ovrun:",
1144 le32_to_cpu(cck->rxe_frame_limit_overrun),
1145 accum_cck->rxe_frame_limit_overrun,
1146 delta_cck->rxe_frame_limit_overrun,
1147 max_cck->rxe_frame_limit_overrun);
1148 pos += scnprintf(buf + pos, bufsz - pos,
1149 fmt_table, "sent_ack_cnt:",
1150 le32_to_cpu(cck->sent_ack_cnt),
1151 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1152 max_cck->sent_ack_cnt);
1153 pos += scnprintf(buf + pos, bufsz - pos,
1154 fmt_table, "sent_cts_cnt:",
1155 le32_to_cpu(cck->sent_cts_cnt),
1156 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1157 max_cck->sent_cts_cnt);
1158 pos += scnprintf(buf + pos, bufsz - pos,
1159 fmt_table, "sent_ba_rsp_cnt:",
1160 le32_to_cpu(cck->sent_ba_rsp_cnt),
1161 accum_cck->sent_ba_rsp_cnt,
1162 delta_cck->sent_ba_rsp_cnt,
1163 max_cck->sent_ba_rsp_cnt);
1164 pos += scnprintf(buf + pos, bufsz - pos,
1165 fmt_table, "dsp_self_kill:",
1166 le32_to_cpu(cck->dsp_self_kill),
1167 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1168 max_cck->dsp_self_kill);
1169 pos += scnprintf(buf + pos, bufsz - pos,
1170 fmt_table, "mh_format_err:",
1171 le32_to_cpu(cck->mh_format_err),
1172 accum_cck->mh_format_err, delta_cck->mh_format_err,
1173 max_cck->mh_format_err);
1174 pos += scnprintf(buf + pos, bufsz - pos,
1175 fmt_table, "re_acq_main_rssi_sum:",
1176 le32_to_cpu(cck->re_acq_main_rssi_sum),
1177 accum_cck->re_acq_main_rssi_sum,
1178 delta_cck->re_acq_main_rssi_sum,
1179 max_cck->re_acq_main_rssi_sum);
1180
1181 pos += scnprintf(buf + pos, bufsz - pos,
1182 fmt_header, "Statistics_Rx - GENERAL:");
1183 pos += scnprintf(buf + pos, bufsz - pos,
1184 fmt_table, "bogus_cts:",
1185 le32_to_cpu(general->bogus_cts),
1186 accum_general->bogus_cts, delta_general->bogus_cts,
1187 max_general->bogus_cts);
1188 pos += scnprintf(buf + pos, bufsz - pos,
1189 fmt_table, "bogus_ack:",
1190 le32_to_cpu(general->bogus_ack),
1191 accum_general->bogus_ack, delta_general->bogus_ack,
1192 max_general->bogus_ack);
1193 pos += scnprintf(buf + pos, bufsz - pos,
1194 fmt_table, "non_bssid_frames:",
1195 le32_to_cpu(general->non_bssid_frames),
1196 accum_general->non_bssid_frames,
1197 delta_general->non_bssid_frames,
1198 max_general->non_bssid_frames);
1199 pos += scnprintf(buf + pos, bufsz - pos,
1200 fmt_table, "filtered_frames:",
1201 le32_to_cpu(general->filtered_frames),
1202 accum_general->filtered_frames,
1203 delta_general->filtered_frames,
1204 max_general->filtered_frames);
1205 pos += scnprintf(buf + pos, bufsz - pos,
1206 fmt_table, "non_channel_beacons:",
1207 le32_to_cpu(general->non_channel_beacons),
1208 accum_general->non_channel_beacons,
1209 delta_general->non_channel_beacons,
1210 max_general->non_channel_beacons);
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 fmt_table, "channel_beacons:",
1213 le32_to_cpu(general->channel_beacons),
1214 accum_general->channel_beacons,
1215 delta_general->channel_beacons,
1216 max_general->channel_beacons);
1217 pos += scnprintf(buf + pos, bufsz - pos,
1218 fmt_table, "num_missed_bcon:",
1219 le32_to_cpu(general->num_missed_bcon),
1220 accum_general->num_missed_bcon,
1221 delta_general->num_missed_bcon,
1222 max_general->num_missed_bcon);
1223 pos += scnprintf(buf + pos, bufsz - pos,
1224 fmt_table, "adc_rx_saturation_time:",
1225 le32_to_cpu(general->adc_rx_saturation_time),
1226 accum_general->adc_rx_saturation_time,
1227 delta_general->adc_rx_saturation_time,
1228 max_general->adc_rx_saturation_time);
1229 pos += scnprintf(buf + pos, bufsz - pos,
1230 fmt_table, "ina_detect_search_tm:",
1231 le32_to_cpu(general->ina_detection_search_time),
1232 accum_general->ina_detection_search_time,
1233 delta_general->ina_detection_search_time,
1234 max_general->ina_detection_search_time);
1235 pos += scnprintf(buf + pos, bufsz - pos,
1236 fmt_table, "beacon_silence_rssi_a:",
1237 le32_to_cpu(general->beacon_silence_rssi_a),
1238 accum_general->beacon_silence_rssi_a,
1239 delta_general->beacon_silence_rssi_a,
1240 max_general->beacon_silence_rssi_a);
1241 pos += scnprintf(buf + pos, bufsz - pos,
1242 fmt_table, "beacon_silence_rssi_b:",
1243 le32_to_cpu(general->beacon_silence_rssi_b),
1244 accum_general->beacon_silence_rssi_b,
1245 delta_general->beacon_silence_rssi_b,
1246 max_general->beacon_silence_rssi_b);
1247 pos += scnprintf(buf + pos, bufsz - pos,
1248 fmt_table, "beacon_silence_rssi_c:",
1249 le32_to_cpu(general->beacon_silence_rssi_c),
1250 accum_general->beacon_silence_rssi_c,
1251 delta_general->beacon_silence_rssi_c,
1252 max_general->beacon_silence_rssi_c);
1253 pos += scnprintf(buf + pos, bufsz - pos,
1254 fmt_table, "interference_data_flag:",
1255 le32_to_cpu(general->interference_data_flag),
1256 accum_general->interference_data_flag,
1257 delta_general->interference_data_flag,
1258 max_general->interference_data_flag);
1259 pos += scnprintf(buf + pos, bufsz - pos,
1260 fmt_table, "channel_load:",
1261 le32_to_cpu(general->channel_load),
1262 accum_general->channel_load,
1263 delta_general->channel_load,
1264 max_general->channel_load);
1265 pos += scnprintf(buf + pos, bufsz - pos,
1266 fmt_table, "dsp_false_alarms:",
1267 le32_to_cpu(general->dsp_false_alarms),
1268 accum_general->dsp_false_alarms,
1269 delta_general->dsp_false_alarms,
1270 max_general->dsp_false_alarms);
1271 pos += scnprintf(buf + pos, bufsz - pos,
1272 fmt_table, "beacon_rssi_a:",
1273 le32_to_cpu(general->beacon_rssi_a),
1274 accum_general->beacon_rssi_a,
1275 delta_general->beacon_rssi_a,
1276 max_general->beacon_rssi_a);
1277 pos += scnprintf(buf + pos, bufsz - pos,
1278 fmt_table, "beacon_rssi_b:",
1279 le32_to_cpu(general->beacon_rssi_b),
1280 accum_general->beacon_rssi_b,
1281 delta_general->beacon_rssi_b,
1282 max_general->beacon_rssi_b);
1283 pos += scnprintf(buf + pos, bufsz - pos,
1284 fmt_table, "beacon_rssi_c:",
1285 le32_to_cpu(general->beacon_rssi_c),
1286 accum_general->beacon_rssi_c,
1287 delta_general->beacon_rssi_c,
1288 max_general->beacon_rssi_c);
1289 pos += scnprintf(buf + pos, bufsz - pos,
1290 fmt_table, "beacon_energy_a:",
1291 le32_to_cpu(general->beacon_energy_a),
1292 accum_general->beacon_energy_a,
1293 delta_general->beacon_energy_a,
1294 max_general->beacon_energy_a);
1295 pos += scnprintf(buf + pos, bufsz - pos,
1296 fmt_table, "beacon_energy_b:",
1297 le32_to_cpu(general->beacon_energy_b),
1298 accum_general->beacon_energy_b,
1299 delta_general->beacon_energy_b,
1300 max_general->beacon_energy_b);
1301 pos += scnprintf(buf + pos, bufsz - pos,
1302 fmt_table, "beacon_energy_c:",
1303 le32_to_cpu(general->beacon_energy_c),
1304 accum_general->beacon_energy_c,
1305 delta_general->beacon_energy_c,
1306 max_general->beacon_energy_c);
1307
1308 pos += scnprintf(buf + pos, bufsz - pos,
1309 fmt_header, "Statistics_Rx - OFDM_HT:");
1310 pos += scnprintf(buf + pos, bufsz - pos,
1311 fmt_table, "plcp_err:",
1312 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1313 delta_ht->plcp_err, max_ht->plcp_err);
1314 pos += scnprintf(buf + pos, bufsz - pos,
1315 fmt_table, "overrun_err:",
1316 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1317 delta_ht->overrun_err, max_ht->overrun_err);
1318 pos += scnprintf(buf + pos, bufsz - pos,
1319 fmt_table, "early_overrun_err:",
1320 le32_to_cpu(ht->early_overrun_err),
1321 accum_ht->early_overrun_err,
1322 delta_ht->early_overrun_err,
1323 max_ht->early_overrun_err);
1324 pos += scnprintf(buf + pos, bufsz - pos,
1325 fmt_table, "crc32_good:",
1326 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1327 delta_ht->crc32_good, max_ht->crc32_good);
1328 pos += scnprintf(buf + pos, bufsz - pos,
1329 fmt_table, "crc32_err:",
1330 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1331 delta_ht->crc32_err, max_ht->crc32_err);
1332 pos += scnprintf(buf + pos, bufsz - pos,
1333 fmt_table, "mh_format_err:",
1334 le32_to_cpu(ht->mh_format_err),
1335 accum_ht->mh_format_err,
1336 delta_ht->mh_format_err, max_ht->mh_format_err);
1337 pos += scnprintf(buf + pos, bufsz - pos,
1338 fmt_table, "agg_crc32_good:",
1339 le32_to_cpu(ht->agg_crc32_good),
1340 accum_ht->agg_crc32_good,
1341 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1342 pos += scnprintf(buf + pos, bufsz - pos,
1343 fmt_table, "agg_mpdu_cnt:",
1344 le32_to_cpu(ht->agg_mpdu_cnt),
1345 accum_ht->agg_mpdu_cnt,
1346 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1347 pos += scnprintf(buf + pos, bufsz - pos,
1348 fmt_table, "agg_cnt:",
1349 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1350 delta_ht->agg_cnt, max_ht->agg_cnt);
1351 pos += scnprintf(buf + pos, bufsz - pos,
1352 fmt_table, "unsupport_mcs:",
1353 le32_to_cpu(ht->unsupport_mcs),
1354 accum_ht->unsupport_mcs,
1355 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1356
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001357 spin_unlock_bh(&priv->statistics.lock);
1358
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001359 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1360 kfree(buf);
1361 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001362}
1363
1364static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1365 char __user *user_buf,
1366 size_t count, loff_t *ppos)
1367{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001368 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001369 int pos = 0;
1370 char *buf;
1371 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1372 ssize_t ret;
1373 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1374
Don Fry83626402012-03-07 09:52:37 -08001375 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001376 return -EAGAIN;
1377
1378 buf = kzalloc(bufsz, GFP_KERNEL);
1379 if (!buf) {
1380 IWL_ERR(priv, "Can not allocate Buffer\n");
1381 return -ENOMEM;
1382 }
1383
1384 /* the statistic information display here is based on
1385 * the last statistics notification from uCode
1386 * might not reflect the current uCode activity
1387 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001388 spin_lock_bh(&priv->statistics.lock);
1389
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001390 tx = &priv->statistics.tx;
1391 accum_tx = &priv->accum_stats.tx;
1392 delta_tx = &priv->delta_stats.tx;
1393 max_tx = &priv->max_delta_stats.tx;
1394
1395 pos += iwl_statistics_flag(priv, buf, bufsz);
1396 pos += scnprintf(buf + pos, bufsz - pos,
1397 fmt_header, "Statistics_Tx:");
1398 pos += scnprintf(buf + pos, bufsz - pos,
1399 fmt_table, "preamble:",
1400 le32_to_cpu(tx->preamble_cnt),
1401 accum_tx->preamble_cnt,
1402 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1403 pos += scnprintf(buf + pos, bufsz - pos,
1404 fmt_table, "rx_detected_cnt:",
1405 le32_to_cpu(tx->rx_detected_cnt),
1406 accum_tx->rx_detected_cnt,
1407 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1408 pos += scnprintf(buf + pos, bufsz - pos,
1409 fmt_table, "bt_prio_defer_cnt:",
1410 le32_to_cpu(tx->bt_prio_defer_cnt),
1411 accum_tx->bt_prio_defer_cnt,
1412 delta_tx->bt_prio_defer_cnt,
1413 max_tx->bt_prio_defer_cnt);
1414 pos += scnprintf(buf + pos, bufsz - pos,
1415 fmt_table, "bt_prio_kill_cnt:",
1416 le32_to_cpu(tx->bt_prio_kill_cnt),
1417 accum_tx->bt_prio_kill_cnt,
1418 delta_tx->bt_prio_kill_cnt,
1419 max_tx->bt_prio_kill_cnt);
1420 pos += scnprintf(buf + pos, bufsz - pos,
1421 fmt_table, "few_bytes_cnt:",
1422 le32_to_cpu(tx->few_bytes_cnt),
1423 accum_tx->few_bytes_cnt,
1424 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1425 pos += scnprintf(buf + pos, bufsz - pos,
1426 fmt_table, "cts_timeout:",
1427 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1428 delta_tx->cts_timeout, max_tx->cts_timeout);
1429 pos += scnprintf(buf + pos, bufsz - pos,
1430 fmt_table, "ack_timeout:",
1431 le32_to_cpu(tx->ack_timeout),
1432 accum_tx->ack_timeout,
1433 delta_tx->ack_timeout, max_tx->ack_timeout);
1434 pos += scnprintf(buf + pos, bufsz - pos,
1435 fmt_table, "expected_ack_cnt:",
1436 le32_to_cpu(tx->expected_ack_cnt),
1437 accum_tx->expected_ack_cnt,
1438 delta_tx->expected_ack_cnt,
1439 max_tx->expected_ack_cnt);
1440 pos += scnprintf(buf + pos, bufsz - pos,
1441 fmt_table, "actual_ack_cnt:",
1442 le32_to_cpu(tx->actual_ack_cnt),
1443 accum_tx->actual_ack_cnt,
1444 delta_tx->actual_ack_cnt,
1445 max_tx->actual_ack_cnt);
1446 pos += scnprintf(buf + pos, bufsz - pos,
1447 fmt_table, "dump_msdu_cnt:",
1448 le32_to_cpu(tx->dump_msdu_cnt),
1449 accum_tx->dump_msdu_cnt,
1450 delta_tx->dump_msdu_cnt,
1451 max_tx->dump_msdu_cnt);
1452 pos += scnprintf(buf + pos, bufsz - pos,
1453 fmt_table, "abort_nxt_frame_mismatch:",
1454 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1455 accum_tx->burst_abort_next_frame_mismatch_cnt,
1456 delta_tx->burst_abort_next_frame_mismatch_cnt,
1457 max_tx->burst_abort_next_frame_mismatch_cnt);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 fmt_table, "abort_missing_nxt_frame:",
1460 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1461 accum_tx->burst_abort_missing_next_frame_cnt,
1462 delta_tx->burst_abort_missing_next_frame_cnt,
1463 max_tx->burst_abort_missing_next_frame_cnt);
1464 pos += scnprintf(buf + pos, bufsz - pos,
1465 fmt_table, "cts_timeout_collision:",
1466 le32_to_cpu(tx->cts_timeout_collision),
1467 accum_tx->cts_timeout_collision,
1468 delta_tx->cts_timeout_collision,
1469 max_tx->cts_timeout_collision);
1470 pos += scnprintf(buf + pos, bufsz - pos,
1471 fmt_table, "ack_ba_timeout_collision:",
1472 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1473 accum_tx->ack_or_ba_timeout_collision,
1474 delta_tx->ack_or_ba_timeout_collision,
1475 max_tx->ack_or_ba_timeout_collision);
1476 pos += scnprintf(buf + pos, bufsz - pos,
1477 fmt_table, "agg ba_timeout:",
1478 le32_to_cpu(tx->agg.ba_timeout),
1479 accum_tx->agg.ba_timeout,
1480 delta_tx->agg.ba_timeout,
1481 max_tx->agg.ba_timeout);
1482 pos += scnprintf(buf + pos, bufsz - pos,
1483 fmt_table, "agg ba_resched_frames:",
1484 le32_to_cpu(tx->agg.ba_reschedule_frames),
1485 accum_tx->agg.ba_reschedule_frames,
1486 delta_tx->agg.ba_reschedule_frames,
1487 max_tx->agg.ba_reschedule_frames);
1488 pos += scnprintf(buf + pos, bufsz - pos,
1489 fmt_table, "agg scd_query_agg_frame:",
1490 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1491 accum_tx->agg.scd_query_agg_frame_cnt,
1492 delta_tx->agg.scd_query_agg_frame_cnt,
1493 max_tx->agg.scd_query_agg_frame_cnt);
1494 pos += scnprintf(buf + pos, bufsz - pos,
1495 fmt_table, "agg scd_query_no_agg:",
1496 le32_to_cpu(tx->agg.scd_query_no_agg),
1497 accum_tx->agg.scd_query_no_agg,
1498 delta_tx->agg.scd_query_no_agg,
1499 max_tx->agg.scd_query_no_agg);
1500 pos += scnprintf(buf + pos, bufsz - pos,
1501 fmt_table, "agg scd_query_agg:",
1502 le32_to_cpu(tx->agg.scd_query_agg),
1503 accum_tx->agg.scd_query_agg,
1504 delta_tx->agg.scd_query_agg,
1505 max_tx->agg.scd_query_agg);
1506 pos += scnprintf(buf + pos, bufsz - pos,
1507 fmt_table, "agg scd_query_mismatch:",
1508 le32_to_cpu(tx->agg.scd_query_mismatch),
1509 accum_tx->agg.scd_query_mismatch,
1510 delta_tx->agg.scd_query_mismatch,
1511 max_tx->agg.scd_query_mismatch);
1512 pos += scnprintf(buf + pos, bufsz - pos,
1513 fmt_table, "agg frame_not_ready:",
1514 le32_to_cpu(tx->agg.frame_not_ready),
1515 accum_tx->agg.frame_not_ready,
1516 delta_tx->agg.frame_not_ready,
1517 max_tx->agg.frame_not_ready);
1518 pos += scnprintf(buf + pos, bufsz - pos,
1519 fmt_table, "agg underrun:",
1520 le32_to_cpu(tx->agg.underrun),
1521 accum_tx->agg.underrun,
1522 delta_tx->agg.underrun, max_tx->agg.underrun);
1523 pos += scnprintf(buf + pos, bufsz - pos,
1524 fmt_table, "agg bt_prio_kill:",
1525 le32_to_cpu(tx->agg.bt_prio_kill),
1526 accum_tx->agg.bt_prio_kill,
1527 delta_tx->agg.bt_prio_kill,
1528 max_tx->agg.bt_prio_kill);
1529 pos += scnprintf(buf + pos, bufsz - pos,
1530 fmt_table, "agg rx_ba_rsp_cnt:",
1531 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1532 accum_tx->agg.rx_ba_rsp_cnt,
1533 delta_tx->agg.rx_ba_rsp_cnt,
1534 max_tx->agg.rx_ba_rsp_cnt);
1535
1536 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1537 pos += scnprintf(buf + pos, bufsz - pos,
1538 "tx power: (1/2 dB step)\n");
Johannes Berg7e79a392012-03-05 11:24:32 -08001539 if ((hw_params(priv).valid_tx_ant & ANT_A) &&
1540 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001541 pos += scnprintf(buf + pos, bufsz - pos,
1542 fmt_hex, "antenna A:",
1543 tx->tx_power.ant_a);
Johannes Berg7e79a392012-03-05 11:24:32 -08001544 if ((hw_params(priv).valid_tx_ant & ANT_B) &&
1545 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001546 pos += scnprintf(buf + pos, bufsz - pos,
1547 fmt_hex, "antenna B:",
1548 tx->tx_power.ant_b);
Johannes Berg7e79a392012-03-05 11:24:32 -08001549 if ((hw_params(priv).valid_tx_ant & ANT_C) &&
1550 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001551 pos += scnprintf(buf + pos, bufsz - pos,
1552 fmt_hex, "antenna C:",
1553 tx->tx_power.ant_c);
1554 }
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001555
1556 spin_unlock_bh(&priv->statistics.lock);
1557
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001558 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1559 kfree(buf);
1560 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001561}
1562
1563static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1564 char __user *user_buf,
1565 size_t count, loff_t *ppos)
1566{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001567 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001568 int pos = 0;
1569 char *buf;
1570 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1571 ssize_t ret;
1572 struct statistics_general_common *general, *accum_general;
1573 struct statistics_general_common *delta_general, *max_general;
1574 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1575 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1576
Don Fry83626402012-03-07 09:52:37 -08001577 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001578 return -EAGAIN;
1579
1580 buf = kzalloc(bufsz, GFP_KERNEL);
1581 if (!buf) {
1582 IWL_ERR(priv, "Can not allocate Buffer\n");
1583 return -ENOMEM;
1584 }
1585
1586 /* the statistic information display here is based on
1587 * the last statistics notification from uCode
1588 * might not reflect the current uCode activity
1589 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001590
1591 spin_lock_bh(&priv->statistics.lock);
1592
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001593 general = &priv->statistics.common;
1594 dbg = &priv->statistics.common.dbg;
1595 div = &priv->statistics.common.div;
1596 accum_general = &priv->accum_stats.common;
1597 accum_dbg = &priv->accum_stats.common.dbg;
1598 accum_div = &priv->accum_stats.common.div;
1599 delta_general = &priv->delta_stats.common;
1600 max_general = &priv->max_delta_stats.common;
1601 delta_dbg = &priv->delta_stats.common.dbg;
1602 max_dbg = &priv->max_delta_stats.common.dbg;
1603 delta_div = &priv->delta_stats.common.div;
1604 max_div = &priv->max_delta_stats.common.div;
1605
1606 pos += iwl_statistics_flag(priv, buf, bufsz);
1607 pos += scnprintf(buf + pos, bufsz - pos,
1608 fmt_header, "Statistics_General:");
1609 pos += scnprintf(buf + pos, bufsz - pos,
1610 fmt_value, "temperature:",
1611 le32_to_cpu(general->temperature));
1612 pos += scnprintf(buf + pos, bufsz - pos,
1613 fmt_value, "temperature_m:",
1614 le32_to_cpu(general->temperature_m));
1615 pos += scnprintf(buf + pos, bufsz - pos,
1616 fmt_value, "ttl_timestamp:",
1617 le32_to_cpu(general->ttl_timestamp));
1618 pos += scnprintf(buf + pos, bufsz - pos,
1619 fmt_table, "burst_check:",
1620 le32_to_cpu(dbg->burst_check),
1621 accum_dbg->burst_check,
1622 delta_dbg->burst_check, max_dbg->burst_check);
1623 pos += scnprintf(buf + pos, bufsz - pos,
1624 fmt_table, "burst_count:",
1625 le32_to_cpu(dbg->burst_count),
1626 accum_dbg->burst_count,
1627 delta_dbg->burst_count, max_dbg->burst_count);
1628 pos += scnprintf(buf + pos, bufsz - pos,
1629 fmt_table, "wait_for_silence_timeout_count:",
1630 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1631 accum_dbg->wait_for_silence_timeout_cnt,
1632 delta_dbg->wait_for_silence_timeout_cnt,
1633 max_dbg->wait_for_silence_timeout_cnt);
1634 pos += scnprintf(buf + pos, bufsz - pos,
1635 fmt_table, "sleep_time:",
1636 le32_to_cpu(general->sleep_time),
1637 accum_general->sleep_time,
1638 delta_general->sleep_time, max_general->sleep_time);
1639 pos += scnprintf(buf + pos, bufsz - pos,
1640 fmt_table, "slots_out:",
1641 le32_to_cpu(general->slots_out),
1642 accum_general->slots_out,
1643 delta_general->slots_out, max_general->slots_out);
1644 pos += scnprintf(buf + pos, bufsz - pos,
1645 fmt_table, "slots_idle:",
1646 le32_to_cpu(general->slots_idle),
1647 accum_general->slots_idle,
1648 delta_general->slots_idle, max_general->slots_idle);
1649 pos += scnprintf(buf + pos, bufsz - pos,
1650 fmt_table, "tx_on_a:",
1651 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1652 delta_div->tx_on_a, max_div->tx_on_a);
1653 pos += scnprintf(buf + pos, bufsz - pos,
1654 fmt_table, "tx_on_b:",
1655 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1656 delta_div->tx_on_b, max_div->tx_on_b);
1657 pos += scnprintf(buf + pos, bufsz - pos,
1658 fmt_table, "exec_time:",
1659 le32_to_cpu(div->exec_time), accum_div->exec_time,
1660 delta_div->exec_time, max_div->exec_time);
1661 pos += scnprintf(buf + pos, bufsz - pos,
1662 fmt_table, "probe_time:",
1663 le32_to_cpu(div->probe_time), accum_div->probe_time,
1664 delta_div->probe_time, max_div->probe_time);
1665 pos += scnprintf(buf + pos, bufsz - pos,
1666 fmt_table, "rx_enable_counter:",
1667 le32_to_cpu(general->rx_enable_counter),
1668 accum_general->rx_enable_counter,
1669 delta_general->rx_enable_counter,
1670 max_general->rx_enable_counter);
1671 pos += scnprintf(buf + pos, bufsz - pos,
1672 fmt_table, "num_of_sos_states:",
1673 le32_to_cpu(general->num_of_sos_states),
1674 accum_general->num_of_sos_states,
1675 delta_general->num_of_sos_states,
1676 max_general->num_of_sos_states);
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001677
1678 spin_unlock_bh(&priv->statistics.lock);
1679
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001680 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1681 kfree(buf);
1682 return ret;
1683}
1684
1685static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1686 char __user *user_buf,
1687 size_t count, loff_t *ppos)
1688{
1689 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1690 int pos = 0;
1691 char *buf;
1692 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1693 ssize_t ret;
1694 struct statistics_bt_activity *bt, *accum_bt;
1695
Don Fry83626402012-03-07 09:52:37 -08001696 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001697 return -EAGAIN;
1698
1699 if (!priv->bt_enable_flag)
1700 return -EINVAL;
1701
1702 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001703 mutex_lock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001704 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001705 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001706
1707 if (ret) {
1708 IWL_ERR(priv,
1709 "Error sending statistics request: %zd\n", ret);
1710 return -EAGAIN;
1711 }
1712 buf = kzalloc(bufsz, GFP_KERNEL);
1713 if (!buf) {
1714 IWL_ERR(priv, "Can not allocate Buffer\n");
1715 return -ENOMEM;
1716 }
1717
1718 /*
1719 * the statistic information display here is based on
1720 * the last statistics notification from uCode
1721 * might not reflect the current uCode activity
1722 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001723
1724 spin_lock_bh(&priv->statistics.lock);
1725
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001726 bt = &priv->statistics.bt_activity;
1727 accum_bt = &priv->accum_stats.bt_activity;
1728
1729 pos += iwl_statistics_flag(priv, buf, bufsz);
1730 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1731 pos += scnprintf(buf + pos, bufsz - pos,
1732 "\t\t\tcurrent\t\t\taccumulative\n");
1733 pos += scnprintf(buf + pos, bufsz - pos,
1734 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1735 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1736 accum_bt->hi_priority_tx_req_cnt);
1737 pos += scnprintf(buf + pos, bufsz - pos,
1738 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1739 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1740 accum_bt->hi_priority_tx_denied_cnt);
1741 pos += scnprintf(buf + pos, bufsz - pos,
1742 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1743 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1744 accum_bt->lo_priority_tx_req_cnt);
1745 pos += scnprintf(buf + pos, bufsz - pos,
1746 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1747 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1748 accum_bt->lo_priority_tx_denied_cnt);
1749 pos += scnprintf(buf + pos, bufsz - pos,
1750 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1751 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1752 accum_bt->hi_priority_rx_req_cnt);
1753 pos += scnprintf(buf + pos, bufsz - pos,
1754 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1755 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1756 accum_bt->hi_priority_rx_denied_cnt);
1757 pos += scnprintf(buf + pos, bufsz - pos,
1758 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1759 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1760 accum_bt->lo_priority_rx_req_cnt);
1761 pos += scnprintf(buf + pos, bufsz - pos,
1762 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1763 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1764 accum_bt->lo_priority_rx_denied_cnt);
1765
1766 pos += scnprintf(buf + pos, bufsz - pos,
1767 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1768 le32_to_cpu(priv->statistics.num_bt_kills),
1769 priv->statistics.accum_num_bt_kills);
1770
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001771 spin_unlock_bh(&priv->statistics.lock);
1772
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001773 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1774 kfree(buf);
1775 return ret;
1776}
1777
1778static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1779 char __user *user_buf,
1780 size_t count, loff_t *ppos)
1781{
1782 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1783 int pos = 0;
1784 char *buf;
1785 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1786 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1787 ssize_t ret;
1788
Don Fry83626402012-03-07 09:52:37 -08001789 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001790 return -EAGAIN;
1791
1792 buf = kzalloc(bufsz, GFP_KERNEL);
1793 if (!buf) {
1794 IWL_ERR(priv, "Can not allocate Buffer\n");
1795 return -ENOMEM;
1796 }
1797
1798 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1799 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1800 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001801 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001802 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1803 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001804 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001805 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1806 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001807 priv->reply_tx_stats.pp_bt_prio);
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_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001810 priv->reply_tx_stats.pp_quiet_period);
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_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001813 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001814 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1815 iwl_get_tx_fail_reason(
1816 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001817 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001818 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1819 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001820 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001821 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1822 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001823 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001824 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1825 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001826 priv->reply_tx_stats.fifo_underrun);
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_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001829 priv->reply_tx_stats.drain_flow);
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_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001832 priv->reply_tx_stats.rfkill_flush);
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_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001835 priv->reply_tx_stats.life_expire);
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_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001838 priv->reply_tx_stats.dest_ps);
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_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001841 priv->reply_tx_stats.host_abort);
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_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001844 priv->reply_tx_stats.pp_delay);
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_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001847 priv->reply_tx_stats.sta_invalid);
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_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_tx_stats.frag_drop);
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_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001853 priv->reply_tx_stats.tid_disable);
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_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001856 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001857 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1858 iwl_get_tx_fail_reason(
1859 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001860 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001861 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1862 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001863 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001864 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1865 iwl_get_tx_fail_reason(
1866 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001867 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001868 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001869 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001870
1871 pos += scnprintf(buf + pos, bufsz - pos,
1872 "\nStatistics_Agg_TX_Error:\n");
1873
1874 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1875 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001876 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001877 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1878 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001879 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001880 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1881 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001882 priv->reply_agg_tx_stats.few_bytes);
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_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001885 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001886 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1887 iwl_get_agg_tx_fail_reason(
1888 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001889 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001890 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1891 iwl_get_agg_tx_fail_reason(
1892 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001893 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001894 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1895 iwl_get_agg_tx_fail_reason(
1896 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001897 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001898 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1899 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001900 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001901 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1902 iwl_get_agg_tx_fail_reason(
1903 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001904 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001905 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1906 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001907 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001908 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1909 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001910 priv->reply_agg_tx_stats.dump_tx);
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_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001913 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001914 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001915 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001916
1917 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1918 kfree(buf);
1919 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001920}
1921
Wey-Yi Guy52259352009-08-07 15:41:43 -07001922static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1923 char __user *user_buf,
1924 size_t count, loff_t *ppos) {
1925
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001926 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001927 int pos = 0;
1928 int cnt = 0;
1929 char *buf;
1930 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1931 ssize_t ret;
1932 struct iwl_sensitivity_data *data;
1933
1934 data = &priv->sensitivity_data;
1935 buf = kzalloc(bufsz, GFP_KERNEL);
1936 if (!buf) {
1937 IWL_ERR(priv, "Can not allocate Buffer\n");
1938 return -ENOMEM;
1939 }
1940
1941 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1942 data->auto_corr_ofdm);
1943 pos += scnprintf(buf + pos, bufsz - pos,
1944 "auto_corr_ofdm_mrc:\t\t %u\n",
1945 data->auto_corr_ofdm_mrc);
1946 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1947 data->auto_corr_ofdm_x1);
1948 pos += scnprintf(buf + pos, bufsz - pos,
1949 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1950 data->auto_corr_ofdm_mrc_x1);
1951 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1952 data->auto_corr_cck);
1953 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1954 data->auto_corr_cck_mrc);
1955 pos += scnprintf(buf + pos, bufsz - pos,
1956 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1957 data->last_bad_plcp_cnt_ofdm);
1958 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1959 data->last_fa_cnt_ofdm);
1960 pos += scnprintf(buf + pos, bufsz - pos,
1961 "last_bad_plcp_cnt_cck:\t\t %u\n",
1962 data->last_bad_plcp_cnt_cck);
1963 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1964 data->last_fa_cnt_cck);
1965 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1966 data->nrg_curr_state);
1967 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1968 data->nrg_prev_state);
1969 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1970 for (cnt = 0; cnt < 10; cnt++) {
1971 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1972 data->nrg_value[cnt]);
1973 }
1974 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1975 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1976 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1977 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1978 data->nrg_silence_rssi[cnt]);
1979 }
1980 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1981 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1982 data->nrg_silence_ref);
1983 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1984 data->nrg_energy_idx);
1985 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1986 data->nrg_silence_idx);
1987 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1988 data->nrg_th_cck);
1989 pos += scnprintf(buf + pos, bufsz - pos,
1990 "nrg_auto_corr_silence_diff:\t %u\n",
1991 data->nrg_auto_corr_silence_diff);
1992 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1993 data->num_in_cck_no_fa);
1994 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1995 data->nrg_th_ofdm);
1996
1997 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1998 kfree(buf);
1999 return ret;
2000}
2001
2002
2003static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2004 char __user *user_buf,
2005 size_t count, loff_t *ppos) {
2006
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002007 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002008 int pos = 0;
2009 int cnt = 0;
2010 char *buf;
2011 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2012 ssize_t ret;
2013 struct iwl_chain_noise_data *data;
2014
2015 data = &priv->chain_noise_data;
2016 buf = kzalloc(bufsz, GFP_KERNEL);
2017 if (!buf) {
2018 IWL_ERR(priv, "Can not allocate Buffer\n");
2019 return -ENOMEM;
2020 }
2021
2022 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2023 data->active_chains);
2024 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2025 data->chain_noise_a);
2026 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2027 data->chain_noise_b);
2028 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2029 data->chain_noise_c);
2030 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2031 data->chain_signal_a);
2032 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2033 data->chain_signal_b);
2034 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2035 data->chain_signal_c);
2036 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2037 data->beacon_count);
2038
2039 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2040 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2041 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2042 data->disconn_array[cnt]);
2043 }
2044 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2045 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2046 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2047 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2048 data->delta_gain_code[cnt]);
2049 }
2050 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2051 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2052 data->radio_write);
2053 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2054 data->state);
2055
2056 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2057 kfree(buf);
2058 return ret;
2059}
2060
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002061static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2062 char __user *user_buf,
2063 size_t count, loff_t *ppos)
2064{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002065 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002066 char buf[60];
2067 int pos = 0;
2068 const size_t bufsz = sizeof(buf);
2069 u32 pwrsave_status;
2070
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002071 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002072 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2073
2074 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2075 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2076 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2077 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2078 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2079 "error");
2080
2081 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2082}
2083
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002084static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002085 const char __user *user_buf,
2086 size_t count, loff_t *ppos)
2087{
2088 struct iwl_priv *priv = file->private_data;
2089 char buf[8];
2090 int buf_size;
2091 int clear;
2092
2093 memset(buf, 0, sizeof(buf));
2094 buf_size = min(count, sizeof(buf) - 1);
2095 if (copy_from_user(buf, user_buf, buf_size))
2096 return -EFAULT;
2097 if (sscanf(buf, "%d", &clear) != 1)
2098 return -EFAULT;
2099
2100 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08002101 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002102 iwl_send_statistics_request(priv, CMD_SYNC, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08002103 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002104
2105 return count;
2106}
2107
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002108static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2109 char __user *user_buf,
2110 size_t count, loff_t *ppos) {
2111
Joe Perches57674302010-07-12 13:50:06 -07002112 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002113 int pos = 0;
2114 char buf[128];
2115 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002116
2117 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2118 priv->event_log.ucode_trace ? "On" : "Off");
2119 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2120 priv->event_log.non_wraps_count);
2121 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2122 priv->event_log.wraps_once_count);
2123 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2124 priv->event_log.wraps_more_count);
2125
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002126 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002127}
2128
2129static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2130 const char __user *user_buf,
2131 size_t count, loff_t *ppos)
2132{
2133 struct iwl_priv *priv = file->private_data;
2134 char buf[8];
2135 int buf_size;
2136 int trace;
2137
2138 memset(buf, 0, sizeof(buf));
2139 buf_size = min(count, sizeof(buf) - 1);
2140 if (copy_from_user(buf, user_buf, buf_size))
2141 return -EFAULT;
2142 if (sscanf(buf, "%d", &trace) != 1)
2143 return -EFAULT;
2144
2145 if (trace) {
2146 priv->event_log.ucode_trace = true;
Don Fry83626402012-03-07 09:52:37 -08002147 if (iwl_is_alive(priv)) {
Johannes Berg98d4bf02012-01-13 11:56:11 +01002148 /* start collecting data now */
2149 mod_timer(&priv->ucode_trace, jiffies);
2150 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002151 } else {
2152 priv->event_log.ucode_trace = false;
2153 del_timer_sync(&priv->ucode_trace);
2154 }
2155
2156 return count;
2157}
2158
Johannes Berg60987202010-02-18 00:36:07 -08002159static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2160 char __user *user_buf,
2161 size_t count, loff_t *ppos) {
2162
Joe Perches57674302010-07-12 13:50:06 -07002163 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002164 int len = 0;
2165 char buf[20];
2166
Johannes Berg246ed352010-08-23 10:46:32 +02002167 len = sprintf(buf, "0x%04X\n",
2168 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002169 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2170}
2171
2172static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2173 char __user *user_buf,
2174 size_t count, loff_t *ppos) {
2175
Joe Perches57674302010-07-12 13:50:06 -07002176 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002177 int len = 0;
2178 char buf[20];
2179
2180 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002181 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002182 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2183}
2184
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002185static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2186 char __user *user_buf,
2187 size_t count, loff_t *ppos) {
2188
2189 struct iwl_priv *priv = file->private_data;
2190 int pos = 0;
2191 char buf[12];
2192 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002193
2194 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2195 priv->missed_beacon_threshold);
2196
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002197 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002198}
2199
2200static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2201 const char __user *user_buf,
2202 size_t count, loff_t *ppos)
2203{
2204 struct iwl_priv *priv = file->private_data;
2205 char buf[8];
2206 int buf_size;
2207 int missed;
2208
2209 memset(buf, 0, sizeof(buf));
2210 buf_size = min(count, sizeof(buf) - 1);
2211 if (copy_from_user(buf, user_buf, buf_size))
2212 return -EFAULT;
2213 if (sscanf(buf, "%d", &missed) != 1)
2214 return -EINVAL;
2215
2216 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2217 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2218 priv->missed_beacon_threshold =
2219 IWL_MISSED_BEACON_THRESHOLD_DEF;
2220 else
2221 priv->missed_beacon_threshold = missed;
2222
2223 return count;
2224}
2225
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002226static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2227 char __user *user_buf,
2228 size_t count, loff_t *ppos) {
2229
Joe Perches57674302010-07-12 13:50:06 -07002230 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002231 int pos = 0;
2232 char buf[12];
2233 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002234
2235 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002236 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002237
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002238 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002239}
2240
2241static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2242 const char __user *user_buf,
2243 size_t count, loff_t *ppos) {
2244
2245 struct iwl_priv *priv = file->private_data;
2246 char buf[8];
2247 int buf_size;
2248 int plcp;
2249
2250 memset(buf, 0, sizeof(buf));
2251 buf_size = min(count, sizeof(buf) - 1);
2252 if (copy_from_user(buf, user_buf, buf_size))
2253 return -EFAULT;
2254 if (sscanf(buf, "%d", &plcp) != 1)
2255 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002256 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002257 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002258 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002259 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002260 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002261 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002262 return count;
2263}
2264
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002265static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2266 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002267 size_t count, loff_t *ppos)
2268{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002269 struct iwl_priv *priv = file->private_data;
2270 int i, pos = 0;
2271 char buf[300];
2272 const size_t bufsz = sizeof(buf);
2273 struct iwl_force_reset *force_reset;
2274
2275 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2276 force_reset = &priv->force_reset[i];
2277 pos += scnprintf(buf + pos, bufsz - pos,
2278 "Force reset method %d\n", i);
2279 pos += scnprintf(buf + pos, bufsz - pos,
2280 "\tnumber of reset request: %d\n",
2281 force_reset->reset_request_count);
2282 pos += scnprintf(buf + pos, bufsz - pos,
2283 "\tnumber of reset request success: %d\n",
2284 force_reset->reset_success_count);
2285 pos += scnprintf(buf + pos, bufsz - pos,
2286 "\tnumber of reset request reject: %d\n",
2287 force_reset->reset_reject_count);
2288 pos += scnprintf(buf + pos, bufsz - pos,
2289 "\treset duration: %lu\n",
2290 force_reset->reset_duration);
2291 }
2292 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2293}
2294
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002295static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2296 const char __user *user_buf,
2297 size_t count, loff_t *ppos) {
2298
2299 struct iwl_priv *priv = file->private_data;
2300 char buf[8];
2301 int buf_size;
2302 int reset, ret;
2303
2304 memset(buf, 0, sizeof(buf));
2305 buf_size = min(count, sizeof(buf) - 1);
2306 if (copy_from_user(buf, user_buf, buf_size))
2307 return -EFAULT;
2308 if (sscanf(buf, "%d", &reset) != 1)
2309 return -EINVAL;
2310 switch (reset) {
2311 case IWL_RF_RESET:
2312 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002313 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002314 break;
2315 default:
2316 return -EINVAL;
2317 }
2318 return ret ? ret : count;
2319}
2320
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002321static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2322 const char __user *user_buf,
2323 size_t count, loff_t *ppos) {
2324
2325 struct iwl_priv *priv = file->private_data;
2326 char buf[8];
2327 int buf_size;
2328 int flush;
2329
2330 memset(buf, 0, sizeof(buf));
2331 buf_size = min(count, sizeof(buf) - 1);
2332 if (copy_from_user(buf, user_buf, buf_size))
2333 return -EFAULT;
2334 if (sscanf(buf, "%d", &flush) != 1)
2335 return -EINVAL;
2336
Don Fry83626402012-03-07 09:52:37 -08002337 if (iwl_is_rfkill(priv))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002338 return -EFAULT;
2339
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002340 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002341
2342 return count;
2343}
2344
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002345static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002346 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002347 size_t count, loff_t *ppos)
2348{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002349 struct iwl_priv *priv = file->private_data;
2350 char buf[8];
2351 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002352 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002353
2354 memset(buf, 0, sizeof(buf));
2355 buf_size = min(count, sizeof(buf) - 1);
2356 if (copy_from_user(buf, user_buf, buf_size))
2357 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002358 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002359 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002360 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2361 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002362
Johannes Berge7a09432012-03-06 13:30:54 -08002363 hw_params(priv).wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002364 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002365 return count;
2366}
2367
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002368static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2369 char __user *user_buf,
2370 size_t count, loff_t *ppos) {
2371
2372 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2373 int pos = 0;
2374 char buf[200];
2375 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002376
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002377 if (!priv->bt_enable_flag) {
2378 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002379 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002380 }
2381 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2382 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002383 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2384 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2385 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2386 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002387 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002388 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002389 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2390 priv->bt_ch_announce, priv->kill_ack_mask,
2391 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002392
2393 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2394 switch (priv->bt_traffic_load) {
2395 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2396 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2397 break;
2398 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2399 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2400 break;
2401 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2402 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2403 break;
2404 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2405 default:
2406 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2407 break;
2408 }
2409
Johannes Berg08960de2011-04-05 09:41:53 -07002410 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002411}
2412
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002413static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2414 char __user *user_buf,
2415 size_t count, loff_t *ppos)
2416{
2417 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2418
2419 int pos = 0;
2420 char buf[40];
2421 const size_t bufsz = sizeof(buf);
2422
Don Fry38622412011-12-16 07:07:36 -08002423 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002424 pos += scnprintf(buf + pos, bufsz - pos,
2425 "use %s for aggregation\n",
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002426 (hw_params(priv).use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002427 "rts/cts" : "cts-to-self");
2428 else
2429 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2430
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002431 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2432}
2433
2434static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2435 const char __user *user_buf,
2436 size_t count, loff_t *ppos) {
2437
2438 struct iwl_priv *priv = file->private_data;
2439 char buf[8];
2440 int buf_size;
2441 int rts;
2442
Don Fry38622412011-12-16 07:07:36 -08002443 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002444 return -EINVAL;
2445
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002446 memset(buf, 0, sizeof(buf));
2447 buf_size = min(count, sizeof(buf) - 1);
2448 if (copy_from_user(buf, user_buf, buf_size))
2449 return -EFAULT;
2450 if (sscanf(buf, "%d", &rts) != 1)
2451 return -EINVAL;
2452 if (rts)
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002453 hw_params(priv).use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002454 else
Johannes Bergb9ad70d2012-03-06 13:30:55 -08002455 hw_params(priv).use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002456 return count;
2457}
2458
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002459static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2460 const char __user *user_buf,
2461 size_t count, loff_t *ppos)
2462{
2463 struct iwl_priv *priv = file->private_data;
2464 char buf[8];
2465 int buf_size;
2466
2467 memset(buf, 0, sizeof(buf));
2468 buf_size = min(count, sizeof(buf) - 1);
2469 if (copy_from_user(buf, user_buf, buf_size))
2470 return -EFAULT;
2471
2472 iwl_cmd_echo_test(priv);
2473 return count;
2474}
2475
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002476DEBUGFS_READ_FILE_OPS(rx_statistics);
2477DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002478DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002479DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2480DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2481DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002482DEBUGFS_READ_FILE_OPS(sensitivity);
2483DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002484DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002485DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2486DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002487DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002488DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002489DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002490DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002491DEBUGFS_READ_FILE_OPS(rxon_flags);
2492DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002493DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002494DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002495DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002496DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002497DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002498DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002499DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002500
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002501/*
2502 * Create the debugfs files and directories
2503 *
2504 */
2505int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2506{
Zhu Yi95b1a822008-05-29 16:34:50 +08002507 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002508 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002509
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002510 dir_drv = debugfs_create_dir(name, phyd);
2511 if (!dir_drv)
2512 return -ENOMEM;
2513
2514 priv->debugfs_dir = dir_drv;
2515
2516 dir_data = debugfs_create_dir("data", dir_drv);
2517 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002518 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002519 dir_rf = debugfs_create_dir("rf", dir_drv);
2520 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002521 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002522 dir_debug = debugfs_create_dir("debug", dir_drv);
2523 if (!dir_debug)
2524 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002525
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002526 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2527 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002528 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002529 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2530 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2531 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002532 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002533 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002534 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2535 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002536 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2537 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002538 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002539
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002540 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2541 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002542 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002543 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2544 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2545 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002546 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002547 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002548 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002549 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2550 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2551 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002552 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002553 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002554 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2555 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002556 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002557 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002558 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002559 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2560 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002561 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002562 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002563 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002564 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002565
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002566 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2567 &priv->disable_sens_cal);
2568 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2569 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002570
2571 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2572 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002573 return 0;
2574
2575err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002576 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002577 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002578 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002579}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002580
2581/**
2582 * Remove the debugfs files and directories
2583 *
2584 */
2585void iwl_dbgfs_unregister(struct iwl_priv *priv)
2586{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002587 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002588 return;
2589
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002590 debugfs_remove_recursive(priv->debugfs_dir);
2591 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002592}