blob: 628af563e4e15796373e93c668d1097cc62367f7 [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"
Don Fry65161742012-02-07 15:00:12 -080043#include "iwl-wifi.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070044
45/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080046#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
47 if (!debugfs_create_file(#name, mode, parent, priv, \
48 &iwl_dbgfs_##name##_ops)) \
49 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070050} while (0)
51
Johannes Berg4c84a8f2010-01-22 14:22:54 -080052#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
53 struct dentry *__tmp; \
54 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
55 parent, ptr); \
56 if (IS_ERR(__tmp) || !__tmp) \
57 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070058} while (0)
59
Johannes Berg4c84a8f2010-01-22 14:22:54 -080060#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
61 struct dentry *__tmp; \
62 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
63 parent, ptr); \
64 if (IS_ERR(__tmp) || !__tmp) \
65 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080066} while (0)
67
Johannes Bergca934b62011-09-15 11:46:48 -070068#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
69 struct dentry *__tmp; \
70 __tmp = debugfs_create_u32(#name, mode, \
71 parent, ptr); \
72 if (IS_ERR(__tmp) || !__tmp) \
73 goto err; \
74} while (0)
75
Tomas Winkler712b6cf2008-03-12 16:58:52 -070076/* file operation */
77#define DEBUGFS_READ_FUNC(name) \
78static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
79 char __user *user_buf, \
80 size_t count, loff_t *ppos);
81
82#define DEBUGFS_WRITE_FUNC(name) \
83static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
84 const char __user *user_buf, \
85 size_t count, loff_t *ppos);
86
87
88static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
89{
90 file->private_data = inode->i_private;
91 return 0;
92}
93
94#define DEBUGFS_READ_FILE_OPS(name) \
95 DEBUGFS_READ_FUNC(name); \
96static const struct file_operations iwl_dbgfs_##name##_ops = { \
97 .read = iwl_dbgfs_##name##_read, \
98 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020099 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700100};
101
Ester Kummer189a2b52008-05-15 13:54:18 +0800102#define DEBUGFS_WRITE_FILE_OPS(name) \
103 DEBUGFS_WRITE_FUNC(name); \
104static const struct file_operations iwl_dbgfs_##name##_ops = { \
105 .write = iwl_dbgfs_##name##_write, \
106 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200107 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +0800108};
109
110
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700111#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
112 DEBUGFS_READ_FUNC(name); \
113 DEBUGFS_WRITE_FUNC(name); \
114static const struct file_operations iwl_dbgfs_##name##_ops = { \
115 .write = iwl_dbgfs_##name##_write, \
116 .read = iwl_dbgfs_##name##_read, \
117 .open = iwl_dbgfs_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200118 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700119};
120
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700121static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
122 char __user *user_buf,
123 size_t count, loff_t *ppos) {
124
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700125 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700126 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700127 int pos = 0;
128
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700129 int cnt;
130 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800131 const size_t bufsz = 100 +
132 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700133 buf = kzalloc(bufsz, GFP_KERNEL);
134 if (!buf)
135 return -ENOMEM;
136 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
137 for (cnt = 0; cnt < MANAGEMENT_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_mgmt_string(cnt),
141 priv->tx_stats.mgmt[cnt]);
142 }
143 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
144 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
145 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800146 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700147 get_ctrl_string(cnt),
148 priv->tx_stats.ctrl[cnt]);
149 }
150 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
151 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
152 priv->tx_stats.data_cnt);
153 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
154 priv->tx_stats.data_bytes);
155 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
156 kfree(buf);
157 return ret;
158}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700159
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800160static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700161 const char __user *user_buf,
162 size_t count, loff_t *ppos)
163{
164 struct iwl_priv *priv = file->private_data;
165 u32 clear_flag;
166 char buf[8];
167 int buf_size;
168
169 memset(buf, 0, sizeof(buf));
170 buf_size = min(count, sizeof(buf) - 1);
171 if (copy_from_user(buf, user_buf, buf_size))
172 return -EFAULT;
173 if (sscanf(buf, "%x", &clear_flag) != 1)
174 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800175 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700176
177 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700178}
179
180static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
181 char __user *user_buf,
182 size_t count, loff_t *ppos) {
183
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700184 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700185 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700186 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700187 int cnt;
188 ssize_t ret;
189 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800190 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700191 buf = kzalloc(bufsz, GFP_KERNEL);
192 if (!buf)
193 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700194
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700195 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
196 for (cnt = 0; cnt < MANAGEMENT_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_mgmt_string(cnt),
200 priv->rx_stats.mgmt[cnt]);
201 }
202 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
203 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
204 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800205 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700206 get_ctrl_string(cnt),
207 priv->rx_stats.ctrl[cnt]);
208 }
209 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
210 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
211 priv->rx_stats.data_cnt);
212 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
213 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700214
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700215 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
216 kfree(buf);
217 return ret;
218}
219
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700220static ssize_t iwl_dbgfs_sram_read(struct file *file,
221 char __user *user_buf,
222 size_t count, loff_t *ppos)
223{
Jay Sternberg24834d22011-01-11 15:41:00 -0800224 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800225 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700226 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800227 int i = 0;
228 bool device_format = false;
229 int offset = 0;
230 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700231 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800232 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700233 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800234 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700235
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800236 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800237 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
Don Fry65161742012-02-07 15:00:12 -0800238 struct iwl_nic *nic = nic(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800239 priv->dbgfs_sram_offset = 0x800000;
Don Fry65161742012-02-07 15:00:12 -0800240 if (nic->shrd->ucode_type == IWL_UCODE_INIT)
241 priv->dbgfs_sram_len = nic->fw.ucode_init.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800242 else
Don Fry65161742012-02-07 15:00:12 -0800243 priv->dbgfs_sram_len = nic->fw.ucode_rt.data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800244 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800245 len = priv->dbgfs_sram_len;
246
247 if (len == -4) {
248 device_format = true;
249 len = 4;
250 }
251
252 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800253 buf = kmalloc(bufsz, GFP_KERNEL);
254 if (!buf)
255 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800256
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800257 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800258 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800259 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800260 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800261
262 /* adjust sram address since reads are only on even u32 boundaries */
263 offset = priv->dbgfs_sram_offset & 0x3;
264 sram = priv->dbgfs_sram_offset & ~0x3;
265
266 /* read the first u32 from sram */
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200267 val = iwl_read_targ_mem(trans(priv), sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800268
269 for (; len; len--) {
270 /* put the address at the start of every line */
271 if (i == 0)
272 pos += scnprintf(buf + pos, bufsz - pos,
273 "%08X: ", sram + offset);
274
275 if (device_format)
276 pos += scnprintf(buf + pos, bufsz - pos,
277 "%02x", (val >> (8 * (3 - offset))) & 0xff);
278 else
279 pos += scnprintf(buf + pos, bufsz - pos,
280 "%02x ", (val >> (8 * offset)) & 0xff);
281
282 /* if all bytes processed, read the next u32 from sram */
283 if (++offset == 4) {
284 sram += 4;
285 offset = 0;
Emmanuel Grumbach1042db22012-01-03 16:56:15 +0200286 val = iwl_read_targ_mem(trans(priv), sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700287 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800288
289 /* put in extra spaces and split lines for human readability */
290 if (++i == 16) {
291 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800292 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800293 } else if (!(i & 7)) {
294 pos += scnprintf(buf + pos, bufsz - pos, " ");
295 } else if (!(i & 3)) {
296 pos += scnprintf(buf + pos, bufsz - pos, " ");
297 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700298 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800299 if (i)
300 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700301
302 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800303 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700304 return ret;
305}
306
307static ssize_t iwl_dbgfs_sram_write(struct file *file,
308 const char __user *user_buf,
309 size_t count, loff_t *ppos)
310{
311 struct iwl_priv *priv = file->private_data;
312 char buf[64];
313 int buf_size;
314 u32 offset, len;
315
316 memset(buf, 0, sizeof(buf));
317 buf_size = min(count, sizeof(buf) - 1);
318 if (copy_from_user(buf, user_buf, buf_size))
319 return -EFAULT;
320
321 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800322 priv->dbgfs_sram_offset = offset;
323 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800324 } else if (sscanf(buf, "%x", &offset) == 1) {
325 priv->dbgfs_sram_offset = offset;
326 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700327 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800328 priv->dbgfs_sram_offset = 0;
329 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700330 }
331
332 return count;
333}
334
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700335static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
336 char __user *user_buf,
337 size_t count, loff_t *ppos)
338{
339 struct iwl_priv *priv = file->private_data;
340
341 if (!priv->wowlan_sram)
342 return -ENODATA;
343
344 return simple_read_from_buffer(user_buf, count, ppos,
345 priv->wowlan_sram,
Don Fry65161742012-02-07 15:00:12 -0800346 nic(priv)->fw.ucode_wowlan.data.len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700347}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700348static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
349 size_t count, loff_t *ppos)
350{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700351 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800352 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700353 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700354 char *buf;
355 int i, j, pos = 0;
356 ssize_t ret;
357 /* Add 30 for initial string */
358 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700359
360 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300361 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700362 return -ENOMEM;
363
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700364 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700365 priv->num_stations);
366
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700367 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700368 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700369 if (!station->used)
370 continue;
371 pos += scnprintf(buf + pos, bufsz - pos,
372 "station %d - addr: %pM, flags: %#x\n",
373 i, station->sta.sta.addr,
374 station->sta.station_flags_msk);
375 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200376 "TID\tseq_num\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700377
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700378 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200379 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700380 pos += scnprintf(buf + pos, bufsz - pos,
Emmanuel Grumbach76bc10f2011-11-21 13:25:31 +0200381 "%d:\t%#x\t%#x",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700382 j, tid_data->seq_number,
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700383 tid_data->agg.rate_n_flags);
Johannes Bergda735112010-05-03 01:25:24 -0700384
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700385 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700386 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700387 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700388 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700389 }
Johannes Bergda735112010-05-03 01:25:24 -0700390
391 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700392 }
393
394 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
395 kfree(buf);
396 return ret;
397}
398
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700399static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800400 char __user *user_buf,
401 size_t count,
402 loff_t *ppos)
403{
404 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700405 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800406 int pos = 0, ofs = 0, buf_size = 0;
407 const u8 *ptr;
408 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700409 u16 eeprom_ver;
Don Fry38622412011-12-16 07:07:36 -0800410 size_t eeprom_len = cfg(priv)->base_params->eeprom_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800411 buf_size = 4 * eeprom_len + 256;
412
413 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700414 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800415 return -ENODATA;
416 }
417
Don Fryab36eab2011-11-30 15:37:32 -0800418 ptr = priv->shrd->eeprom;
Julia Lawallc37457e2009-08-03 11:11:45 +0200419 if (!ptr) {
420 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
421 return -ENOMEM;
422 }
423
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800424 /* 4 characters for byte 0xYY */
425 buf = kzalloc(buf_size, GFP_KERNEL);
426 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800427 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800428 return -ENOMEM;
429 }
Don Fryab36eab2011-11-30 15:37:32 -0800430 eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700431 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
432 "version: 0x%x\n",
Don Fry97b52cf2011-11-10 06:55:27 -0800433 (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700434 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800435 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
436 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
437 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
438 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700439 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800440 if (buf_size - pos > 0)
441 buf[pos++] = '\n';
442 }
443
444 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
445 kfree(buf);
446 return ret;
447}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700448
Winkler, Tomasd366df52008-12-02 12:14:01 -0800449static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
450 size_t count, loff_t *ppos)
451{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700452 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800453 struct ieee80211_channel *channels = NULL;
454 const struct ieee80211_supported_band *supp_band = NULL;
455 int pos = 0, i, bufsz = PAGE_SIZE;
456 char *buf;
457 ssize_t ret;
458
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700459 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status))
Winkler, Tomasd366df52008-12-02 12:14:01 -0800460 return -EAGAIN;
461
462 buf = kzalloc(bufsz, GFP_KERNEL);
463 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800464 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800465 return -ENOMEM;
466 }
467
468 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700469 if (supp_band) {
470 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800471
Winkler, Tomasd366df52008-12-02 12:14:01 -0800472 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700473 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
474 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800475
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700476 for (i = 0; i < supp_band->n_channels; i++)
477 pos += scnprintf(buf + pos, bufsz - pos,
478 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700479 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700480 channels[i].max_power,
481 channels[i].flags & IEEE80211_CHAN_RADAR ?
482 " (IEEE 802.11h required)" : "",
483 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
484 || (channels[i].flags &
485 IEEE80211_CHAN_RADAR)) ? "" :
486 ", IBSS",
487 channels[i].flags &
488 IEEE80211_CHAN_PASSIVE_SCAN ?
489 "passive only" : "active/passive");
490 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800491 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700492 if (supp_band) {
493 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800494
Winkler, Tomasd366df52008-12-02 12:14:01 -0800495 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700496 "Displaying %d channels in 5.2GHz band (802.11a)\n",
497 supp_band->n_channels);
498
499 for (i = 0; i < supp_band->n_channels; i++)
500 pos += scnprintf(buf + pos, bufsz - pos,
501 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700502 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700503 channels[i].max_power,
504 channels[i].flags & IEEE80211_CHAN_RADAR ?
505 " (IEEE 802.11h required)" : "",
506 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
507 || (channels[i].flags &
508 IEEE80211_CHAN_RADAR)) ? "" :
509 ", IBSS",
510 channels[i].flags &
511 IEEE80211_CHAN_PASSIVE_SCAN ?
512 "passive only" : "active/passive");
513 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800514 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
515 kfree(buf);
516 return ret;
517}
518
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700519static ssize_t iwl_dbgfs_status_read(struct file *file,
520 char __user *user_buf,
521 size_t count, loff_t *ppos) {
522
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700523 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700524 char buf[512];
525 int pos = 0;
526 const size_t bufsz = sizeof(buf);
527
528 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700529 test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700530 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700531 test_bit(STATUS_INT_ENABLED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700532 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700533 test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700534 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700535 test_bit(STATUS_CT_KILL, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700536 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700537 test_bit(STATUS_INIT, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700538 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700539 test_bit(STATUS_ALIVE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700540 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700541 test_bit(STATUS_READY, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700542 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700543 test_bit(STATUS_TEMPERATURE, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700544 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700545 test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700546 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700547 test_bit(STATUS_EXIT_PENDING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700548 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700549 test_bit(STATUS_STATISTICS, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700550 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700551 test_bit(STATUS_SCANNING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700552 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700553 test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700554 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700555 test_bit(STATUS_SCAN_HW, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700556 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700557 test_bit(STATUS_POWER_PMI, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700558 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700559 test_bit(STATUS_FW_ERROR, &priv->shrd->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700560 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
561}
562
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700563static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700564 char __user *user_buf,
565 size_t count, loff_t *ppos) {
566
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700567 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700568
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700569 int pos = 0;
570 int cnt = 0;
571 char *buf;
572 int bufsz = 24 * 64; /* 24 items * 64 char per item */
573 ssize_t ret;
574
575 buf = kzalloc(bufsz, GFP_KERNEL);
576 if (!buf) {
577 IWL_ERR(priv, "Can not allocate Buffer\n");
578 return -ENOMEM;
579 }
580
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700581 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700582 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700583 pos += scnprintf(buf + pos, bufsz - pos,
584 "\tRx handler[%36s]:\t\t %u\n",
585 get_cmd_string(cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700586 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700587 }
588
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700589 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
590 kfree(buf);
591 return ret;
592}
593
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700594static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700595 const char __user *user_buf,
596 size_t count, loff_t *ppos)
597{
598 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700599
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700600 char buf[8];
601 int buf_size;
602 u32 reset_flag;
603
604 memset(buf, 0, sizeof(buf));
605 buf_size = min(count, sizeof(buf) - 1);
606 if (copy_from_user(buf, user_buf, buf_size))
607 return -EFAULT;
608 if (sscanf(buf, "%x", &reset_flag) != 1)
609 return -EFAULT;
610 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700611 memset(&priv->rx_handlers_stats[0], 0,
612 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700613
614 return count;
615}
616
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700617static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
618 size_t count, loff_t *ppos)
619{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700620 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200621 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700622 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200623 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700624 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700625
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200626 for_each_context(priv, ctx) {
627 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
628 ctx->ctxid);
629 for (i = 0; i < AC_NUM; i++) {
630 pos += scnprintf(buf + pos, bufsz - pos,
631 "\tcw_min\tcw_max\taifsn\ttxop\n");
632 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700633 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200634 ctx->qos_data.def_qos_parm.ac[i].cw_min,
635 ctx->qos_data.def_qos_parm.ac[i].cw_max,
636 ctx->qos_data.def_qos_parm.ac[i].aifsn,
637 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
638 }
639 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700640 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800641 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700642}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700643
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700644static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
645 char __user *user_buf,
646 size_t count, loff_t *ppos)
647{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700648 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700649 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700650 struct iwl_tt_restriction *restriction;
651 char buf[100];
652 int pos = 0;
653 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700654
655 pos += scnprintf(buf + pos, bufsz - pos,
656 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700657 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700658 pos += scnprintf(buf + pos, bufsz - pos,
659 "Thermal Throttling State: %d\n",
660 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700661 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700662 restriction = tt->restriction + tt->state;
663 pos += scnprintf(buf + pos, bufsz - pos,
664 "Tx mode: %d\n",
665 restriction->tx_stream);
666 pos += scnprintf(buf + pos, bufsz - pos,
667 "Rx mode: %d\n",
668 restriction->rx_stream);
669 pos += scnprintf(buf + pos, bufsz - pos,
670 "HT mode: %d\n",
671 restriction->is_ht);
672 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800673 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700674}
675
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700676static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
677 const char __user *user_buf,
678 size_t count, loff_t *ppos)
679{
680 struct iwl_priv *priv = file->private_data;
681 char buf[8];
682 int buf_size;
683 int ht40;
684
685 memset(buf, 0, sizeof(buf));
686 buf_size = min(count, sizeof(buf) - 1);
687 if (copy_from_user(buf, user_buf, buf_size))
688 return -EFAULT;
689 if (sscanf(buf, "%d", &ht40) != 1)
690 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200691 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700692 priv->disable_ht40 = ht40 ? true : false;
693 else {
694 IWL_ERR(priv, "Sta associated with AP - "
695 "Change to 40MHz channel support is not allowed\n");
696 return -EINVAL;
697 }
698
699 return count;
700}
701
702static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
703 char __user *user_buf,
704 size_t count, loff_t *ppos)
705{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700706 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700707 char buf[100];
708 int pos = 0;
709 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700710
711 pos += scnprintf(buf + pos, bufsz - pos,
712 "11n 40MHz Mode: %s\n",
713 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800714 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700715}
716
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700717static ssize_t iwl_dbgfs_temperature_read(struct file *file,
718 char __user *user_buf,
719 size_t count, loff_t *ppos)
720{
721 struct iwl_priv *priv = file->private_data;
722 char buf[8];
723 int pos = 0;
724 const size_t bufsz = sizeof(buf);
725
726 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
727 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
728}
729
730
Johannes Berge312c242009-08-07 15:41:51 -0700731static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
732 const char __user *user_buf,
733 size_t count, loff_t *ppos)
734{
735 struct iwl_priv *priv = file->private_data;
736 char buf[8];
737 int buf_size;
738 int value;
739
740 memset(buf, 0, sizeof(buf));
741 buf_size = min(count, sizeof(buf) - 1);
742 if (copy_from_user(buf, user_buf, buf_size))
743 return -EFAULT;
744
745 if (sscanf(buf, "%d", &value) != 1)
746 return -EINVAL;
747
748 /*
749 * Our users expect 0 to be "CAM", but 0 isn't actually
750 * valid here. However, let's not confuse them and present
751 * IWL_POWER_INDEX_1 as "1", not "0".
752 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700753 if (value == 0)
754 return -EINVAL;
755 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700756 value -= 1;
757
758 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
759 return -EINVAL;
760
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700761 if (!iwl_is_ready_rf(priv->shrd))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700762 return -EAGAIN;
763
Johannes Berge312c242009-08-07 15:41:51 -0700764 priv->power_data.debug_sleep_level_override = value;
765
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700766 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700767 iwl_power_update_mode(priv, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700768 mutex_unlock(&priv->shrd->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700769
770 return count;
771}
772
773static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
774 char __user *user_buf,
775 size_t count, loff_t *ppos)
776{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700777 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700778 char buf[10];
779 int pos, value;
780 const size_t bufsz = sizeof(buf);
781
782 /* see the write function */
783 value = priv->power_data.debug_sleep_level_override;
784 if (value >= 0)
785 value += 1;
786
787 pos = scnprintf(buf, bufsz, "%d\n", value);
788 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
789}
790
791static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
792 char __user *user_buf,
793 size_t count, loff_t *ppos)
794{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700795 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700796 char buf[200];
797 int pos = 0, i;
798 const size_t bufsz = sizeof(buf);
799 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
800
801 pos += scnprintf(buf + pos, bufsz - pos,
802 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
803 pos += scnprintf(buf + pos, bufsz - pos,
804 "RX/TX timeout: %d/%d usec\n",
805 le32_to_cpu(cmd->rx_data_timeout),
806 le32_to_cpu(cmd->tx_data_timeout));
807 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
808 pos += scnprintf(buf + pos, bufsz - pos,
809 "sleep_interval[%d]: %d\n", i,
810 le32_to_cpu(cmd->sleep_interval[i]));
811
812 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
813}
814
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700815DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700816DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700817DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700818DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800819DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700820DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700821DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700822DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700823DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700824DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700825DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700826DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
827DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700828
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -0700829static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
830 char __user *user_buf,
831 size_t count, loff_t *ppos)
832{
833 struct iwl_priv *priv = file->private_data;
834 int pos = 0, ofs = 0;
835 int cnt = 0, entry;
836
837 char *buf;
838 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
839 (hw_params(priv).max_txq_num * 32 * 8) + 400;
840 const u8 *ptr;
841 ssize_t ret;
842
843 buf = kzalloc(bufsz, GFP_KERNEL);
844 if (!buf) {
845 IWL_ERR(priv, "Can not allocate buffer\n");
846 return -ENOMEM;
847 }
848 if (priv->tx_traffic &&
849 (iwl_get_debug_level(priv->shrd) & IWL_DL_TX)) {
850 ptr = priv->tx_traffic;
851 pos += scnprintf(buf + pos, bufsz - pos,
852 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
853 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
854 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
855 entry++, ofs += 16) {
856 pos += scnprintf(buf + pos, bufsz - pos,
857 "0x%.4x ", ofs);
858 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
859 buf + pos, bufsz - pos, 0);
860 pos += strlen(buf + pos);
861 if (bufsz - pos > 0)
862 buf[pos++] = '\n';
863 }
864 }
865 }
866
867 if (priv->rx_traffic &&
868 (iwl_get_debug_level(priv->shrd) & IWL_DL_RX)) {
869 ptr = priv->rx_traffic;
870 pos += scnprintf(buf + pos, bufsz - pos,
871 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
872 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
873 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
874 entry++, ofs += 16) {
875 pos += scnprintf(buf + pos, bufsz - pos,
876 "0x%.4x ", ofs);
877 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
878 buf + pos, bufsz - pos, 0);
879 pos += strlen(buf + pos);
880 if (bufsz - pos > 0)
881 buf[pos++] = '\n';
882 }
883 }
884 }
885
886 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
887 kfree(buf);
888 return ret;
889}
890
891static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
892 const char __user *user_buf,
893 size_t count, loff_t *ppos)
894{
895 struct iwl_priv *priv = file->private_data;
896 char buf[8];
897 int buf_size;
898 int traffic_log;
899
900 memset(buf, 0, sizeof(buf));
901 buf_size = min(count, sizeof(buf) - 1);
902 if (copy_from_user(buf, user_buf, buf_size))
903 return -EFAULT;
904 if (sscanf(buf, "%d", &traffic_log) != 1)
905 return -EFAULT;
906 if (traffic_log == 0)
907 iwl_reset_traffic_log(priv);
908
909 return count;
910}
911
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700912static const char *fmt_value = " %-30s %10u\n";
913static const char *fmt_hex = " %-30s 0x%02X\n";
914static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
915static const char *fmt_header =
916 "%-32s current cumulative delta max\n";
917
918static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
919{
920 int p = 0;
921 u32 flag;
922
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800923 lockdep_assert_held(&priv->statistics.lock);
924
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700925 flag = le32_to_cpu(priv->statistics.flag);
926
927 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
928 if (flag & UCODE_STATISTICS_CLEAR_MSK)
929 p += scnprintf(buf + p, bufsz - p,
930 "\tStatistics have been cleared\n");
931 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
932 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
933 ? "2.4 GHz" : "5.2 GHz");
934 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
935 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
936 ? "enabled" : "disabled");
937
938 return p;
939}
940
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700941static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
942 char __user *user_buf,
943 size_t count, loff_t *ppos)
944{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700945 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700946 int pos = 0;
947 char *buf;
948 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
949 sizeof(struct statistics_rx_non_phy) * 40 +
950 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
951 ssize_t ret;
952 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
953 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
954 struct statistics_rx_non_phy *general, *accum_general;
955 struct statistics_rx_non_phy *delta_general, *max_general;
956 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
957
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700958 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700959 return -EAGAIN;
960
961 buf = kzalloc(bufsz, GFP_KERNEL);
962 if (!buf) {
963 IWL_ERR(priv, "Can not allocate Buffer\n");
964 return -ENOMEM;
965 }
966
967 /*
968 * the statistic information display here is based on
969 * the last statistics notification from uCode
970 * might not reflect the current uCode activity
971 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -0800972 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700973 ofdm = &priv->statistics.rx_ofdm;
974 cck = &priv->statistics.rx_cck;
975 general = &priv->statistics.rx_non_phy;
976 ht = &priv->statistics.rx_ofdm_ht;
977 accum_ofdm = &priv->accum_stats.rx_ofdm;
978 accum_cck = &priv->accum_stats.rx_cck;
979 accum_general = &priv->accum_stats.rx_non_phy;
980 accum_ht = &priv->accum_stats.rx_ofdm_ht;
981 delta_ofdm = &priv->delta_stats.rx_ofdm;
982 delta_cck = &priv->delta_stats.rx_cck;
983 delta_general = &priv->delta_stats.rx_non_phy;
984 delta_ht = &priv->delta_stats.rx_ofdm_ht;
985 max_ofdm = &priv->max_delta_stats.rx_ofdm;
986 max_cck = &priv->max_delta_stats.rx_cck;
987 max_general = &priv->max_delta_stats.rx_non_phy;
988 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
989
990 pos += iwl_statistics_flag(priv, buf, bufsz);
991 pos += scnprintf(buf + pos, bufsz - pos,
992 fmt_header, "Statistics_Rx - OFDM:");
993 pos += scnprintf(buf + pos, bufsz - pos,
994 fmt_table, "ina_cnt:",
995 le32_to_cpu(ofdm->ina_cnt),
996 accum_ofdm->ina_cnt,
997 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
998 pos += scnprintf(buf + pos, bufsz - pos,
999 fmt_table, "fina_cnt:",
1000 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
1001 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
1002 pos += scnprintf(buf + pos, bufsz - pos,
1003 fmt_table, "plcp_err:",
1004 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
1005 delta_ofdm->plcp_err, max_ofdm->plcp_err);
1006 pos += scnprintf(buf + pos, bufsz - pos,
1007 fmt_table, "crc32_err:",
1008 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
1009 delta_ofdm->crc32_err, max_ofdm->crc32_err);
1010 pos += scnprintf(buf + pos, bufsz - pos,
1011 fmt_table, "overrun_err:",
1012 le32_to_cpu(ofdm->overrun_err),
1013 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
1014 max_ofdm->overrun_err);
1015 pos += scnprintf(buf + pos, bufsz - pos,
1016 fmt_table, "early_overrun_err:",
1017 le32_to_cpu(ofdm->early_overrun_err),
1018 accum_ofdm->early_overrun_err,
1019 delta_ofdm->early_overrun_err,
1020 max_ofdm->early_overrun_err);
1021 pos += scnprintf(buf + pos, bufsz - pos,
1022 fmt_table, "crc32_good:",
1023 le32_to_cpu(ofdm->crc32_good),
1024 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
1025 max_ofdm->crc32_good);
1026 pos += scnprintf(buf + pos, bufsz - pos,
1027 fmt_table, "false_alarm_cnt:",
1028 le32_to_cpu(ofdm->false_alarm_cnt),
1029 accum_ofdm->false_alarm_cnt,
1030 delta_ofdm->false_alarm_cnt,
1031 max_ofdm->false_alarm_cnt);
1032 pos += scnprintf(buf + pos, bufsz - pos,
1033 fmt_table, "fina_sync_err_cnt:",
1034 le32_to_cpu(ofdm->fina_sync_err_cnt),
1035 accum_ofdm->fina_sync_err_cnt,
1036 delta_ofdm->fina_sync_err_cnt,
1037 max_ofdm->fina_sync_err_cnt);
1038 pos += scnprintf(buf + pos, bufsz - pos,
1039 fmt_table, "sfd_timeout:",
1040 le32_to_cpu(ofdm->sfd_timeout),
1041 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
1042 max_ofdm->sfd_timeout);
1043 pos += scnprintf(buf + pos, bufsz - pos,
1044 fmt_table, "fina_timeout:",
1045 le32_to_cpu(ofdm->fina_timeout),
1046 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
1047 max_ofdm->fina_timeout);
1048 pos += scnprintf(buf + pos, bufsz - pos,
1049 fmt_table, "unresponded_rts:",
1050 le32_to_cpu(ofdm->unresponded_rts),
1051 accum_ofdm->unresponded_rts,
1052 delta_ofdm->unresponded_rts,
1053 max_ofdm->unresponded_rts);
1054 pos += scnprintf(buf + pos, bufsz - pos,
1055 fmt_table, "rxe_frame_lmt_ovrun:",
1056 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
1057 accum_ofdm->rxe_frame_limit_overrun,
1058 delta_ofdm->rxe_frame_limit_overrun,
1059 max_ofdm->rxe_frame_limit_overrun);
1060 pos += scnprintf(buf + pos, bufsz - pos,
1061 fmt_table, "sent_ack_cnt:",
1062 le32_to_cpu(ofdm->sent_ack_cnt),
1063 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
1064 max_ofdm->sent_ack_cnt);
1065 pos += scnprintf(buf + pos, bufsz - pos,
1066 fmt_table, "sent_cts_cnt:",
1067 le32_to_cpu(ofdm->sent_cts_cnt),
1068 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
1069 max_ofdm->sent_cts_cnt);
1070 pos += scnprintf(buf + pos, bufsz - pos,
1071 fmt_table, "sent_ba_rsp_cnt:",
1072 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
1073 accum_ofdm->sent_ba_rsp_cnt,
1074 delta_ofdm->sent_ba_rsp_cnt,
1075 max_ofdm->sent_ba_rsp_cnt);
1076 pos += scnprintf(buf + pos, bufsz - pos,
1077 fmt_table, "dsp_self_kill:",
1078 le32_to_cpu(ofdm->dsp_self_kill),
1079 accum_ofdm->dsp_self_kill,
1080 delta_ofdm->dsp_self_kill,
1081 max_ofdm->dsp_self_kill);
1082 pos += scnprintf(buf + pos, bufsz - pos,
1083 fmt_table, "mh_format_err:",
1084 le32_to_cpu(ofdm->mh_format_err),
1085 accum_ofdm->mh_format_err,
1086 delta_ofdm->mh_format_err,
1087 max_ofdm->mh_format_err);
1088 pos += scnprintf(buf + pos, bufsz - pos,
1089 fmt_table, "re_acq_main_rssi_sum:",
1090 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
1091 accum_ofdm->re_acq_main_rssi_sum,
1092 delta_ofdm->re_acq_main_rssi_sum,
1093 max_ofdm->re_acq_main_rssi_sum);
1094
1095 pos += scnprintf(buf + pos, bufsz - pos,
1096 fmt_header, "Statistics_Rx - CCK:");
1097 pos += scnprintf(buf + pos, bufsz - pos,
1098 fmt_table, "ina_cnt:",
1099 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
1100 delta_cck->ina_cnt, max_cck->ina_cnt);
1101 pos += scnprintf(buf + pos, bufsz - pos,
1102 fmt_table, "fina_cnt:",
1103 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
1104 delta_cck->fina_cnt, max_cck->fina_cnt);
1105 pos += scnprintf(buf + pos, bufsz - pos,
1106 fmt_table, "plcp_err:",
1107 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
1108 delta_cck->plcp_err, max_cck->plcp_err);
1109 pos += scnprintf(buf + pos, bufsz - pos,
1110 fmt_table, "crc32_err:",
1111 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
1112 delta_cck->crc32_err, max_cck->crc32_err);
1113 pos += scnprintf(buf + pos, bufsz - pos,
1114 fmt_table, "overrun_err:",
1115 le32_to_cpu(cck->overrun_err),
1116 accum_cck->overrun_err, delta_cck->overrun_err,
1117 max_cck->overrun_err);
1118 pos += scnprintf(buf + pos, bufsz - pos,
1119 fmt_table, "early_overrun_err:",
1120 le32_to_cpu(cck->early_overrun_err),
1121 accum_cck->early_overrun_err,
1122 delta_cck->early_overrun_err,
1123 max_cck->early_overrun_err);
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 fmt_table, "crc32_good:",
1126 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
1127 delta_cck->crc32_good, max_cck->crc32_good);
1128 pos += scnprintf(buf + pos, bufsz - pos,
1129 fmt_table, "false_alarm_cnt:",
1130 le32_to_cpu(cck->false_alarm_cnt),
1131 accum_cck->false_alarm_cnt,
1132 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
1133 pos += scnprintf(buf + pos, bufsz - pos,
1134 fmt_table, "fina_sync_err_cnt:",
1135 le32_to_cpu(cck->fina_sync_err_cnt),
1136 accum_cck->fina_sync_err_cnt,
1137 delta_cck->fina_sync_err_cnt,
1138 max_cck->fina_sync_err_cnt);
1139 pos += scnprintf(buf + pos, bufsz - pos,
1140 fmt_table, "sfd_timeout:",
1141 le32_to_cpu(cck->sfd_timeout),
1142 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
1143 max_cck->sfd_timeout);
1144 pos += scnprintf(buf + pos, bufsz - pos,
1145 fmt_table, "fina_timeout:",
1146 le32_to_cpu(cck->fina_timeout),
1147 accum_cck->fina_timeout, delta_cck->fina_timeout,
1148 max_cck->fina_timeout);
1149 pos += scnprintf(buf + pos, bufsz - pos,
1150 fmt_table, "unresponded_rts:",
1151 le32_to_cpu(cck->unresponded_rts),
1152 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
1153 max_cck->unresponded_rts);
1154 pos += scnprintf(buf + pos, bufsz - pos,
1155 fmt_table, "rxe_frame_lmt_ovrun:",
1156 le32_to_cpu(cck->rxe_frame_limit_overrun),
1157 accum_cck->rxe_frame_limit_overrun,
1158 delta_cck->rxe_frame_limit_overrun,
1159 max_cck->rxe_frame_limit_overrun);
1160 pos += scnprintf(buf + pos, bufsz - pos,
1161 fmt_table, "sent_ack_cnt:",
1162 le32_to_cpu(cck->sent_ack_cnt),
1163 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
1164 max_cck->sent_ack_cnt);
1165 pos += scnprintf(buf + pos, bufsz - pos,
1166 fmt_table, "sent_cts_cnt:",
1167 le32_to_cpu(cck->sent_cts_cnt),
1168 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
1169 max_cck->sent_cts_cnt);
1170 pos += scnprintf(buf + pos, bufsz - pos,
1171 fmt_table, "sent_ba_rsp_cnt:",
1172 le32_to_cpu(cck->sent_ba_rsp_cnt),
1173 accum_cck->sent_ba_rsp_cnt,
1174 delta_cck->sent_ba_rsp_cnt,
1175 max_cck->sent_ba_rsp_cnt);
1176 pos += scnprintf(buf + pos, bufsz - pos,
1177 fmt_table, "dsp_self_kill:",
1178 le32_to_cpu(cck->dsp_self_kill),
1179 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
1180 max_cck->dsp_self_kill);
1181 pos += scnprintf(buf + pos, bufsz - pos,
1182 fmt_table, "mh_format_err:",
1183 le32_to_cpu(cck->mh_format_err),
1184 accum_cck->mh_format_err, delta_cck->mh_format_err,
1185 max_cck->mh_format_err);
1186 pos += scnprintf(buf + pos, bufsz - pos,
1187 fmt_table, "re_acq_main_rssi_sum:",
1188 le32_to_cpu(cck->re_acq_main_rssi_sum),
1189 accum_cck->re_acq_main_rssi_sum,
1190 delta_cck->re_acq_main_rssi_sum,
1191 max_cck->re_acq_main_rssi_sum);
1192
1193 pos += scnprintf(buf + pos, bufsz - pos,
1194 fmt_header, "Statistics_Rx - GENERAL:");
1195 pos += scnprintf(buf + pos, bufsz - pos,
1196 fmt_table, "bogus_cts:",
1197 le32_to_cpu(general->bogus_cts),
1198 accum_general->bogus_cts, delta_general->bogus_cts,
1199 max_general->bogus_cts);
1200 pos += scnprintf(buf + pos, bufsz - pos,
1201 fmt_table, "bogus_ack:",
1202 le32_to_cpu(general->bogus_ack),
1203 accum_general->bogus_ack, delta_general->bogus_ack,
1204 max_general->bogus_ack);
1205 pos += scnprintf(buf + pos, bufsz - pos,
1206 fmt_table, "non_bssid_frames:",
1207 le32_to_cpu(general->non_bssid_frames),
1208 accum_general->non_bssid_frames,
1209 delta_general->non_bssid_frames,
1210 max_general->non_bssid_frames);
1211 pos += scnprintf(buf + pos, bufsz - pos,
1212 fmt_table, "filtered_frames:",
1213 le32_to_cpu(general->filtered_frames),
1214 accum_general->filtered_frames,
1215 delta_general->filtered_frames,
1216 max_general->filtered_frames);
1217 pos += scnprintf(buf + pos, bufsz - pos,
1218 fmt_table, "non_channel_beacons:",
1219 le32_to_cpu(general->non_channel_beacons),
1220 accum_general->non_channel_beacons,
1221 delta_general->non_channel_beacons,
1222 max_general->non_channel_beacons);
1223 pos += scnprintf(buf + pos, bufsz - pos,
1224 fmt_table, "channel_beacons:",
1225 le32_to_cpu(general->channel_beacons),
1226 accum_general->channel_beacons,
1227 delta_general->channel_beacons,
1228 max_general->channel_beacons);
1229 pos += scnprintf(buf + pos, bufsz - pos,
1230 fmt_table, "num_missed_bcon:",
1231 le32_to_cpu(general->num_missed_bcon),
1232 accum_general->num_missed_bcon,
1233 delta_general->num_missed_bcon,
1234 max_general->num_missed_bcon);
1235 pos += scnprintf(buf + pos, bufsz - pos,
1236 fmt_table, "adc_rx_saturation_time:",
1237 le32_to_cpu(general->adc_rx_saturation_time),
1238 accum_general->adc_rx_saturation_time,
1239 delta_general->adc_rx_saturation_time,
1240 max_general->adc_rx_saturation_time);
1241 pos += scnprintf(buf + pos, bufsz - pos,
1242 fmt_table, "ina_detect_search_tm:",
1243 le32_to_cpu(general->ina_detection_search_time),
1244 accum_general->ina_detection_search_time,
1245 delta_general->ina_detection_search_time,
1246 max_general->ina_detection_search_time);
1247 pos += scnprintf(buf + pos, bufsz - pos,
1248 fmt_table, "beacon_silence_rssi_a:",
1249 le32_to_cpu(general->beacon_silence_rssi_a),
1250 accum_general->beacon_silence_rssi_a,
1251 delta_general->beacon_silence_rssi_a,
1252 max_general->beacon_silence_rssi_a);
1253 pos += scnprintf(buf + pos, bufsz - pos,
1254 fmt_table, "beacon_silence_rssi_b:",
1255 le32_to_cpu(general->beacon_silence_rssi_b),
1256 accum_general->beacon_silence_rssi_b,
1257 delta_general->beacon_silence_rssi_b,
1258 max_general->beacon_silence_rssi_b);
1259 pos += scnprintf(buf + pos, bufsz - pos,
1260 fmt_table, "beacon_silence_rssi_c:",
1261 le32_to_cpu(general->beacon_silence_rssi_c),
1262 accum_general->beacon_silence_rssi_c,
1263 delta_general->beacon_silence_rssi_c,
1264 max_general->beacon_silence_rssi_c);
1265 pos += scnprintf(buf + pos, bufsz - pos,
1266 fmt_table, "interference_data_flag:",
1267 le32_to_cpu(general->interference_data_flag),
1268 accum_general->interference_data_flag,
1269 delta_general->interference_data_flag,
1270 max_general->interference_data_flag);
1271 pos += scnprintf(buf + pos, bufsz - pos,
1272 fmt_table, "channel_load:",
1273 le32_to_cpu(general->channel_load),
1274 accum_general->channel_load,
1275 delta_general->channel_load,
1276 max_general->channel_load);
1277 pos += scnprintf(buf + pos, bufsz - pos,
1278 fmt_table, "dsp_false_alarms:",
1279 le32_to_cpu(general->dsp_false_alarms),
1280 accum_general->dsp_false_alarms,
1281 delta_general->dsp_false_alarms,
1282 max_general->dsp_false_alarms);
1283 pos += scnprintf(buf + pos, bufsz - pos,
1284 fmt_table, "beacon_rssi_a:",
1285 le32_to_cpu(general->beacon_rssi_a),
1286 accum_general->beacon_rssi_a,
1287 delta_general->beacon_rssi_a,
1288 max_general->beacon_rssi_a);
1289 pos += scnprintf(buf + pos, bufsz - pos,
1290 fmt_table, "beacon_rssi_b:",
1291 le32_to_cpu(general->beacon_rssi_b),
1292 accum_general->beacon_rssi_b,
1293 delta_general->beacon_rssi_b,
1294 max_general->beacon_rssi_b);
1295 pos += scnprintf(buf + pos, bufsz - pos,
1296 fmt_table, "beacon_rssi_c:",
1297 le32_to_cpu(general->beacon_rssi_c),
1298 accum_general->beacon_rssi_c,
1299 delta_general->beacon_rssi_c,
1300 max_general->beacon_rssi_c);
1301 pos += scnprintf(buf + pos, bufsz - pos,
1302 fmt_table, "beacon_energy_a:",
1303 le32_to_cpu(general->beacon_energy_a),
1304 accum_general->beacon_energy_a,
1305 delta_general->beacon_energy_a,
1306 max_general->beacon_energy_a);
1307 pos += scnprintf(buf + pos, bufsz - pos,
1308 fmt_table, "beacon_energy_b:",
1309 le32_to_cpu(general->beacon_energy_b),
1310 accum_general->beacon_energy_b,
1311 delta_general->beacon_energy_b,
1312 max_general->beacon_energy_b);
1313 pos += scnprintf(buf + pos, bufsz - pos,
1314 fmt_table, "beacon_energy_c:",
1315 le32_to_cpu(general->beacon_energy_c),
1316 accum_general->beacon_energy_c,
1317 delta_general->beacon_energy_c,
1318 max_general->beacon_energy_c);
1319
1320 pos += scnprintf(buf + pos, bufsz - pos,
1321 fmt_header, "Statistics_Rx - OFDM_HT:");
1322 pos += scnprintf(buf + pos, bufsz - pos,
1323 fmt_table, "plcp_err:",
1324 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1325 delta_ht->plcp_err, max_ht->plcp_err);
1326 pos += scnprintf(buf + pos, bufsz - pos,
1327 fmt_table, "overrun_err:",
1328 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1329 delta_ht->overrun_err, max_ht->overrun_err);
1330 pos += scnprintf(buf + pos, bufsz - pos,
1331 fmt_table, "early_overrun_err:",
1332 le32_to_cpu(ht->early_overrun_err),
1333 accum_ht->early_overrun_err,
1334 delta_ht->early_overrun_err,
1335 max_ht->early_overrun_err);
1336 pos += scnprintf(buf + pos, bufsz - pos,
1337 fmt_table, "crc32_good:",
1338 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1339 delta_ht->crc32_good, max_ht->crc32_good);
1340 pos += scnprintf(buf + pos, bufsz - pos,
1341 fmt_table, "crc32_err:",
1342 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1343 delta_ht->crc32_err, max_ht->crc32_err);
1344 pos += scnprintf(buf + pos, bufsz - pos,
1345 fmt_table, "mh_format_err:",
1346 le32_to_cpu(ht->mh_format_err),
1347 accum_ht->mh_format_err,
1348 delta_ht->mh_format_err, max_ht->mh_format_err);
1349 pos += scnprintf(buf + pos, bufsz - pos,
1350 fmt_table, "agg_crc32_good:",
1351 le32_to_cpu(ht->agg_crc32_good),
1352 accum_ht->agg_crc32_good,
1353 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1354 pos += scnprintf(buf + pos, bufsz - pos,
1355 fmt_table, "agg_mpdu_cnt:",
1356 le32_to_cpu(ht->agg_mpdu_cnt),
1357 accum_ht->agg_mpdu_cnt,
1358 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1359 pos += scnprintf(buf + pos, bufsz - pos,
1360 fmt_table, "agg_cnt:",
1361 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1362 delta_ht->agg_cnt, max_ht->agg_cnt);
1363 pos += scnprintf(buf + pos, bufsz - pos,
1364 fmt_table, "unsupport_mcs:",
1365 le32_to_cpu(ht->unsupport_mcs),
1366 accum_ht->unsupport_mcs,
1367 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1368
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001369 spin_unlock_bh(&priv->statistics.lock);
1370
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001371 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1372 kfree(buf);
1373 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001374}
1375
1376static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1377 char __user *user_buf,
1378 size_t count, loff_t *ppos)
1379{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001380 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001381 int pos = 0;
1382 char *buf;
1383 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1384 ssize_t ret;
1385 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1386
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001387 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001388 return -EAGAIN;
1389
1390 buf = kzalloc(bufsz, GFP_KERNEL);
1391 if (!buf) {
1392 IWL_ERR(priv, "Can not allocate Buffer\n");
1393 return -ENOMEM;
1394 }
1395
1396 /* the statistic information display here is based on
1397 * the last statistics notification from uCode
1398 * might not reflect the current uCode activity
1399 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001400 spin_lock_bh(&priv->statistics.lock);
1401
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001402 tx = &priv->statistics.tx;
1403 accum_tx = &priv->accum_stats.tx;
1404 delta_tx = &priv->delta_stats.tx;
1405 max_tx = &priv->max_delta_stats.tx;
1406
1407 pos += iwl_statistics_flag(priv, buf, bufsz);
1408 pos += scnprintf(buf + pos, bufsz - pos,
1409 fmt_header, "Statistics_Tx:");
1410 pos += scnprintf(buf + pos, bufsz - pos,
1411 fmt_table, "preamble:",
1412 le32_to_cpu(tx->preamble_cnt),
1413 accum_tx->preamble_cnt,
1414 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1415 pos += scnprintf(buf + pos, bufsz - pos,
1416 fmt_table, "rx_detected_cnt:",
1417 le32_to_cpu(tx->rx_detected_cnt),
1418 accum_tx->rx_detected_cnt,
1419 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1420 pos += scnprintf(buf + pos, bufsz - pos,
1421 fmt_table, "bt_prio_defer_cnt:",
1422 le32_to_cpu(tx->bt_prio_defer_cnt),
1423 accum_tx->bt_prio_defer_cnt,
1424 delta_tx->bt_prio_defer_cnt,
1425 max_tx->bt_prio_defer_cnt);
1426 pos += scnprintf(buf + pos, bufsz - pos,
1427 fmt_table, "bt_prio_kill_cnt:",
1428 le32_to_cpu(tx->bt_prio_kill_cnt),
1429 accum_tx->bt_prio_kill_cnt,
1430 delta_tx->bt_prio_kill_cnt,
1431 max_tx->bt_prio_kill_cnt);
1432 pos += scnprintf(buf + pos, bufsz - pos,
1433 fmt_table, "few_bytes_cnt:",
1434 le32_to_cpu(tx->few_bytes_cnt),
1435 accum_tx->few_bytes_cnt,
1436 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1437 pos += scnprintf(buf + pos, bufsz - pos,
1438 fmt_table, "cts_timeout:",
1439 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1440 delta_tx->cts_timeout, max_tx->cts_timeout);
1441 pos += scnprintf(buf + pos, bufsz - pos,
1442 fmt_table, "ack_timeout:",
1443 le32_to_cpu(tx->ack_timeout),
1444 accum_tx->ack_timeout,
1445 delta_tx->ack_timeout, max_tx->ack_timeout);
1446 pos += scnprintf(buf + pos, bufsz - pos,
1447 fmt_table, "expected_ack_cnt:",
1448 le32_to_cpu(tx->expected_ack_cnt),
1449 accum_tx->expected_ack_cnt,
1450 delta_tx->expected_ack_cnt,
1451 max_tx->expected_ack_cnt);
1452 pos += scnprintf(buf + pos, bufsz - pos,
1453 fmt_table, "actual_ack_cnt:",
1454 le32_to_cpu(tx->actual_ack_cnt),
1455 accum_tx->actual_ack_cnt,
1456 delta_tx->actual_ack_cnt,
1457 max_tx->actual_ack_cnt);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 fmt_table, "dump_msdu_cnt:",
1460 le32_to_cpu(tx->dump_msdu_cnt),
1461 accum_tx->dump_msdu_cnt,
1462 delta_tx->dump_msdu_cnt,
1463 max_tx->dump_msdu_cnt);
1464 pos += scnprintf(buf + pos, bufsz - pos,
1465 fmt_table, "abort_nxt_frame_mismatch:",
1466 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1467 accum_tx->burst_abort_next_frame_mismatch_cnt,
1468 delta_tx->burst_abort_next_frame_mismatch_cnt,
1469 max_tx->burst_abort_next_frame_mismatch_cnt);
1470 pos += scnprintf(buf + pos, bufsz - pos,
1471 fmt_table, "abort_missing_nxt_frame:",
1472 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1473 accum_tx->burst_abort_missing_next_frame_cnt,
1474 delta_tx->burst_abort_missing_next_frame_cnt,
1475 max_tx->burst_abort_missing_next_frame_cnt);
1476 pos += scnprintf(buf + pos, bufsz - pos,
1477 fmt_table, "cts_timeout_collision:",
1478 le32_to_cpu(tx->cts_timeout_collision),
1479 accum_tx->cts_timeout_collision,
1480 delta_tx->cts_timeout_collision,
1481 max_tx->cts_timeout_collision);
1482 pos += scnprintf(buf + pos, bufsz - pos,
1483 fmt_table, "ack_ba_timeout_collision:",
1484 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1485 accum_tx->ack_or_ba_timeout_collision,
1486 delta_tx->ack_or_ba_timeout_collision,
1487 max_tx->ack_or_ba_timeout_collision);
1488 pos += scnprintf(buf + pos, bufsz - pos,
1489 fmt_table, "agg ba_timeout:",
1490 le32_to_cpu(tx->agg.ba_timeout),
1491 accum_tx->agg.ba_timeout,
1492 delta_tx->agg.ba_timeout,
1493 max_tx->agg.ba_timeout);
1494 pos += scnprintf(buf + pos, bufsz - pos,
1495 fmt_table, "agg ba_resched_frames:",
1496 le32_to_cpu(tx->agg.ba_reschedule_frames),
1497 accum_tx->agg.ba_reschedule_frames,
1498 delta_tx->agg.ba_reschedule_frames,
1499 max_tx->agg.ba_reschedule_frames);
1500 pos += scnprintf(buf + pos, bufsz - pos,
1501 fmt_table, "agg scd_query_agg_frame:",
1502 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1503 accum_tx->agg.scd_query_agg_frame_cnt,
1504 delta_tx->agg.scd_query_agg_frame_cnt,
1505 max_tx->agg.scd_query_agg_frame_cnt);
1506 pos += scnprintf(buf + pos, bufsz - pos,
1507 fmt_table, "agg scd_query_no_agg:",
1508 le32_to_cpu(tx->agg.scd_query_no_agg),
1509 accum_tx->agg.scd_query_no_agg,
1510 delta_tx->agg.scd_query_no_agg,
1511 max_tx->agg.scd_query_no_agg);
1512 pos += scnprintf(buf + pos, bufsz - pos,
1513 fmt_table, "agg scd_query_agg:",
1514 le32_to_cpu(tx->agg.scd_query_agg),
1515 accum_tx->agg.scd_query_agg,
1516 delta_tx->agg.scd_query_agg,
1517 max_tx->agg.scd_query_agg);
1518 pos += scnprintf(buf + pos, bufsz - pos,
1519 fmt_table, "agg scd_query_mismatch:",
1520 le32_to_cpu(tx->agg.scd_query_mismatch),
1521 accum_tx->agg.scd_query_mismatch,
1522 delta_tx->agg.scd_query_mismatch,
1523 max_tx->agg.scd_query_mismatch);
1524 pos += scnprintf(buf + pos, bufsz - pos,
1525 fmt_table, "agg frame_not_ready:",
1526 le32_to_cpu(tx->agg.frame_not_ready),
1527 accum_tx->agg.frame_not_ready,
1528 delta_tx->agg.frame_not_ready,
1529 max_tx->agg.frame_not_ready);
1530 pos += scnprintf(buf + pos, bufsz - pos,
1531 fmt_table, "agg underrun:",
1532 le32_to_cpu(tx->agg.underrun),
1533 accum_tx->agg.underrun,
1534 delta_tx->agg.underrun, max_tx->agg.underrun);
1535 pos += scnprintf(buf + pos, bufsz - pos,
1536 fmt_table, "agg bt_prio_kill:",
1537 le32_to_cpu(tx->agg.bt_prio_kill),
1538 accum_tx->agg.bt_prio_kill,
1539 delta_tx->agg.bt_prio_kill,
1540 max_tx->agg.bt_prio_kill);
1541 pos += scnprintf(buf + pos, bufsz - pos,
1542 fmt_table, "agg rx_ba_rsp_cnt:",
1543 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1544 accum_tx->agg.rx_ba_rsp_cnt,
1545 delta_tx->agg.rx_ba_rsp_cnt,
1546 max_tx->agg.rx_ba_rsp_cnt);
1547
1548 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1549 pos += scnprintf(buf + pos, bufsz - pos,
1550 "tx power: (1/2 dB step)\n");
Don Fry38622412011-12-16 07:07:36 -08001551 if ((cfg(priv)->valid_tx_ant & ANT_A) && tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001552 pos += scnprintf(buf + pos, bufsz - pos,
1553 fmt_hex, "antenna A:",
1554 tx->tx_power.ant_a);
Don Fry38622412011-12-16 07:07:36 -08001555 if ((cfg(priv)->valid_tx_ant & ANT_B) && tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001556 pos += scnprintf(buf + pos, bufsz - pos,
1557 fmt_hex, "antenna B:",
1558 tx->tx_power.ant_b);
Don Fry38622412011-12-16 07:07:36 -08001559 if ((cfg(priv)->valid_tx_ant & ANT_C) && tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001560 pos += scnprintf(buf + pos, bufsz - pos,
1561 fmt_hex, "antenna C:",
1562 tx->tx_power.ant_c);
1563 }
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001564
1565 spin_unlock_bh(&priv->statistics.lock);
1566
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001567 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1568 kfree(buf);
1569 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001570}
1571
1572static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1573 char __user *user_buf,
1574 size_t count, loff_t *ppos)
1575{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001576 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001577 int pos = 0;
1578 char *buf;
1579 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1580 ssize_t ret;
1581 struct statistics_general_common *general, *accum_general;
1582 struct statistics_general_common *delta_general, *max_general;
1583 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1584 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1585
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001586 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001587 return -EAGAIN;
1588
1589 buf = kzalloc(bufsz, GFP_KERNEL);
1590 if (!buf) {
1591 IWL_ERR(priv, "Can not allocate Buffer\n");
1592 return -ENOMEM;
1593 }
1594
1595 /* the statistic information display here is based on
1596 * the last statistics notification from uCode
1597 * might not reflect the current uCode activity
1598 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001599
1600 spin_lock_bh(&priv->statistics.lock);
1601
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001602 general = &priv->statistics.common;
1603 dbg = &priv->statistics.common.dbg;
1604 div = &priv->statistics.common.div;
1605 accum_general = &priv->accum_stats.common;
1606 accum_dbg = &priv->accum_stats.common.dbg;
1607 accum_div = &priv->accum_stats.common.div;
1608 delta_general = &priv->delta_stats.common;
1609 max_general = &priv->max_delta_stats.common;
1610 delta_dbg = &priv->delta_stats.common.dbg;
1611 max_dbg = &priv->max_delta_stats.common.dbg;
1612 delta_div = &priv->delta_stats.common.div;
1613 max_div = &priv->max_delta_stats.common.div;
1614
1615 pos += iwl_statistics_flag(priv, buf, bufsz);
1616 pos += scnprintf(buf + pos, bufsz - pos,
1617 fmt_header, "Statistics_General:");
1618 pos += scnprintf(buf + pos, bufsz - pos,
1619 fmt_value, "temperature:",
1620 le32_to_cpu(general->temperature));
1621 pos += scnprintf(buf + pos, bufsz - pos,
1622 fmt_value, "temperature_m:",
1623 le32_to_cpu(general->temperature_m));
1624 pos += scnprintf(buf + pos, bufsz - pos,
1625 fmt_value, "ttl_timestamp:",
1626 le32_to_cpu(general->ttl_timestamp));
1627 pos += scnprintf(buf + pos, bufsz - pos,
1628 fmt_table, "burst_check:",
1629 le32_to_cpu(dbg->burst_check),
1630 accum_dbg->burst_check,
1631 delta_dbg->burst_check, max_dbg->burst_check);
1632 pos += scnprintf(buf + pos, bufsz - pos,
1633 fmt_table, "burst_count:",
1634 le32_to_cpu(dbg->burst_count),
1635 accum_dbg->burst_count,
1636 delta_dbg->burst_count, max_dbg->burst_count);
1637 pos += scnprintf(buf + pos, bufsz - pos,
1638 fmt_table, "wait_for_silence_timeout_count:",
1639 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1640 accum_dbg->wait_for_silence_timeout_cnt,
1641 delta_dbg->wait_for_silence_timeout_cnt,
1642 max_dbg->wait_for_silence_timeout_cnt);
1643 pos += scnprintf(buf + pos, bufsz - pos,
1644 fmt_table, "sleep_time:",
1645 le32_to_cpu(general->sleep_time),
1646 accum_general->sleep_time,
1647 delta_general->sleep_time, max_general->sleep_time);
1648 pos += scnprintf(buf + pos, bufsz - pos,
1649 fmt_table, "slots_out:",
1650 le32_to_cpu(general->slots_out),
1651 accum_general->slots_out,
1652 delta_general->slots_out, max_general->slots_out);
1653 pos += scnprintf(buf + pos, bufsz - pos,
1654 fmt_table, "slots_idle:",
1655 le32_to_cpu(general->slots_idle),
1656 accum_general->slots_idle,
1657 delta_general->slots_idle, max_general->slots_idle);
1658 pos += scnprintf(buf + pos, bufsz - pos,
1659 fmt_table, "tx_on_a:",
1660 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1661 delta_div->tx_on_a, max_div->tx_on_a);
1662 pos += scnprintf(buf + pos, bufsz - pos,
1663 fmt_table, "tx_on_b:",
1664 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1665 delta_div->tx_on_b, max_div->tx_on_b);
1666 pos += scnprintf(buf + pos, bufsz - pos,
1667 fmt_table, "exec_time:",
1668 le32_to_cpu(div->exec_time), accum_div->exec_time,
1669 delta_div->exec_time, max_div->exec_time);
1670 pos += scnprintf(buf + pos, bufsz - pos,
1671 fmt_table, "probe_time:",
1672 le32_to_cpu(div->probe_time), accum_div->probe_time,
1673 delta_div->probe_time, max_div->probe_time);
1674 pos += scnprintf(buf + pos, bufsz - pos,
1675 fmt_table, "rx_enable_counter:",
1676 le32_to_cpu(general->rx_enable_counter),
1677 accum_general->rx_enable_counter,
1678 delta_general->rx_enable_counter,
1679 max_general->rx_enable_counter);
1680 pos += scnprintf(buf + pos, bufsz - pos,
1681 fmt_table, "num_of_sos_states:",
1682 le32_to_cpu(general->num_of_sos_states),
1683 accum_general->num_of_sos_states,
1684 delta_general->num_of_sos_states,
1685 max_general->num_of_sos_states);
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001686
1687 spin_unlock_bh(&priv->statistics.lock);
1688
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001689 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1690 kfree(buf);
1691 return ret;
1692}
1693
1694static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1695 char __user *user_buf,
1696 size_t count, loff_t *ppos)
1697{
1698 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1699 int pos = 0;
1700 char *buf;
1701 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1702 ssize_t ret;
1703 struct statistics_bt_activity *bt, *accum_bt;
1704
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001705 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001706 return -EAGAIN;
1707
1708 if (!priv->bt_enable_flag)
1709 return -EINVAL;
1710
1711 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001712 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001713 ret = iwl_send_statistics_request(priv, CMD_SYNC, false);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07001714 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001715
1716 if (ret) {
1717 IWL_ERR(priv,
1718 "Error sending statistics request: %zd\n", ret);
1719 return -EAGAIN;
1720 }
1721 buf = kzalloc(bufsz, GFP_KERNEL);
1722 if (!buf) {
1723 IWL_ERR(priv, "Can not allocate Buffer\n");
1724 return -ENOMEM;
1725 }
1726
1727 /*
1728 * the statistic information display here is based on
1729 * the last statistics notification from uCode
1730 * might not reflect the current uCode activity
1731 */
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001732
1733 spin_lock_bh(&priv->statistics.lock);
1734
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001735 bt = &priv->statistics.bt_activity;
1736 accum_bt = &priv->accum_stats.bt_activity;
1737
1738 pos += iwl_statistics_flag(priv, buf, bufsz);
1739 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1740 pos += scnprintf(buf + pos, bufsz - pos,
1741 "\t\t\tcurrent\t\t\taccumulative\n");
1742 pos += scnprintf(buf + pos, bufsz - pos,
1743 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1744 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1745 accum_bt->hi_priority_tx_req_cnt);
1746 pos += scnprintf(buf + pos, bufsz - pos,
1747 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1748 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1749 accum_bt->hi_priority_tx_denied_cnt);
1750 pos += scnprintf(buf + pos, bufsz - pos,
1751 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1752 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1753 accum_bt->lo_priority_tx_req_cnt);
1754 pos += scnprintf(buf + pos, bufsz - pos,
1755 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1756 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1757 accum_bt->lo_priority_tx_denied_cnt);
1758 pos += scnprintf(buf + pos, bufsz - pos,
1759 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1760 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1761 accum_bt->hi_priority_rx_req_cnt);
1762 pos += scnprintf(buf + pos, bufsz - pos,
1763 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1764 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1765 accum_bt->hi_priority_rx_denied_cnt);
1766 pos += scnprintf(buf + pos, bufsz - pos,
1767 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1768 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1769 accum_bt->lo_priority_rx_req_cnt);
1770 pos += scnprintf(buf + pos, bufsz - pos,
1771 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1772 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1773 accum_bt->lo_priority_rx_denied_cnt);
1774
1775 pos += scnprintf(buf + pos, bufsz - pos,
1776 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1777 le32_to_cpu(priv->statistics.num_bt_kills),
1778 priv->statistics.accum_num_bt_kills);
1779
Johannes Berg4ff70fcd2012-03-05 11:24:26 -08001780 spin_unlock_bh(&priv->statistics.lock);
1781
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001782 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1783 kfree(buf);
1784 return ret;
1785}
1786
1787static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1788 char __user *user_buf,
1789 size_t count, loff_t *ppos)
1790{
1791 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1792 int pos = 0;
1793 char *buf;
1794 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1795 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1796 ssize_t ret;
1797
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07001798 if (!iwl_is_alive(priv->shrd))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001799 return -EAGAIN;
1800
1801 buf = kzalloc(bufsz, GFP_KERNEL);
1802 if (!buf) {
1803 IWL_ERR(priv, "Can not allocate Buffer\n");
1804 return -ENOMEM;
1805 }
1806
1807 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1808 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1809 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001810 priv->reply_tx_stats.pp_delay);
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_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001813 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001814 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1815 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001816 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001817 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1818 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001819 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001820 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1821 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001822 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001823 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1824 iwl_get_tx_fail_reason(
1825 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001826 priv->reply_tx_stats.int_crossed_retry);
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_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001829 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001830 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1831 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001832 priv->reply_tx_stats.long_limit);
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_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001835 priv->reply_tx_stats.fifo_underrun);
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_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001838 priv->reply_tx_stats.drain_flow);
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_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001841 priv->reply_tx_stats.rfkill_flush);
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_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001844 priv->reply_tx_stats.life_expire);
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_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001847 priv->reply_tx_stats.dest_ps);
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_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001850 priv->reply_tx_stats.host_abort);
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_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001853 priv->reply_tx_stats.pp_delay);
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_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001856 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001857 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1858 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001859 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001860 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1861 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001862 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001863 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1864 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001865 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001866 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1867 iwl_get_tx_fail_reason(
1868 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001869 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001870 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1871 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001872 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001873 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1874 iwl_get_tx_fail_reason(
1875 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001876 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001877 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001878 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001879
1880 pos += scnprintf(buf + pos, bufsz - pos,
1881 "\nStatistics_Agg_TX_Error:\n");
1882
1883 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1884 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001885 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001886 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1887 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001888 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001889 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1890 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001891 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001892 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1893 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001894 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001895 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1896 iwl_get_agg_tx_fail_reason(
1897 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001898 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001899 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1900 iwl_get_agg_tx_fail_reason(
1901 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001902 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001903 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1904 iwl_get_agg_tx_fail_reason(
1905 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001906 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001907 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1908 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001909 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001910 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1911 iwl_get_agg_tx_fail_reason(
1912 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001913 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001914 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1915 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001916 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001917 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1918 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001919 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001920 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1921 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001922 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001923 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001924 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001925
1926 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1927 kfree(buf);
1928 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001929}
1930
Wey-Yi Guy52259352009-08-07 15:41:43 -07001931static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1932 char __user *user_buf,
1933 size_t count, loff_t *ppos) {
1934
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001935 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001936 int pos = 0;
1937 int cnt = 0;
1938 char *buf;
1939 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1940 ssize_t ret;
1941 struct iwl_sensitivity_data *data;
1942
1943 data = &priv->sensitivity_data;
1944 buf = kzalloc(bufsz, GFP_KERNEL);
1945 if (!buf) {
1946 IWL_ERR(priv, "Can not allocate Buffer\n");
1947 return -ENOMEM;
1948 }
1949
1950 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1951 data->auto_corr_ofdm);
1952 pos += scnprintf(buf + pos, bufsz - pos,
1953 "auto_corr_ofdm_mrc:\t\t %u\n",
1954 data->auto_corr_ofdm_mrc);
1955 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1956 data->auto_corr_ofdm_x1);
1957 pos += scnprintf(buf + pos, bufsz - pos,
1958 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1959 data->auto_corr_ofdm_mrc_x1);
1960 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1961 data->auto_corr_cck);
1962 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1963 data->auto_corr_cck_mrc);
1964 pos += scnprintf(buf + pos, bufsz - pos,
1965 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1966 data->last_bad_plcp_cnt_ofdm);
1967 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1968 data->last_fa_cnt_ofdm);
1969 pos += scnprintf(buf + pos, bufsz - pos,
1970 "last_bad_plcp_cnt_cck:\t\t %u\n",
1971 data->last_bad_plcp_cnt_cck);
1972 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1973 data->last_fa_cnt_cck);
1974 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1975 data->nrg_curr_state);
1976 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1977 data->nrg_prev_state);
1978 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1979 for (cnt = 0; cnt < 10; cnt++) {
1980 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1981 data->nrg_value[cnt]);
1982 }
1983 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1984 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1985 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1986 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1987 data->nrg_silence_rssi[cnt]);
1988 }
1989 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1990 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1991 data->nrg_silence_ref);
1992 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1993 data->nrg_energy_idx);
1994 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1995 data->nrg_silence_idx);
1996 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1997 data->nrg_th_cck);
1998 pos += scnprintf(buf + pos, bufsz - pos,
1999 "nrg_auto_corr_silence_diff:\t %u\n",
2000 data->nrg_auto_corr_silence_diff);
2001 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
2002 data->num_in_cck_no_fa);
2003 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
2004 data->nrg_th_ofdm);
2005
2006 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2007 kfree(buf);
2008 return ret;
2009}
2010
2011
2012static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
2013 char __user *user_buf,
2014 size_t count, loff_t *ppos) {
2015
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002016 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07002017 int pos = 0;
2018 int cnt = 0;
2019 char *buf;
2020 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
2021 ssize_t ret;
2022 struct iwl_chain_noise_data *data;
2023
2024 data = &priv->chain_noise_data;
2025 buf = kzalloc(bufsz, GFP_KERNEL);
2026 if (!buf) {
2027 IWL_ERR(priv, "Can not allocate Buffer\n");
2028 return -ENOMEM;
2029 }
2030
2031 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
2032 data->active_chains);
2033 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
2034 data->chain_noise_a);
2035 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
2036 data->chain_noise_b);
2037 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
2038 data->chain_noise_c);
2039 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
2040 data->chain_signal_a);
2041 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
2042 data->chain_signal_b);
2043 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
2044 data->chain_signal_c);
2045 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
2046 data->beacon_count);
2047
2048 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
2049 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2050 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2051 data->disconn_array[cnt]);
2052 }
2053 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2054 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
2055 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
2056 pos += scnprintf(buf + pos, bufsz - pos, " %u",
2057 data->delta_gain_code[cnt]);
2058 }
2059 pos += scnprintf(buf + pos, bufsz - pos, "\n");
2060 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
2061 data->radio_write);
2062 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
2063 data->state);
2064
2065 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2066 kfree(buf);
2067 return ret;
2068}
2069
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002070static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
2071 char __user *user_buf,
2072 size_t count, loff_t *ppos)
2073{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07002074 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002075 char buf[60];
2076 int pos = 0;
2077 const size_t bufsz = sizeof(buf);
2078 u32 pwrsave_status;
2079
Emmanuel Grumbach1042db22012-01-03 16:56:15 +02002080 pwrsave_status = iwl_read32(trans(priv), CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002081 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
2082
2083 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
2084 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
2085 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
2086 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
2087 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
2088 "error");
2089
2090 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2091}
2092
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002093static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002094 const char __user *user_buf,
2095 size_t count, loff_t *ppos)
2096{
2097 struct iwl_priv *priv = file->private_data;
2098 char buf[8];
2099 int buf_size;
2100 int clear;
2101
2102 memset(buf, 0, sizeof(buf));
2103 buf_size = min(count, sizeof(buf) - 1);
2104 if (copy_from_user(buf, user_buf, buf_size))
2105 return -EFAULT;
2106 if (sscanf(buf, "%d", &clear) != 1)
2107 return -EFAULT;
2108
2109 /* make request to uCode to retrieve statistics information */
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002110 mutex_lock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002111 iwl_send_statistics_request(priv, CMD_SYNC, true);
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -07002112 mutex_unlock(&priv->shrd->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08002113
2114 return count;
2115}
2116
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002117static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
2118 char __user *user_buf,
2119 size_t count, loff_t *ppos) {
2120
Joe Perches57674302010-07-12 13:50:06 -07002121 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002122 int pos = 0;
2123 char buf[128];
2124 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002125
2126 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
2127 priv->event_log.ucode_trace ? "On" : "Off");
2128 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
2129 priv->event_log.non_wraps_count);
2130 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
2131 priv->event_log.wraps_once_count);
2132 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
2133 priv->event_log.wraps_more_count);
2134
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002135 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002136}
2137
2138static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
2139 const char __user *user_buf,
2140 size_t count, loff_t *ppos)
2141{
2142 struct iwl_priv *priv = file->private_data;
2143 char buf[8];
2144 int buf_size;
2145 int trace;
2146
2147 memset(buf, 0, sizeof(buf));
2148 buf_size = min(count, sizeof(buf) - 1);
2149 if (copy_from_user(buf, user_buf, buf_size))
2150 return -EFAULT;
2151 if (sscanf(buf, "%d", &trace) != 1)
2152 return -EFAULT;
2153
2154 if (trace) {
2155 priv->event_log.ucode_trace = true;
Johannes Berg98d4bf02012-01-13 11:56:11 +01002156 if (iwl_is_alive(priv->shrd)) {
2157 /* start collecting data now */
2158 mod_timer(&priv->ucode_trace, jiffies);
2159 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002160 } else {
2161 priv->event_log.ucode_trace = false;
2162 del_timer_sync(&priv->ucode_trace);
2163 }
2164
2165 return count;
2166}
2167
Johannes Berg60987202010-02-18 00:36:07 -08002168static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
2169 char __user *user_buf,
2170 size_t count, loff_t *ppos) {
2171
Joe Perches57674302010-07-12 13:50:06 -07002172 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002173 int len = 0;
2174 char buf[20];
2175
Johannes Berg246ed352010-08-23 10:46:32 +02002176 len = sprintf(buf, "0x%04X\n",
2177 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08002178 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2179}
2180
2181static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
2182 char __user *user_buf,
2183 size_t count, loff_t *ppos) {
2184
Joe Perches57674302010-07-12 13:50:06 -07002185 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08002186 int len = 0;
2187 char buf[20];
2188
2189 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02002190 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08002191 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2192}
2193
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002194static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
2195 char __user *user_buf,
2196 size_t count, loff_t *ppos) {
2197
2198 struct iwl_priv *priv = file->private_data;
2199 int pos = 0;
2200 char buf[12];
2201 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002202
2203 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
2204 priv->missed_beacon_threshold);
2205
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002206 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002207}
2208
2209static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
2210 const char __user *user_buf,
2211 size_t count, loff_t *ppos)
2212{
2213 struct iwl_priv *priv = file->private_data;
2214 char buf[8];
2215 int buf_size;
2216 int missed;
2217
2218 memset(buf, 0, sizeof(buf));
2219 buf_size = min(count, sizeof(buf) - 1);
2220 if (copy_from_user(buf, user_buf, buf_size))
2221 return -EFAULT;
2222 if (sscanf(buf, "%d", &missed) != 1)
2223 return -EINVAL;
2224
2225 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
2226 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
2227 priv->missed_beacon_threshold =
2228 IWL_MISSED_BEACON_THRESHOLD_DEF;
2229 else
2230 priv->missed_beacon_threshold = missed;
2231
2232 return count;
2233}
2234
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002235static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
2236 char __user *user_buf,
2237 size_t count, loff_t *ppos) {
2238
Joe Perches57674302010-07-12 13:50:06 -07002239 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002240 int pos = 0;
2241 char buf[12];
2242 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002243
2244 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Don Fry38622412011-12-16 07:07:36 -08002245 cfg(priv)->base_params->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002246
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002247 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002248}
2249
2250static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2251 const char __user *user_buf,
2252 size_t count, loff_t *ppos) {
2253
2254 struct iwl_priv *priv = file->private_data;
2255 char buf[8];
2256 int buf_size;
2257 int plcp;
2258
2259 memset(buf, 0, sizeof(buf));
2260 buf_size = min(count, sizeof(buf) - 1);
2261 if (copy_from_user(buf, user_buf, buf_size))
2262 return -EFAULT;
2263 if (sscanf(buf, "%d", &plcp) != 1)
2264 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002265 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002266 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Don Fry38622412011-12-16 07:07:36 -08002267 cfg(priv)->base_params->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002268 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002269 else
Don Fry38622412011-12-16 07:07:36 -08002270 cfg(priv)->base_params->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002271 return count;
2272}
2273
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002274static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
2275 char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002276 size_t count, loff_t *ppos)
2277{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002278 struct iwl_priv *priv = file->private_data;
2279 int i, pos = 0;
2280 char buf[300];
2281 const size_t bufsz = sizeof(buf);
2282 struct iwl_force_reset *force_reset;
2283
2284 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
2285 force_reset = &priv->force_reset[i];
2286 pos += scnprintf(buf + pos, bufsz - pos,
2287 "Force reset method %d\n", i);
2288 pos += scnprintf(buf + pos, bufsz - pos,
2289 "\tnumber of reset request: %d\n",
2290 force_reset->reset_request_count);
2291 pos += scnprintf(buf + pos, bufsz - pos,
2292 "\tnumber of reset request success: %d\n",
2293 force_reset->reset_success_count);
2294 pos += scnprintf(buf + pos, bufsz - pos,
2295 "\tnumber of reset request reject: %d\n",
2296 force_reset->reset_reject_count);
2297 pos += scnprintf(buf + pos, bufsz - pos,
2298 "\treset duration: %lu\n",
2299 force_reset->reset_duration);
2300 }
2301 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2302}
2303
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002304static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
2305 const char __user *user_buf,
2306 size_t count, loff_t *ppos) {
2307
2308 struct iwl_priv *priv = file->private_data;
2309 char buf[8];
2310 int buf_size;
2311 int reset, ret;
2312
2313 memset(buf, 0, sizeof(buf));
2314 buf_size = min(count, sizeof(buf) - 1);
2315 if (copy_from_user(buf, user_buf, buf_size))
2316 return -EFAULT;
2317 if (sscanf(buf, "%d", &reset) != 1)
2318 return -EINVAL;
2319 switch (reset) {
2320 case IWL_RF_RESET:
2321 case IWL_FW_RESET:
Wey-Yi Guyc04f9f22010-06-21 16:52:55 -07002322 ret = iwl_force_reset(priv, reset, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002323 break;
2324 default:
2325 return -EINVAL;
2326 }
2327 return ret ? ret : count;
2328}
2329
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002330static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2331 const char __user *user_buf,
2332 size_t count, loff_t *ppos) {
2333
2334 struct iwl_priv *priv = file->private_data;
2335 char buf[8];
2336 int buf_size;
2337 int flush;
2338
2339 memset(buf, 0, sizeof(buf));
2340 buf_size = min(count, sizeof(buf) - 1);
2341 if (copy_from_user(buf, user_buf, buf_size))
2342 return -EFAULT;
2343 if (sscanf(buf, "%d", &flush) != 1)
2344 return -EINVAL;
2345
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -07002346 if (iwl_is_rfkill(priv->shrd))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002347 return -EFAULT;
2348
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002349 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002350
2351 return count;
2352}
2353
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002354static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002355 const char __user *user_buf,
Johannes Bergca934b62011-09-15 11:46:48 -07002356 size_t count, loff_t *ppos)
2357{
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002358 struct iwl_priv *priv = file->private_data;
2359 char buf[8];
2360 int buf_size;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002361 int timeout;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002362
2363 memset(buf, 0, sizeof(buf));
2364 buf_size = min(count, sizeof(buf) - 1);
2365 if (copy_from_user(buf, user_buf, buf_size))
2366 return -EFAULT;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002367 if (sscanf(buf, "%d", &timeout) != 1)
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002368 return -EINVAL;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002369 if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
2370 timeout = IWL_DEF_WD_TIMEOUT;
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002371
Don Fry38622412011-12-16 07:07:36 -08002372 cfg(priv)->base_params->wd_timeout = timeout;
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002373 iwl_setup_watchdog(priv);
Wey-Yi Guy7bdc4732010-08-23 07:57:07 -07002374 return count;
2375}
2376
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002377static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2378 char __user *user_buf,
2379 size_t count, loff_t *ppos) {
2380
2381 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2382 int pos = 0;
2383 char buf[200];
2384 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002385
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002386 if (!priv->bt_enable_flag) {
2387 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002388 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002389 }
2390 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2391 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002392 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2393 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2394 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2395 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002396 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002397 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002398 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2399 priv->bt_ch_announce, priv->kill_ack_mask,
2400 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002401
2402 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2403 switch (priv->bt_traffic_load) {
2404 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2405 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2406 break;
2407 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2408 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2409 break;
2410 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2411 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2412 break;
2413 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2414 default:
2415 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2416 break;
2417 }
2418
Johannes Berg08960de2011-04-05 09:41:53 -07002419 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002420}
2421
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002422static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2423 char __user *user_buf,
2424 size_t count, loff_t *ppos)
2425{
2426 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2427
2428 int pos = 0;
2429 char buf[40];
2430 const size_t bufsz = sizeof(buf);
2431
Don Fry38622412011-12-16 07:07:36 -08002432 if (cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002433 pos += scnprintf(buf + pos, bufsz - pos,
2434 "use %s for aggregation\n",
Don Fry38622412011-12-16 07:07:36 -08002435 (cfg(priv)->ht_params->use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002436 "rts/cts" : "cts-to-self");
2437 else
2438 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2439
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002440 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2441}
2442
2443static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2444 const char __user *user_buf,
2445 size_t count, loff_t *ppos) {
2446
2447 struct iwl_priv *priv = file->private_data;
2448 char buf[8];
2449 int buf_size;
2450 int rts;
2451
Don Fry38622412011-12-16 07:07:36 -08002452 if (!cfg(priv)->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002453 return -EINVAL;
2454
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002455 memset(buf, 0, sizeof(buf));
2456 buf_size = min(count, sizeof(buf) - 1);
2457 if (copy_from_user(buf, user_buf, buf_size))
2458 return -EFAULT;
2459 if (sscanf(buf, "%d", &rts) != 1)
2460 return -EINVAL;
2461 if (rts)
Don Fry38622412011-12-16 07:07:36 -08002462 cfg(priv)->ht_params->use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002463 else
Don Fry38622412011-12-16 07:07:36 -08002464 cfg(priv)->ht_params->use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002465 return count;
2466}
2467
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002468static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2469 const char __user *user_buf,
2470 size_t count, loff_t *ppos)
2471{
2472 struct iwl_priv *priv = file->private_data;
2473 char buf[8];
2474 int buf_size;
2475
2476 memset(buf, 0, sizeof(buf));
2477 buf_size = min(count, sizeof(buf) - 1);
2478 if (copy_from_user(buf, user_buf, buf_size))
2479 return -EFAULT;
2480
2481 iwl_cmd_echo_test(priv);
2482 return count;
2483}
2484
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002485DEBUGFS_READ_FILE_OPS(rx_statistics);
2486DEBUGFS_READ_FILE_OPS(tx_statistics);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002487DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002488DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2489DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2490DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002491DEBUGFS_READ_FILE_OPS(sensitivity);
2492DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002493DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002494DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
2495DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002496DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002497DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002498DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002499DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002500DEBUGFS_READ_FILE_OPS(rxon_flags);
2501DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002502DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002503DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002504DEBUGFS_WRITE_FILE_OPS(wd_timeout);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002505DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002506DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002507DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002508DEBUGFS_WRITE_FILE_OPS(echo_test);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002509
Johannes Bergca934b62011-09-15 11:46:48 -07002510#ifdef CONFIG_IWLWIFI_DEBUG
2511static ssize_t iwl_dbgfs_debug_level_read(struct file *file,
2512 char __user *user_buf,
2513 size_t count, loff_t *ppos)
2514{
2515 struct iwl_priv *priv = file->private_data;
2516 struct iwl_shared *shrd = priv->shrd;
2517 char buf[11];
2518 int len;
2519
2520 len = scnprintf(buf, sizeof(buf), "0x%.8x",
2521 iwl_get_debug_level(shrd));
2522
2523 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
2524}
2525
2526static ssize_t iwl_dbgfs_debug_level_write(struct file *file,
2527 const char __user *user_buf,
2528 size_t count, loff_t *ppos)
2529{
2530 struct iwl_priv *priv = file->private_data;
2531 struct iwl_shared *shrd = priv->shrd;
2532 char buf[11];
2533 unsigned long val;
2534 int ret;
2535
2536 if (count > sizeof(buf))
2537 return -EINVAL;
2538
2539 memset(buf, 0, sizeof(buf));
2540 if (copy_from_user(buf, user_buf, count))
2541 return -EFAULT;
2542
2543 ret = strict_strtoul(buf, 0, &val);
2544 if (ret)
2545 return ret;
2546
2547 shrd->dbg_level_dev = val;
2548 if (iwl_alloc_traffic_mem(priv))
2549 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
2550
2551 return count;
2552}
2553DEBUGFS_READ_WRITE_FILE_OPS(debug_level);
2554#endif /* CONFIG_IWLWIFI_DEBUG */
2555
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002556/*
2557 * Create the debugfs files and directories
2558 *
2559 */
2560int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
2561{
Zhu Yi95b1a822008-05-29 16:34:50 +08002562 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002563 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002564
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002565 dir_drv = debugfs_create_dir(name, phyd);
2566 if (!dir_drv)
2567 return -ENOMEM;
2568
2569 priv->debugfs_dir = dir_drv;
2570
2571 dir_data = debugfs_create_dir("data", dir_drv);
2572 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002573 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002574 dir_rf = debugfs_create_dir("rf", dir_drv);
2575 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002576 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002577 dir_debug = debugfs_create_dir("debug", dir_drv);
2578 if (!dir_debug)
2579 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002580
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002581 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2582 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002583 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002584 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2585 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2586 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002587 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002588 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002589 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2590 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002591 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2592 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002593 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002594
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002595 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
2596 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
Emmanuel Grumbach41f5e042011-09-06 09:31:20 -07002597 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002598 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2599 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
2600 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002601 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002602 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002603 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002604 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2605 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2606 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002607 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002608 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002609 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2610 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002611 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002612 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002613 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002614 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2615 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002616 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002617 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002618 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002619 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002620#ifdef CONFIG_IWLWIFI_DEBUG
2621 DEBUGFS_ADD_FILE(debug_level, dir_debug, S_IRUSR | S_IWUSR);
2622#endif
2623
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002624 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
2625 &priv->disable_sens_cal);
2626 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
2627 &priv->disable_chain_noise_cal);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002628
2629 if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
2630 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002631 return 0;
2632
2633err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002634 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002635 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002636 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002637}
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002638
2639/**
2640 * Remove the debugfs files and directories
2641 *
2642 */
2643void iwl_dbgfs_unregister(struct iwl_priv *priv)
2644{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002645 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002646 return;
2647
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002648 debugfs_remove_recursive(priv->debugfs_dir);
2649 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002650}