blob: 376c79337a0e04f86796494565749b7b333ab1ff [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02005 * Copyright(c) 2008 - 2014 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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020022 * in the file called COPYING.
Tomas Winkler712b6cf2008-03-12 16:58:52 -070023 *
24 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020025 * Intel Linux Wireless <linuxwifi@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>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070033#include <linux/ieee80211.h>
34#include <net/mac80211.h>
Sharon Dvir39bdb172015-10-15 18:18:09 +030035
Tomas Winkler712b6cf2008-03-12 16:58:52 -070036#include "iwl-debug.h"
Sharon Dvir39bdb172015-10-15 18:18:09 +030037#include "iwl-trans.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070038#include "iwl-io.h"
Johannes Berg1023fdc2012-05-15 12:16:34 +020039#include "dev.h"
40#include "agn.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070041
42/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080043#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
44 if (!debugfs_create_file(#name, mode, parent, priv, \
45 &iwl_dbgfs_##name##_ops)) \
46 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070047} while (0)
48
Johannes Berg4c84a8f2010-01-22 14:22:54 -080049#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
50 struct dentry *__tmp; \
51 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
52 parent, ptr); \
53 if (IS_ERR(__tmp) || !__tmp) \
54 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070055} while (0)
56
Johannes Berg4c84a8f2010-01-22 14:22:54 -080057#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
58 struct dentry *__tmp; \
59 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
60 parent, ptr); \
61 if (IS_ERR(__tmp) || !__tmp) \
62 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080063} while (0)
64
Johannes Bergca934b62011-09-15 11:46:48 -070065#define DEBUGFS_ADD_U32(name, parent, ptr, mode) do { \
66 struct dentry *__tmp; \
67 __tmp = debugfs_create_u32(#name, mode, \
68 parent, ptr); \
69 if (IS_ERR(__tmp) || !__tmp) \
70 goto err; \
71} while (0)
72
Tomas Winkler712b6cf2008-03-12 16:58:52 -070073/* file operation */
Tomas Winkler712b6cf2008-03-12 16:58:52 -070074#define DEBUGFS_READ_FILE_OPS(name) \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070075static const struct file_operations iwl_dbgfs_##name##_ops = { \
Richard A. Griffiths0ff1bd32012-06-28 13:14:11 -070076 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070077 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020078 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070079};
80
Ester Kummer189a2b52008-05-15 13:54:18 +080081#define DEBUGFS_WRITE_FILE_OPS(name) \
Ester Kummer189a2b52008-05-15 13:54:18 +080082static const struct file_operations iwl_dbgfs_##name##_ops = { \
83 .write = iwl_dbgfs_##name##_write, \
Stephen Boyd234e3402012-04-05 14:25:11 -070084 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020085 .llseek = generic_file_llseek, \
Ester Kummer189a2b52008-05-15 13:54:18 +080086};
87
88
Tomas Winkler712b6cf2008-03-12 16:58:52 -070089#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070090static const struct file_operations iwl_dbgfs_##name##_ops = { \
91 .write = iwl_dbgfs_##name##_write, \
92 .read = iwl_dbgfs_##name##_read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070093 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020094 .llseek = generic_file_llseek, \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070095};
96
Tomas Winkler712b6cf2008-03-12 16:58:52 -070097static ssize_t iwl_dbgfs_sram_read(struct file *file,
98 char __user *user_buf,
99 size_t count, loff_t *ppos)
100{
Jay Sternberg24834d22011-01-11 15:41:00 -0800101 u32 val = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800102 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700103 ssize_t ret;
Jay Sternberg24834d22011-01-11 15:41:00 -0800104 int i = 0;
105 bool device_format = false;
106 int offset = 0;
107 int len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700108 int pos = 0;
Jay Sternberg24834d22011-01-11 15:41:00 -0800109 int sram;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700110 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800111 const struct fw_img *img;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800112 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700113
Johannes Berg4fc79db2012-08-21 18:57:11 +0200114 if (!iwl_is_ready_rf(priv))
115 return -EAGAIN;
116
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800117 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800118 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
119 priv->dbgfs_sram_offset = 0x800000;
Johannes Bergf9e75442012-03-30 09:37:39 +0200120 if (!priv->ucode_loaded)
David Spinadel8f7ffbe2012-03-10 13:00:10 -0800121 return -EINVAL;
Meenakshi Venkataramana42506e2012-03-15 13:26:57 -0700122 img = &priv->fw->img[priv->cur_ucode];
David Spinadel6dfa8d02012-03-10 13:00:14 -0800123 priv->dbgfs_sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800124 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800125 len = priv->dbgfs_sram_len;
126
127 if (len == -4) {
128 device_format = true;
129 len = 4;
130 }
131
132 bufsz = 50 + len * 4;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800133 buf = kmalloc(bufsz, GFP_KERNEL);
134 if (!buf)
135 return -ENOMEM;
Jay Sternberg24834d22011-01-11 15:41:00 -0800136
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800137 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Jay Sternberg24834d22011-01-11 15:41:00 -0800138 len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800139 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800140 priv->dbgfs_sram_offset);
Jay Sternberg24834d22011-01-11 15:41:00 -0800141
142 /* adjust sram address since reads are only on even u32 boundaries */
143 offset = priv->dbgfs_sram_offset & 0x3;
144 sram = priv->dbgfs_sram_offset & ~0x3;
145
146 /* read the first u32 from sram */
Emmanuel Grumbach4fd442d2012-12-24 14:27:11 +0200147 val = iwl_trans_read_mem32(priv->trans, sram);
Jay Sternberg24834d22011-01-11 15:41:00 -0800148
149 for (; len; len--) {
150 /* put the address at the start of every line */
151 if (i == 0)
152 pos += scnprintf(buf + pos, bufsz - pos,
153 "%08X: ", sram + offset);
154
155 if (device_format)
156 pos += scnprintf(buf + pos, bufsz - pos,
157 "%02x", (val >> (8 * (3 - offset))) & 0xff);
158 else
159 pos += scnprintf(buf + pos, bufsz - pos,
160 "%02x ", (val >> (8 * offset)) & 0xff);
161
162 /* if all bytes processed, read the next u32 from sram */
163 if (++offset == 4) {
164 sram += 4;
165 offset = 0;
Emmanuel Grumbach4fd442d2012-12-24 14:27:11 +0200166 val = iwl_trans_read_mem32(priv->trans, sram);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700167 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800168
169 /* put in extra spaces and split lines for human readability */
170 if (++i == 16) {
171 i = 0;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800172 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Jay Sternberg24834d22011-01-11 15:41:00 -0800173 } else if (!(i & 7)) {
174 pos += scnprintf(buf + pos, bufsz - pos, " ");
175 } else if (!(i & 3)) {
176 pos += scnprintf(buf + pos, bufsz - pos, " ");
177 }
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700178 }
Jay Sternberg24834d22011-01-11 15:41:00 -0800179 if (i)
180 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700181
182 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800183 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700184 return ret;
185}
186
187static ssize_t iwl_dbgfs_sram_write(struct file *file,
188 const char __user *user_buf,
189 size_t count, loff_t *ppos)
190{
191 struct iwl_priv *priv = file->private_data;
192 char buf[64];
193 int buf_size;
194 u32 offset, len;
195
196 memset(buf, 0, sizeof(buf));
197 buf_size = min(count, sizeof(buf) - 1);
198 if (copy_from_user(buf, user_buf, buf_size))
199 return -EFAULT;
200
201 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800202 priv->dbgfs_sram_offset = offset;
203 priv->dbgfs_sram_len = len;
Jay Sternberg24834d22011-01-11 15:41:00 -0800204 } else if (sscanf(buf, "%x", &offset) == 1) {
205 priv->dbgfs_sram_offset = offset;
206 priv->dbgfs_sram_len = -4;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700207 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800208 priv->dbgfs_sram_offset = 0;
209 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700210 }
211
212 return count;
213}
214
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700215static ssize_t iwl_dbgfs_wowlan_sram_read(struct file *file,
216 char __user *user_buf,
217 size_t count, loff_t *ppos)
218{
219 struct iwl_priv *priv = file->private_data;
David Spinadel6dfa8d02012-03-10 13:00:14 -0800220 const struct fw_img *img = &priv->fw->img[IWL_UCODE_WOWLAN];
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700221
222 if (!priv->wowlan_sram)
223 return -ENODATA;
224
225 return simple_read_from_buffer(user_buf, count, ppos,
226 priv->wowlan_sram,
David Spinadel6dfa8d02012-03-10 13:00:14 -0800227 img->sec[IWL_UCODE_SECTION_DATA].len);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700228}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700229static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
230 size_t count, loff_t *ppos)
231{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700232 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800233 struct iwl_station_entry *station;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700234 struct iwl_tid_data *tid_data;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700235 char *buf;
236 int i, j, pos = 0;
237 ssize_t ret;
238 /* Add 30 for initial string */
239 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700240
241 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300242 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700243 return -ENOMEM;
244
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700245 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700246 priv->num_stations);
247
Emmanuel Grumbach3eae4bb2011-10-10 07:26:55 -0700248 for (i = 0; i < IWLAGN_STATION_COUNT; i++) {
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700249 station = &priv->stations[i];
Johannes Bergda735112010-05-03 01:25:24 -0700250 if (!station->used)
251 continue;
252 pos += scnprintf(buf + pos, bufsz - pos,
253 "station %d - addr: %pM, flags: %#x\n",
254 i, station->sta.sta.addr,
255 station->sta.station_flags_msk);
256 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Berg9eae88f2012-03-15 13:26:52 -0700257 "TID seqno next_rclmd "
258 "rate_n_flags state txq\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700259
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700260 for (j = 0; j < IWL_MAX_TID_COUNT; j++) {
Emmanuel Grumbach04cf6822011-11-23 11:06:12 +0200261 tid_data = &priv->tid_data[i][j];
Johannes Bergda735112010-05-03 01:25:24 -0700262 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Berg9eae88f2012-03-15 13:26:52 -0700263 "%d: 0x%.4x 0x%.4x 0x%.8x "
264 "%d %.2d",
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700265 j, tid_data->seq_number,
Johannes Berg9eae88f2012-03-15 13:26:52 -0700266 tid_data->next_reclaimed,
267 tid_data->agg.rate_n_flags,
268 tid_data->agg.state,
269 tid_data->agg.txq_id);
Johannes Bergda735112010-05-03 01:25:24 -0700270
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700271 if (tid_data->agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700272 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700273 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700274 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700275 }
Johannes Bergda735112010-05-03 01:25:24 -0700276
277 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700278 }
279
280 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
281 kfree(buf);
282 return ret;
283}
284
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700285static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800286 char __user *user_buf,
287 size_t count,
288 loff_t *ppos)
289{
290 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700291 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800292 int pos = 0, ofs = 0, buf_size = 0;
293 const u8 *ptr;
294 char *buf;
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200295 u16 nvm_ver;
Johannes Berg26a7ca92012-05-21 11:55:54 +0200296 size_t eeprom_len = priv->eeprom_blob_size;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800297 buf_size = 4 * eeprom_len + 256;
298
Johannes Bergf9e75442012-03-30 09:37:39 +0200299 if (eeprom_len % 16)
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800300 return -ENODATA;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800301
Johannes Berg26a7ca92012-05-21 11:55:54 +0200302 ptr = priv->eeprom_blob;
Johannes Bergf9e75442012-03-30 09:37:39 +0200303 if (!ptr)
Julia Lawallc37457e2009-08-03 11:11:45 +0200304 return -ENOMEM;
Julia Lawallc37457e2009-08-03 11:11:45 +0200305
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800306 /* 4 characters for byte 0xYY */
307 buf = kzalloc(buf_size, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +0200308 if (!buf)
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800309 return -ENOMEM;
Johannes Bergf9e75442012-03-30 09:37:39 +0200310
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200311 nvm_ver = priv->nvm_data->nvm_version;
Johannes Berg26a7ca92012-05-21 11:55:54 +0200312 pos += scnprintf(buf + pos, buf_size - pos,
Eytan Lifshitzb7998c82012-12-01 20:59:49 +0200313 "NVM version: 0x%x\n", nvm_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800314 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
Andy Shevchenko3cd6e2f2015-07-16 15:42:14 +0300315 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x %16ph\n",
316 ofs, ptr + ofs);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800317 }
318
319 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
320 kfree(buf);
321 return ret;
322}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700323
Winkler, Tomasd366df52008-12-02 12:14:01 -0800324static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
325 size_t count, loff_t *ppos)
326{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700327 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800328 struct ieee80211_channel *channels = NULL;
329 const struct ieee80211_supported_band *supp_band = NULL;
330 int pos = 0, i, bufsz = PAGE_SIZE;
331 char *buf;
332 ssize_t ret;
333
Winkler, Tomasd366df52008-12-02 12:14:01 -0800334 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +0200335 if (!buf)
Winkler, Tomasd366df52008-12-02 12:14:01 -0800336 return -ENOMEM;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800337
Johannes Berg57fbcce2016-04-12 15:56:15 +0200338 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700339 if (supp_band) {
340 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800341
Winkler, Tomasd366df52008-12-02 12:14:01 -0800342 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700343 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
344 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800345
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700346 for (i = 0; i < supp_band->n_channels; i++)
347 pos += scnprintf(buf + pos, bufsz - pos,
348 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700349 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700350 channels[i].max_power,
351 channels[i].flags & IEEE80211_CHAN_RADAR ?
352 " (IEEE 802.11h required)" : "",
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200353 ((channels[i].flags & IEEE80211_CHAN_NO_IR)
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700354 || (channels[i].flags &
355 IEEE80211_CHAN_RADAR)) ? "" :
356 ", IBSS",
357 channels[i].flags &
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200358 IEEE80211_CHAN_NO_IR ?
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700359 "passive only" : "active/passive");
360 }
Johannes Berg57fbcce2016-04-12 15:56:15 +0200361 supp_band = iwl_get_hw_mode(priv, NL80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700362 if (supp_band) {
363 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800364
Winkler, Tomasd366df52008-12-02 12:14:01 -0800365 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700366 "Displaying %d channels in 5.2GHz band (802.11a)\n",
367 supp_band->n_channels);
368
369 for (i = 0; i < supp_band->n_channels; i++)
370 pos += scnprintf(buf + pos, bufsz - pos,
371 "%d: %ddBm: BSS%s%s, %s.\n",
Shanyu Zhao81e95432010-07-28 13:40:27 -0700372 channels[i].hw_value,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700373 channels[i].max_power,
374 channels[i].flags & IEEE80211_CHAN_RADAR ?
375 " (IEEE 802.11h required)" : "",
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200376 ((channels[i].flags & IEEE80211_CHAN_NO_IR)
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700377 || (channels[i].flags &
378 IEEE80211_CHAN_RADAR)) ? "" :
379 ", IBSS",
380 channels[i].flags &
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200381 IEEE80211_CHAN_NO_IR ?
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700382 "passive only" : "active/passive");
383 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800384 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
385 kfree(buf);
386 return ret;
387}
388
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700389static ssize_t iwl_dbgfs_status_read(struct file *file,
390 char __user *user_buf,
391 size_t count, loff_t *ppos) {
392
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700393 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700394 char buf[512];
395 int pos = 0;
396 const size_t bufsz = sizeof(buf);
397
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700398 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800399 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700400 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
Don Fry9a716862012-03-07 09:52:32 -0800401 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700402 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800403 test_bit(STATUS_ALIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700404 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800405 test_bit(STATUS_READY, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700406 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800407 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700408 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800409 test_bit(STATUS_STATISTICS, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700410 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800411 test_bit(STATUS_SCANNING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700412 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800413 test_bit(STATUS_SCAN_ABORTING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700414 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
Don Fry83626402012-03-07 09:52:37 -0800415 test_bit(STATUS_SCAN_HW, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700416 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
Don Fry47107e82012-03-15 13:27:06 -0700417 test_bit(STATUS_POWER_PMI, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700418 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
Don Fry17acd0b2012-03-15 13:27:05 -0700419 test_bit(STATUS_FW_ERROR, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700420 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
421}
422
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700423static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700424 char __user *user_buf,
425 size_t count, loff_t *ppos) {
426
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700427 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700428
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700429 int pos = 0;
430 int cnt = 0;
431 char *buf;
432 int bufsz = 24 * 64; /* 24 items * 64 char per item */
433 ssize_t ret;
434
435 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +0200436 if (!buf)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700437 return -ENOMEM;
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700438
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700439 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700440 if (priv->rx_handlers_stats[cnt] > 0)
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700441 pos += scnprintf(buf + pos, bufsz - pos,
442 "\tRx handler[%36s]:\t\t %u\n",
Sharon Dvir39bdb172015-10-15 18:18:09 +0300443 iwl_get_cmd_string(priv->trans, (u32)cnt),
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700444 priv->rx_handlers_stats[cnt]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700445 }
446
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700447 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
448 kfree(buf);
449 return ret;
450}
451
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700452static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700453 const char __user *user_buf,
454 size_t count, loff_t *ppos)
455{
456 struct iwl_priv *priv = file->private_data;
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700457
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700458 char buf[8];
459 int buf_size;
460 u32 reset_flag;
461
462 memset(buf, 0, sizeof(buf));
463 buf_size = min(count, sizeof(buf) - 1);
464 if (copy_from_user(buf, user_buf, buf_size))
465 return -EFAULT;
466 if (sscanf(buf, "%x", &reset_flag) != 1)
467 return -EFAULT;
468 if (reset_flag == 0)
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700469 memset(&priv->rx_handlers_stats[0], 0,
470 sizeof(priv->rx_handlers_stats));
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700471
472 return count;
473}
474
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700475static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
476 size_t count, loff_t *ppos)
477{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700478 struct iwl_priv *priv = file->private_data;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200479 struct iwl_rxon_context *ctx;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700480 int pos = 0, i;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200481 char buf[256 * NUM_IWL_RXON_CTX];
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700482 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700483
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200484 for_each_context(priv, ctx) {
485 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
486 ctx->ctxid);
487 for (i = 0; i < AC_NUM; i++) {
488 pos += scnprintf(buf + pos, bufsz - pos,
489 "\tcw_min\tcw_max\taifsn\ttxop\n");
490 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700491 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
Johannes Berg8dfdb9d2010-08-23 10:46:38 +0200492 ctx->qos_data.def_qos_parm.ac[i].cw_min,
493 ctx->qos_data.def_qos_parm.ac[i].cw_max,
494 ctx->qos_data.def_qos_parm.ac[i].aifsn,
495 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
496 }
497 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700498 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800499 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700500}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700501
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700502static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
503 char __user *user_buf,
504 size_t count, loff_t *ppos)
505{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700506 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700507 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700508 struct iwl_tt_restriction *restriction;
509 char buf[100];
510 int pos = 0;
511 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700512
513 pos += scnprintf(buf + pos, bufsz - pos,
514 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700515 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700516 pos += scnprintf(buf + pos, bufsz - pos,
517 "Thermal Throttling State: %d\n",
518 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700519 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700520 restriction = tt->restriction + tt->state;
521 pos += scnprintf(buf + pos, bufsz - pos,
522 "Tx mode: %d\n",
523 restriction->tx_stream);
524 pos += scnprintf(buf + pos, bufsz - pos,
525 "Rx mode: %d\n",
526 restriction->rx_stream);
527 pos += scnprintf(buf + pos, bufsz - pos,
528 "HT mode: %d\n",
529 restriction->is_ht);
530 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800531 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700532}
533
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700534static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
535 const char __user *user_buf,
536 size_t count, loff_t *ppos)
537{
538 struct iwl_priv *priv = file->private_data;
539 char buf[8];
540 int buf_size;
541 int ht40;
542
543 memset(buf, 0, sizeof(buf));
544 buf_size = min(count, sizeof(buf) - 1);
545 if (copy_from_user(buf, user_buf, buf_size))
546 return -EFAULT;
547 if (sscanf(buf, "%d", &ht40) != 1)
548 return -EFAULT;
Johannes Berg246ed352010-08-23 10:46:32 +0200549 if (!iwl_is_any_associated(priv))
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700550 priv->disable_ht40 = ht40 ? true : false;
Johannes Bergf9e75442012-03-30 09:37:39 +0200551 else
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700552 return -EINVAL;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700553
554 return count;
555}
556
557static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
558 char __user *user_buf,
559 size_t count, loff_t *ppos)
560{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700561 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700562 char buf[100];
563 int pos = 0;
564 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700565
566 pos += scnprintf(buf + pos, bufsz - pos,
567 "11n 40MHz Mode: %s\n",
568 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800569 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700570}
571
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700572static ssize_t iwl_dbgfs_temperature_read(struct file *file,
573 char __user *user_buf,
574 size_t count, loff_t *ppos)
575{
576 struct iwl_priv *priv = file->private_data;
577 char buf[8];
578 int pos = 0;
579 const size_t bufsz = sizeof(buf);
580
581 pos += scnprintf(buf + pos, bufsz - pos, "%d\n", priv->temperature);
582 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
583}
584
585
Johannes Berge312c242009-08-07 15:41:51 -0700586static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
587 const char __user *user_buf,
588 size_t count, loff_t *ppos)
589{
590 struct iwl_priv *priv = file->private_data;
591 char buf[8];
592 int buf_size;
593 int value;
594
595 memset(buf, 0, sizeof(buf));
596 buf_size = min(count, sizeof(buf) - 1);
597 if (copy_from_user(buf, user_buf, buf_size))
598 return -EFAULT;
599
600 if (sscanf(buf, "%d", &value) != 1)
601 return -EINVAL;
602
603 /*
604 * Our users expect 0 to be "CAM", but 0 isn't actually
605 * valid here. However, let's not confuse them and present
606 * IWL_POWER_INDEX_1 as "1", not "0".
607 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700608 if (value == 0)
609 return -EINVAL;
610 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700611 value -= 1;
612
613 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
614 return -EINVAL;
615
Don Fry83626402012-03-07 09:52:37 -0800616 if (!iwl_is_ready_rf(priv))
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700617 return -EAGAIN;
618
Johannes Berge312c242009-08-07 15:41:51 -0700619 priv->power_data.debug_sleep_level_override = value;
620
Johannes Bergb1eea292012-03-06 13:30:42 -0800621 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700622 iwl_power_update_mode(priv, true);
Johannes Bergb1eea292012-03-06 13:30:42 -0800623 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700624
625 return count;
626}
627
628static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
629 char __user *user_buf,
630 size_t count, loff_t *ppos)
631{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700632 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700633 char buf[10];
634 int pos, value;
635 const size_t bufsz = sizeof(buf);
636
637 /* see the write function */
638 value = priv->power_data.debug_sleep_level_override;
639 if (value >= 0)
640 value += 1;
641
642 pos = scnprintf(buf, bufsz, "%d\n", value);
643 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
644}
645
646static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
647 char __user *user_buf,
648 size_t count, loff_t *ppos)
649{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700650 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700651 char buf[200];
652 int pos = 0, i;
653 const size_t bufsz = sizeof(buf);
654 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
655
656 pos += scnprintf(buf + pos, bufsz - pos,
657 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
658 pos += scnprintf(buf + pos, bufsz - pos,
659 "RX/TX timeout: %d/%d usec\n",
660 le32_to_cpu(cmd->rx_data_timeout),
661 le32_to_cpu(cmd->tx_data_timeout));
662 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
663 pos += scnprintf(buf + pos, bufsz - pos,
664 "sleep_interval[%d]: %d\n", i,
665 le32_to_cpu(cmd->sleep_interval[i]));
666
667 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
668}
669
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700670DEBUGFS_READ_WRITE_FILE_OPS(sram);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700671DEBUGFS_READ_FILE_OPS(wowlan_sram);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700672DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700673DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800674DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700675DEBUGFS_READ_FILE_OPS(status);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -0700676DEBUGFS_READ_WRITE_FILE_OPS(rx_handlers);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700677DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700678DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700679DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -0700680DEBUGFS_READ_FILE_OPS(temperature);
Johannes Berge312c242009-08-07 15:41:51 -0700681DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
682DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700683
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700684static const char *fmt_value = " %-30s %10u\n";
685static const char *fmt_hex = " %-30s 0x%02X\n";
686static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
687static const char *fmt_header =
688 "%-32s current cumulative delta max\n";
689
690static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
691{
692 int p = 0;
693 u32 flag;
694
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800695 lockdep_assert_held(&priv->statistics.lock);
696
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700697 flag = le32_to_cpu(priv->statistics.flag);
698
699 p += scnprintf(buf + p, bufsz - p, "Statistics Flag(0x%X):\n", flag);
700 if (flag & UCODE_STATISTICS_CLEAR_MSK)
701 p += scnprintf(buf + p, bufsz - p,
702 "\tStatistics have been cleared\n");
703 p += scnprintf(buf + p, bufsz - p, "\tOperational Frequency: %s\n",
704 (flag & UCODE_STATISTICS_FREQUENCY_MSK)
705 ? "2.4 GHz" : "5.2 GHz");
706 p += scnprintf(buf + p, bufsz - p, "\tTGj Narrow Band: %s\n",
707 (flag & UCODE_STATISTICS_NARROW_BAND_MSK)
708 ? "enabled" : "disabled");
709
710 return p;
711}
712
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -0700713static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
714 char __user *user_buf,
715 size_t count, loff_t *ppos)
716{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700717 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700718 int pos = 0;
719 char *buf;
720 int bufsz = sizeof(struct statistics_rx_phy) * 40 +
721 sizeof(struct statistics_rx_non_phy) * 40 +
722 sizeof(struct statistics_rx_ht_phy) * 40 + 400;
723 ssize_t ret;
724 struct statistics_rx_phy *ofdm, *accum_ofdm, *delta_ofdm, *max_ofdm;
725 struct statistics_rx_phy *cck, *accum_cck, *delta_cck, *max_cck;
726 struct statistics_rx_non_phy *general, *accum_general;
727 struct statistics_rx_non_phy *delta_general, *max_general;
728 struct statistics_rx_ht_phy *ht, *accum_ht, *delta_ht, *max_ht;
729
Don Fry83626402012-03-07 09:52:37 -0800730 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700731 return -EAGAIN;
732
733 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +0200734 if (!buf)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700735 return -ENOMEM;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700736
737 /*
738 * the statistic information display here is based on
739 * the last statistics notification from uCode
740 * might not reflect the current uCode activity
741 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800742 spin_lock_bh(&priv->statistics.lock);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -0700743 ofdm = &priv->statistics.rx_ofdm;
744 cck = &priv->statistics.rx_cck;
745 general = &priv->statistics.rx_non_phy;
746 ht = &priv->statistics.rx_ofdm_ht;
747 accum_ofdm = &priv->accum_stats.rx_ofdm;
748 accum_cck = &priv->accum_stats.rx_cck;
749 accum_general = &priv->accum_stats.rx_non_phy;
750 accum_ht = &priv->accum_stats.rx_ofdm_ht;
751 delta_ofdm = &priv->delta_stats.rx_ofdm;
752 delta_cck = &priv->delta_stats.rx_cck;
753 delta_general = &priv->delta_stats.rx_non_phy;
754 delta_ht = &priv->delta_stats.rx_ofdm_ht;
755 max_ofdm = &priv->max_delta_stats.rx_ofdm;
756 max_cck = &priv->max_delta_stats.rx_cck;
757 max_general = &priv->max_delta_stats.rx_non_phy;
758 max_ht = &priv->max_delta_stats.rx_ofdm_ht;
759
760 pos += iwl_statistics_flag(priv, buf, bufsz);
761 pos += scnprintf(buf + pos, bufsz - pos,
762 fmt_header, "Statistics_Rx - OFDM:");
763 pos += scnprintf(buf + pos, bufsz - pos,
764 fmt_table, "ina_cnt:",
765 le32_to_cpu(ofdm->ina_cnt),
766 accum_ofdm->ina_cnt,
767 delta_ofdm->ina_cnt, max_ofdm->ina_cnt);
768 pos += scnprintf(buf + pos, bufsz - pos,
769 fmt_table, "fina_cnt:",
770 le32_to_cpu(ofdm->fina_cnt), accum_ofdm->fina_cnt,
771 delta_ofdm->fina_cnt, max_ofdm->fina_cnt);
772 pos += scnprintf(buf + pos, bufsz - pos,
773 fmt_table, "plcp_err:",
774 le32_to_cpu(ofdm->plcp_err), accum_ofdm->plcp_err,
775 delta_ofdm->plcp_err, max_ofdm->plcp_err);
776 pos += scnprintf(buf + pos, bufsz - pos,
777 fmt_table, "crc32_err:",
778 le32_to_cpu(ofdm->crc32_err), accum_ofdm->crc32_err,
779 delta_ofdm->crc32_err, max_ofdm->crc32_err);
780 pos += scnprintf(buf + pos, bufsz - pos,
781 fmt_table, "overrun_err:",
782 le32_to_cpu(ofdm->overrun_err),
783 accum_ofdm->overrun_err, delta_ofdm->overrun_err,
784 max_ofdm->overrun_err);
785 pos += scnprintf(buf + pos, bufsz - pos,
786 fmt_table, "early_overrun_err:",
787 le32_to_cpu(ofdm->early_overrun_err),
788 accum_ofdm->early_overrun_err,
789 delta_ofdm->early_overrun_err,
790 max_ofdm->early_overrun_err);
791 pos += scnprintf(buf + pos, bufsz - pos,
792 fmt_table, "crc32_good:",
793 le32_to_cpu(ofdm->crc32_good),
794 accum_ofdm->crc32_good, delta_ofdm->crc32_good,
795 max_ofdm->crc32_good);
796 pos += scnprintf(buf + pos, bufsz - pos,
797 fmt_table, "false_alarm_cnt:",
798 le32_to_cpu(ofdm->false_alarm_cnt),
799 accum_ofdm->false_alarm_cnt,
800 delta_ofdm->false_alarm_cnt,
801 max_ofdm->false_alarm_cnt);
802 pos += scnprintf(buf + pos, bufsz - pos,
803 fmt_table, "fina_sync_err_cnt:",
804 le32_to_cpu(ofdm->fina_sync_err_cnt),
805 accum_ofdm->fina_sync_err_cnt,
806 delta_ofdm->fina_sync_err_cnt,
807 max_ofdm->fina_sync_err_cnt);
808 pos += scnprintf(buf + pos, bufsz - pos,
809 fmt_table, "sfd_timeout:",
810 le32_to_cpu(ofdm->sfd_timeout),
811 accum_ofdm->sfd_timeout, delta_ofdm->sfd_timeout,
812 max_ofdm->sfd_timeout);
813 pos += scnprintf(buf + pos, bufsz - pos,
814 fmt_table, "fina_timeout:",
815 le32_to_cpu(ofdm->fina_timeout),
816 accum_ofdm->fina_timeout, delta_ofdm->fina_timeout,
817 max_ofdm->fina_timeout);
818 pos += scnprintf(buf + pos, bufsz - pos,
819 fmt_table, "unresponded_rts:",
820 le32_to_cpu(ofdm->unresponded_rts),
821 accum_ofdm->unresponded_rts,
822 delta_ofdm->unresponded_rts,
823 max_ofdm->unresponded_rts);
824 pos += scnprintf(buf + pos, bufsz - pos,
825 fmt_table, "rxe_frame_lmt_ovrun:",
826 le32_to_cpu(ofdm->rxe_frame_limit_overrun),
827 accum_ofdm->rxe_frame_limit_overrun,
828 delta_ofdm->rxe_frame_limit_overrun,
829 max_ofdm->rxe_frame_limit_overrun);
830 pos += scnprintf(buf + pos, bufsz - pos,
831 fmt_table, "sent_ack_cnt:",
832 le32_to_cpu(ofdm->sent_ack_cnt),
833 accum_ofdm->sent_ack_cnt, delta_ofdm->sent_ack_cnt,
834 max_ofdm->sent_ack_cnt);
835 pos += scnprintf(buf + pos, bufsz - pos,
836 fmt_table, "sent_cts_cnt:",
837 le32_to_cpu(ofdm->sent_cts_cnt),
838 accum_ofdm->sent_cts_cnt, delta_ofdm->sent_cts_cnt,
839 max_ofdm->sent_cts_cnt);
840 pos += scnprintf(buf + pos, bufsz - pos,
841 fmt_table, "sent_ba_rsp_cnt:",
842 le32_to_cpu(ofdm->sent_ba_rsp_cnt),
843 accum_ofdm->sent_ba_rsp_cnt,
844 delta_ofdm->sent_ba_rsp_cnt,
845 max_ofdm->sent_ba_rsp_cnt);
846 pos += scnprintf(buf + pos, bufsz - pos,
847 fmt_table, "dsp_self_kill:",
848 le32_to_cpu(ofdm->dsp_self_kill),
849 accum_ofdm->dsp_self_kill,
850 delta_ofdm->dsp_self_kill,
851 max_ofdm->dsp_self_kill);
852 pos += scnprintf(buf + pos, bufsz - pos,
853 fmt_table, "mh_format_err:",
854 le32_to_cpu(ofdm->mh_format_err),
855 accum_ofdm->mh_format_err,
856 delta_ofdm->mh_format_err,
857 max_ofdm->mh_format_err);
858 pos += scnprintf(buf + pos, bufsz - pos,
859 fmt_table, "re_acq_main_rssi_sum:",
860 le32_to_cpu(ofdm->re_acq_main_rssi_sum),
861 accum_ofdm->re_acq_main_rssi_sum,
862 delta_ofdm->re_acq_main_rssi_sum,
863 max_ofdm->re_acq_main_rssi_sum);
864
865 pos += scnprintf(buf + pos, bufsz - pos,
866 fmt_header, "Statistics_Rx - CCK:");
867 pos += scnprintf(buf + pos, bufsz - pos,
868 fmt_table, "ina_cnt:",
869 le32_to_cpu(cck->ina_cnt), accum_cck->ina_cnt,
870 delta_cck->ina_cnt, max_cck->ina_cnt);
871 pos += scnprintf(buf + pos, bufsz - pos,
872 fmt_table, "fina_cnt:",
873 le32_to_cpu(cck->fina_cnt), accum_cck->fina_cnt,
874 delta_cck->fina_cnt, max_cck->fina_cnt);
875 pos += scnprintf(buf + pos, bufsz - pos,
876 fmt_table, "plcp_err:",
877 le32_to_cpu(cck->plcp_err), accum_cck->plcp_err,
878 delta_cck->plcp_err, max_cck->plcp_err);
879 pos += scnprintf(buf + pos, bufsz - pos,
880 fmt_table, "crc32_err:",
881 le32_to_cpu(cck->crc32_err), accum_cck->crc32_err,
882 delta_cck->crc32_err, max_cck->crc32_err);
883 pos += scnprintf(buf + pos, bufsz - pos,
884 fmt_table, "overrun_err:",
885 le32_to_cpu(cck->overrun_err),
886 accum_cck->overrun_err, delta_cck->overrun_err,
887 max_cck->overrun_err);
888 pos += scnprintf(buf + pos, bufsz - pos,
889 fmt_table, "early_overrun_err:",
890 le32_to_cpu(cck->early_overrun_err),
891 accum_cck->early_overrun_err,
892 delta_cck->early_overrun_err,
893 max_cck->early_overrun_err);
894 pos += scnprintf(buf + pos, bufsz - pos,
895 fmt_table, "crc32_good:",
896 le32_to_cpu(cck->crc32_good), accum_cck->crc32_good,
897 delta_cck->crc32_good, max_cck->crc32_good);
898 pos += scnprintf(buf + pos, bufsz - pos,
899 fmt_table, "false_alarm_cnt:",
900 le32_to_cpu(cck->false_alarm_cnt),
901 accum_cck->false_alarm_cnt,
902 delta_cck->false_alarm_cnt, max_cck->false_alarm_cnt);
903 pos += scnprintf(buf + pos, bufsz - pos,
904 fmt_table, "fina_sync_err_cnt:",
905 le32_to_cpu(cck->fina_sync_err_cnt),
906 accum_cck->fina_sync_err_cnt,
907 delta_cck->fina_sync_err_cnt,
908 max_cck->fina_sync_err_cnt);
909 pos += scnprintf(buf + pos, bufsz - pos,
910 fmt_table, "sfd_timeout:",
911 le32_to_cpu(cck->sfd_timeout),
912 accum_cck->sfd_timeout, delta_cck->sfd_timeout,
913 max_cck->sfd_timeout);
914 pos += scnprintf(buf + pos, bufsz - pos,
915 fmt_table, "fina_timeout:",
916 le32_to_cpu(cck->fina_timeout),
917 accum_cck->fina_timeout, delta_cck->fina_timeout,
918 max_cck->fina_timeout);
919 pos += scnprintf(buf + pos, bufsz - pos,
920 fmt_table, "unresponded_rts:",
921 le32_to_cpu(cck->unresponded_rts),
922 accum_cck->unresponded_rts, delta_cck->unresponded_rts,
923 max_cck->unresponded_rts);
924 pos += scnprintf(buf + pos, bufsz - pos,
925 fmt_table, "rxe_frame_lmt_ovrun:",
926 le32_to_cpu(cck->rxe_frame_limit_overrun),
927 accum_cck->rxe_frame_limit_overrun,
928 delta_cck->rxe_frame_limit_overrun,
929 max_cck->rxe_frame_limit_overrun);
930 pos += scnprintf(buf + pos, bufsz - pos,
931 fmt_table, "sent_ack_cnt:",
932 le32_to_cpu(cck->sent_ack_cnt),
933 accum_cck->sent_ack_cnt, delta_cck->sent_ack_cnt,
934 max_cck->sent_ack_cnt);
935 pos += scnprintf(buf + pos, bufsz - pos,
936 fmt_table, "sent_cts_cnt:",
937 le32_to_cpu(cck->sent_cts_cnt),
938 accum_cck->sent_cts_cnt, delta_cck->sent_cts_cnt,
939 max_cck->sent_cts_cnt);
940 pos += scnprintf(buf + pos, bufsz - pos,
941 fmt_table, "sent_ba_rsp_cnt:",
942 le32_to_cpu(cck->sent_ba_rsp_cnt),
943 accum_cck->sent_ba_rsp_cnt,
944 delta_cck->sent_ba_rsp_cnt,
945 max_cck->sent_ba_rsp_cnt);
946 pos += scnprintf(buf + pos, bufsz - pos,
947 fmt_table, "dsp_self_kill:",
948 le32_to_cpu(cck->dsp_self_kill),
949 accum_cck->dsp_self_kill, delta_cck->dsp_self_kill,
950 max_cck->dsp_self_kill);
951 pos += scnprintf(buf + pos, bufsz - pos,
952 fmt_table, "mh_format_err:",
953 le32_to_cpu(cck->mh_format_err),
954 accum_cck->mh_format_err, delta_cck->mh_format_err,
955 max_cck->mh_format_err);
956 pos += scnprintf(buf + pos, bufsz - pos,
957 fmt_table, "re_acq_main_rssi_sum:",
958 le32_to_cpu(cck->re_acq_main_rssi_sum),
959 accum_cck->re_acq_main_rssi_sum,
960 delta_cck->re_acq_main_rssi_sum,
961 max_cck->re_acq_main_rssi_sum);
962
963 pos += scnprintf(buf + pos, bufsz - pos,
964 fmt_header, "Statistics_Rx - GENERAL:");
965 pos += scnprintf(buf + pos, bufsz - pos,
966 fmt_table, "bogus_cts:",
967 le32_to_cpu(general->bogus_cts),
968 accum_general->bogus_cts, delta_general->bogus_cts,
969 max_general->bogus_cts);
970 pos += scnprintf(buf + pos, bufsz - pos,
971 fmt_table, "bogus_ack:",
972 le32_to_cpu(general->bogus_ack),
973 accum_general->bogus_ack, delta_general->bogus_ack,
974 max_general->bogus_ack);
975 pos += scnprintf(buf + pos, bufsz - pos,
976 fmt_table, "non_bssid_frames:",
977 le32_to_cpu(general->non_bssid_frames),
978 accum_general->non_bssid_frames,
979 delta_general->non_bssid_frames,
980 max_general->non_bssid_frames);
981 pos += scnprintf(buf + pos, bufsz - pos,
982 fmt_table, "filtered_frames:",
983 le32_to_cpu(general->filtered_frames),
984 accum_general->filtered_frames,
985 delta_general->filtered_frames,
986 max_general->filtered_frames);
987 pos += scnprintf(buf + pos, bufsz - pos,
988 fmt_table, "non_channel_beacons:",
989 le32_to_cpu(general->non_channel_beacons),
990 accum_general->non_channel_beacons,
991 delta_general->non_channel_beacons,
992 max_general->non_channel_beacons);
993 pos += scnprintf(buf + pos, bufsz - pos,
994 fmt_table, "channel_beacons:",
995 le32_to_cpu(general->channel_beacons),
996 accum_general->channel_beacons,
997 delta_general->channel_beacons,
998 max_general->channel_beacons);
999 pos += scnprintf(buf + pos, bufsz - pos,
1000 fmt_table, "num_missed_bcon:",
1001 le32_to_cpu(general->num_missed_bcon),
1002 accum_general->num_missed_bcon,
1003 delta_general->num_missed_bcon,
1004 max_general->num_missed_bcon);
1005 pos += scnprintf(buf + pos, bufsz - pos,
1006 fmt_table, "adc_rx_saturation_time:",
1007 le32_to_cpu(general->adc_rx_saturation_time),
1008 accum_general->adc_rx_saturation_time,
1009 delta_general->adc_rx_saturation_time,
1010 max_general->adc_rx_saturation_time);
1011 pos += scnprintf(buf + pos, bufsz - pos,
1012 fmt_table, "ina_detect_search_tm:",
1013 le32_to_cpu(general->ina_detection_search_time),
1014 accum_general->ina_detection_search_time,
1015 delta_general->ina_detection_search_time,
1016 max_general->ina_detection_search_time);
1017 pos += scnprintf(buf + pos, bufsz - pos,
1018 fmt_table, "beacon_silence_rssi_a:",
1019 le32_to_cpu(general->beacon_silence_rssi_a),
1020 accum_general->beacon_silence_rssi_a,
1021 delta_general->beacon_silence_rssi_a,
1022 max_general->beacon_silence_rssi_a);
1023 pos += scnprintf(buf + pos, bufsz - pos,
1024 fmt_table, "beacon_silence_rssi_b:",
1025 le32_to_cpu(general->beacon_silence_rssi_b),
1026 accum_general->beacon_silence_rssi_b,
1027 delta_general->beacon_silence_rssi_b,
1028 max_general->beacon_silence_rssi_b);
1029 pos += scnprintf(buf + pos, bufsz - pos,
1030 fmt_table, "beacon_silence_rssi_c:",
1031 le32_to_cpu(general->beacon_silence_rssi_c),
1032 accum_general->beacon_silence_rssi_c,
1033 delta_general->beacon_silence_rssi_c,
1034 max_general->beacon_silence_rssi_c);
1035 pos += scnprintf(buf + pos, bufsz - pos,
1036 fmt_table, "interference_data_flag:",
1037 le32_to_cpu(general->interference_data_flag),
1038 accum_general->interference_data_flag,
1039 delta_general->interference_data_flag,
1040 max_general->interference_data_flag);
1041 pos += scnprintf(buf + pos, bufsz - pos,
1042 fmt_table, "channel_load:",
1043 le32_to_cpu(general->channel_load),
1044 accum_general->channel_load,
1045 delta_general->channel_load,
1046 max_general->channel_load);
1047 pos += scnprintf(buf + pos, bufsz - pos,
1048 fmt_table, "dsp_false_alarms:",
1049 le32_to_cpu(general->dsp_false_alarms),
1050 accum_general->dsp_false_alarms,
1051 delta_general->dsp_false_alarms,
1052 max_general->dsp_false_alarms);
1053 pos += scnprintf(buf + pos, bufsz - pos,
1054 fmt_table, "beacon_rssi_a:",
1055 le32_to_cpu(general->beacon_rssi_a),
1056 accum_general->beacon_rssi_a,
1057 delta_general->beacon_rssi_a,
1058 max_general->beacon_rssi_a);
1059 pos += scnprintf(buf + pos, bufsz - pos,
1060 fmt_table, "beacon_rssi_b:",
1061 le32_to_cpu(general->beacon_rssi_b),
1062 accum_general->beacon_rssi_b,
1063 delta_general->beacon_rssi_b,
1064 max_general->beacon_rssi_b);
1065 pos += scnprintf(buf + pos, bufsz - pos,
1066 fmt_table, "beacon_rssi_c:",
1067 le32_to_cpu(general->beacon_rssi_c),
1068 accum_general->beacon_rssi_c,
1069 delta_general->beacon_rssi_c,
1070 max_general->beacon_rssi_c);
1071 pos += scnprintf(buf + pos, bufsz - pos,
1072 fmt_table, "beacon_energy_a:",
1073 le32_to_cpu(general->beacon_energy_a),
1074 accum_general->beacon_energy_a,
1075 delta_general->beacon_energy_a,
1076 max_general->beacon_energy_a);
1077 pos += scnprintf(buf + pos, bufsz - pos,
1078 fmt_table, "beacon_energy_b:",
1079 le32_to_cpu(general->beacon_energy_b),
1080 accum_general->beacon_energy_b,
1081 delta_general->beacon_energy_b,
1082 max_general->beacon_energy_b);
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 fmt_table, "beacon_energy_c:",
1085 le32_to_cpu(general->beacon_energy_c),
1086 accum_general->beacon_energy_c,
1087 delta_general->beacon_energy_c,
1088 max_general->beacon_energy_c);
1089
1090 pos += scnprintf(buf + pos, bufsz - pos,
1091 fmt_header, "Statistics_Rx - OFDM_HT:");
1092 pos += scnprintf(buf + pos, bufsz - pos,
1093 fmt_table, "plcp_err:",
1094 le32_to_cpu(ht->plcp_err), accum_ht->plcp_err,
1095 delta_ht->plcp_err, max_ht->plcp_err);
1096 pos += scnprintf(buf + pos, bufsz - pos,
1097 fmt_table, "overrun_err:",
1098 le32_to_cpu(ht->overrun_err), accum_ht->overrun_err,
1099 delta_ht->overrun_err, max_ht->overrun_err);
1100 pos += scnprintf(buf + pos, bufsz - pos,
1101 fmt_table, "early_overrun_err:",
1102 le32_to_cpu(ht->early_overrun_err),
1103 accum_ht->early_overrun_err,
1104 delta_ht->early_overrun_err,
1105 max_ht->early_overrun_err);
1106 pos += scnprintf(buf + pos, bufsz - pos,
1107 fmt_table, "crc32_good:",
1108 le32_to_cpu(ht->crc32_good), accum_ht->crc32_good,
1109 delta_ht->crc32_good, max_ht->crc32_good);
1110 pos += scnprintf(buf + pos, bufsz - pos,
1111 fmt_table, "crc32_err:",
1112 le32_to_cpu(ht->crc32_err), accum_ht->crc32_err,
1113 delta_ht->crc32_err, max_ht->crc32_err);
1114 pos += scnprintf(buf + pos, bufsz - pos,
1115 fmt_table, "mh_format_err:",
1116 le32_to_cpu(ht->mh_format_err),
1117 accum_ht->mh_format_err,
1118 delta_ht->mh_format_err, max_ht->mh_format_err);
1119 pos += scnprintf(buf + pos, bufsz - pos,
1120 fmt_table, "agg_crc32_good:",
1121 le32_to_cpu(ht->agg_crc32_good),
1122 accum_ht->agg_crc32_good,
1123 delta_ht->agg_crc32_good, max_ht->agg_crc32_good);
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 fmt_table, "agg_mpdu_cnt:",
1126 le32_to_cpu(ht->agg_mpdu_cnt),
1127 accum_ht->agg_mpdu_cnt,
1128 delta_ht->agg_mpdu_cnt, max_ht->agg_mpdu_cnt);
1129 pos += scnprintf(buf + pos, bufsz - pos,
1130 fmt_table, "agg_cnt:",
1131 le32_to_cpu(ht->agg_cnt), accum_ht->agg_cnt,
1132 delta_ht->agg_cnt, max_ht->agg_cnt);
1133 pos += scnprintf(buf + pos, bufsz - pos,
1134 fmt_table, "unsupport_mcs:",
1135 le32_to_cpu(ht->unsupport_mcs),
1136 accum_ht->unsupport_mcs,
1137 delta_ht->unsupport_mcs, max_ht->unsupport_mcs);
1138
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001139 spin_unlock_bh(&priv->statistics.lock);
1140
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001141 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1142 kfree(buf);
1143 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001144}
1145
1146static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1147 char __user *user_buf,
1148 size_t count, loff_t *ppos)
1149{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001150 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001151 int pos = 0;
1152 char *buf;
1153 int bufsz = (sizeof(struct statistics_tx) * 48) + 250;
1154 ssize_t ret;
1155 struct statistics_tx *tx, *accum_tx, *delta_tx, *max_tx;
1156
Don Fry83626402012-03-07 09:52:37 -08001157 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001158 return -EAGAIN;
1159
1160 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001161 if (!buf)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001162 return -ENOMEM;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001163
1164 /* the statistic information display here is based on
1165 * the last statistics notification from uCode
1166 * might not reflect the current uCode activity
1167 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001168 spin_lock_bh(&priv->statistics.lock);
1169
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001170 tx = &priv->statistics.tx;
1171 accum_tx = &priv->accum_stats.tx;
1172 delta_tx = &priv->delta_stats.tx;
1173 max_tx = &priv->max_delta_stats.tx;
1174
1175 pos += iwl_statistics_flag(priv, buf, bufsz);
1176 pos += scnprintf(buf + pos, bufsz - pos,
1177 fmt_header, "Statistics_Tx:");
1178 pos += scnprintf(buf + pos, bufsz - pos,
1179 fmt_table, "preamble:",
1180 le32_to_cpu(tx->preamble_cnt),
1181 accum_tx->preamble_cnt,
1182 delta_tx->preamble_cnt, max_tx->preamble_cnt);
1183 pos += scnprintf(buf + pos, bufsz - pos,
1184 fmt_table, "rx_detected_cnt:",
1185 le32_to_cpu(tx->rx_detected_cnt),
1186 accum_tx->rx_detected_cnt,
1187 delta_tx->rx_detected_cnt, max_tx->rx_detected_cnt);
1188 pos += scnprintf(buf + pos, bufsz - pos,
1189 fmt_table, "bt_prio_defer_cnt:",
1190 le32_to_cpu(tx->bt_prio_defer_cnt),
1191 accum_tx->bt_prio_defer_cnt,
1192 delta_tx->bt_prio_defer_cnt,
1193 max_tx->bt_prio_defer_cnt);
1194 pos += scnprintf(buf + pos, bufsz - pos,
1195 fmt_table, "bt_prio_kill_cnt:",
1196 le32_to_cpu(tx->bt_prio_kill_cnt),
1197 accum_tx->bt_prio_kill_cnt,
1198 delta_tx->bt_prio_kill_cnt,
1199 max_tx->bt_prio_kill_cnt);
1200 pos += scnprintf(buf + pos, bufsz - pos,
1201 fmt_table, "few_bytes_cnt:",
1202 le32_to_cpu(tx->few_bytes_cnt),
1203 accum_tx->few_bytes_cnt,
1204 delta_tx->few_bytes_cnt, max_tx->few_bytes_cnt);
1205 pos += scnprintf(buf + pos, bufsz - pos,
1206 fmt_table, "cts_timeout:",
1207 le32_to_cpu(tx->cts_timeout), accum_tx->cts_timeout,
1208 delta_tx->cts_timeout, max_tx->cts_timeout);
1209 pos += scnprintf(buf + pos, bufsz - pos,
1210 fmt_table, "ack_timeout:",
1211 le32_to_cpu(tx->ack_timeout),
1212 accum_tx->ack_timeout,
1213 delta_tx->ack_timeout, max_tx->ack_timeout);
1214 pos += scnprintf(buf + pos, bufsz - pos,
1215 fmt_table, "expected_ack_cnt:",
1216 le32_to_cpu(tx->expected_ack_cnt),
1217 accum_tx->expected_ack_cnt,
1218 delta_tx->expected_ack_cnt,
1219 max_tx->expected_ack_cnt);
1220 pos += scnprintf(buf + pos, bufsz - pos,
1221 fmt_table, "actual_ack_cnt:",
1222 le32_to_cpu(tx->actual_ack_cnt),
1223 accum_tx->actual_ack_cnt,
1224 delta_tx->actual_ack_cnt,
1225 max_tx->actual_ack_cnt);
1226 pos += scnprintf(buf + pos, bufsz - pos,
1227 fmt_table, "dump_msdu_cnt:",
1228 le32_to_cpu(tx->dump_msdu_cnt),
1229 accum_tx->dump_msdu_cnt,
1230 delta_tx->dump_msdu_cnt,
1231 max_tx->dump_msdu_cnt);
1232 pos += scnprintf(buf + pos, bufsz - pos,
1233 fmt_table, "abort_nxt_frame_mismatch:",
1234 le32_to_cpu(tx->burst_abort_next_frame_mismatch_cnt),
1235 accum_tx->burst_abort_next_frame_mismatch_cnt,
1236 delta_tx->burst_abort_next_frame_mismatch_cnt,
1237 max_tx->burst_abort_next_frame_mismatch_cnt);
1238 pos += scnprintf(buf + pos, bufsz - pos,
1239 fmt_table, "abort_missing_nxt_frame:",
1240 le32_to_cpu(tx->burst_abort_missing_next_frame_cnt),
1241 accum_tx->burst_abort_missing_next_frame_cnt,
1242 delta_tx->burst_abort_missing_next_frame_cnt,
1243 max_tx->burst_abort_missing_next_frame_cnt);
1244 pos += scnprintf(buf + pos, bufsz - pos,
1245 fmt_table, "cts_timeout_collision:",
1246 le32_to_cpu(tx->cts_timeout_collision),
1247 accum_tx->cts_timeout_collision,
1248 delta_tx->cts_timeout_collision,
1249 max_tx->cts_timeout_collision);
1250 pos += scnprintf(buf + pos, bufsz - pos,
1251 fmt_table, "ack_ba_timeout_collision:",
1252 le32_to_cpu(tx->ack_or_ba_timeout_collision),
1253 accum_tx->ack_or_ba_timeout_collision,
1254 delta_tx->ack_or_ba_timeout_collision,
1255 max_tx->ack_or_ba_timeout_collision);
1256 pos += scnprintf(buf + pos, bufsz - pos,
1257 fmt_table, "agg ba_timeout:",
1258 le32_to_cpu(tx->agg.ba_timeout),
1259 accum_tx->agg.ba_timeout,
1260 delta_tx->agg.ba_timeout,
1261 max_tx->agg.ba_timeout);
1262 pos += scnprintf(buf + pos, bufsz - pos,
1263 fmt_table, "agg ba_resched_frames:",
1264 le32_to_cpu(tx->agg.ba_reschedule_frames),
1265 accum_tx->agg.ba_reschedule_frames,
1266 delta_tx->agg.ba_reschedule_frames,
1267 max_tx->agg.ba_reschedule_frames);
1268 pos += scnprintf(buf + pos, bufsz - pos,
1269 fmt_table, "agg scd_query_agg_frame:",
1270 le32_to_cpu(tx->agg.scd_query_agg_frame_cnt),
1271 accum_tx->agg.scd_query_agg_frame_cnt,
1272 delta_tx->agg.scd_query_agg_frame_cnt,
1273 max_tx->agg.scd_query_agg_frame_cnt);
1274 pos += scnprintf(buf + pos, bufsz - pos,
1275 fmt_table, "agg scd_query_no_agg:",
1276 le32_to_cpu(tx->agg.scd_query_no_agg),
1277 accum_tx->agg.scd_query_no_agg,
1278 delta_tx->agg.scd_query_no_agg,
1279 max_tx->agg.scd_query_no_agg);
1280 pos += scnprintf(buf + pos, bufsz - pos,
1281 fmt_table, "agg scd_query_agg:",
1282 le32_to_cpu(tx->agg.scd_query_agg),
1283 accum_tx->agg.scd_query_agg,
1284 delta_tx->agg.scd_query_agg,
1285 max_tx->agg.scd_query_agg);
1286 pos += scnprintf(buf + pos, bufsz - pos,
1287 fmt_table, "agg scd_query_mismatch:",
1288 le32_to_cpu(tx->agg.scd_query_mismatch),
1289 accum_tx->agg.scd_query_mismatch,
1290 delta_tx->agg.scd_query_mismatch,
1291 max_tx->agg.scd_query_mismatch);
1292 pos += scnprintf(buf + pos, bufsz - pos,
1293 fmt_table, "agg frame_not_ready:",
1294 le32_to_cpu(tx->agg.frame_not_ready),
1295 accum_tx->agg.frame_not_ready,
1296 delta_tx->agg.frame_not_ready,
1297 max_tx->agg.frame_not_ready);
1298 pos += scnprintf(buf + pos, bufsz - pos,
1299 fmt_table, "agg underrun:",
1300 le32_to_cpu(tx->agg.underrun),
1301 accum_tx->agg.underrun,
1302 delta_tx->agg.underrun, max_tx->agg.underrun);
1303 pos += scnprintf(buf + pos, bufsz - pos,
1304 fmt_table, "agg bt_prio_kill:",
1305 le32_to_cpu(tx->agg.bt_prio_kill),
1306 accum_tx->agg.bt_prio_kill,
1307 delta_tx->agg.bt_prio_kill,
1308 max_tx->agg.bt_prio_kill);
1309 pos += scnprintf(buf + pos, bufsz - pos,
1310 fmt_table, "agg rx_ba_rsp_cnt:",
1311 le32_to_cpu(tx->agg.rx_ba_rsp_cnt),
1312 accum_tx->agg.rx_ba_rsp_cnt,
1313 delta_tx->agg.rx_ba_rsp_cnt,
1314 max_tx->agg.rx_ba_rsp_cnt);
1315
1316 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1317 pos += scnprintf(buf + pos, bufsz - pos,
1318 "tx power: (1/2 dB step)\n");
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001319 if ((priv->nvm_data->valid_tx_ant & ANT_A) &&
Johannes Berg7e79a392012-03-05 11:24:32 -08001320 tx->tx_power.ant_a)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001321 pos += scnprintf(buf + pos, bufsz - pos,
1322 fmt_hex, "antenna A:",
1323 tx->tx_power.ant_a);
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001324 if ((priv->nvm_data->valid_tx_ant & ANT_B) &&
Johannes Berg7e79a392012-03-05 11:24:32 -08001325 tx->tx_power.ant_b)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001326 pos += scnprintf(buf + pos, bufsz - pos,
1327 fmt_hex, "antenna B:",
1328 tx->tx_power.ant_b);
Eytan Lifshitzb7998c82012-12-01 20:59:49 +02001329 if ((priv->nvm_data->valid_tx_ant & ANT_C) &&
Johannes Berg7e79a392012-03-05 11:24:32 -08001330 tx->tx_power.ant_c)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001331 pos += scnprintf(buf + pos, bufsz - pos,
1332 fmt_hex, "antenna C:",
1333 tx->tx_power.ant_c);
1334 }
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001335
1336 spin_unlock_bh(&priv->statistics.lock);
1337
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001338 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1339 kfree(buf);
1340 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001341}
1342
1343static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1344 char __user *user_buf,
1345 size_t count, loff_t *ppos)
1346{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001347 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001348 int pos = 0;
1349 char *buf;
1350 int bufsz = sizeof(struct statistics_general) * 10 + 300;
1351 ssize_t ret;
1352 struct statistics_general_common *general, *accum_general;
1353 struct statistics_general_common *delta_general, *max_general;
1354 struct statistics_dbg *dbg, *accum_dbg, *delta_dbg, *max_dbg;
1355 struct statistics_div *div, *accum_div, *delta_div, *max_div;
1356
Don Fry83626402012-03-07 09:52:37 -08001357 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001358 return -EAGAIN;
1359
1360 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001361 if (!buf)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001362 return -ENOMEM;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001363
1364 /* the statistic information display here is based on
1365 * the last statistics notification from uCode
1366 * might not reflect the current uCode activity
1367 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001368
1369 spin_lock_bh(&priv->statistics.lock);
1370
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001371 general = &priv->statistics.common;
1372 dbg = &priv->statistics.common.dbg;
1373 div = &priv->statistics.common.div;
1374 accum_general = &priv->accum_stats.common;
1375 accum_dbg = &priv->accum_stats.common.dbg;
1376 accum_div = &priv->accum_stats.common.div;
1377 delta_general = &priv->delta_stats.common;
1378 max_general = &priv->max_delta_stats.common;
1379 delta_dbg = &priv->delta_stats.common.dbg;
1380 max_dbg = &priv->max_delta_stats.common.dbg;
1381 delta_div = &priv->delta_stats.common.div;
1382 max_div = &priv->max_delta_stats.common.div;
1383
1384 pos += iwl_statistics_flag(priv, buf, bufsz);
1385 pos += scnprintf(buf + pos, bufsz - pos,
1386 fmt_header, "Statistics_General:");
1387 pos += scnprintf(buf + pos, bufsz - pos,
1388 fmt_value, "temperature:",
1389 le32_to_cpu(general->temperature));
1390 pos += scnprintf(buf + pos, bufsz - pos,
1391 fmt_value, "temperature_m:",
1392 le32_to_cpu(general->temperature_m));
1393 pos += scnprintf(buf + pos, bufsz - pos,
1394 fmt_value, "ttl_timestamp:",
1395 le32_to_cpu(general->ttl_timestamp));
1396 pos += scnprintf(buf + pos, bufsz - pos,
1397 fmt_table, "burst_check:",
1398 le32_to_cpu(dbg->burst_check),
1399 accum_dbg->burst_check,
1400 delta_dbg->burst_check, max_dbg->burst_check);
1401 pos += scnprintf(buf + pos, bufsz - pos,
1402 fmt_table, "burst_count:",
1403 le32_to_cpu(dbg->burst_count),
1404 accum_dbg->burst_count,
1405 delta_dbg->burst_count, max_dbg->burst_count);
1406 pos += scnprintf(buf + pos, bufsz - pos,
1407 fmt_table, "wait_for_silence_timeout_count:",
1408 le32_to_cpu(dbg->wait_for_silence_timeout_cnt),
1409 accum_dbg->wait_for_silence_timeout_cnt,
1410 delta_dbg->wait_for_silence_timeout_cnt,
1411 max_dbg->wait_for_silence_timeout_cnt);
1412 pos += scnprintf(buf + pos, bufsz - pos,
1413 fmt_table, "sleep_time:",
1414 le32_to_cpu(general->sleep_time),
1415 accum_general->sleep_time,
1416 delta_general->sleep_time, max_general->sleep_time);
1417 pos += scnprintf(buf + pos, bufsz - pos,
1418 fmt_table, "slots_out:",
1419 le32_to_cpu(general->slots_out),
1420 accum_general->slots_out,
1421 delta_general->slots_out, max_general->slots_out);
1422 pos += scnprintf(buf + pos, bufsz - pos,
1423 fmt_table, "slots_idle:",
1424 le32_to_cpu(general->slots_idle),
1425 accum_general->slots_idle,
1426 delta_general->slots_idle, max_general->slots_idle);
1427 pos += scnprintf(buf + pos, bufsz - pos,
1428 fmt_table, "tx_on_a:",
1429 le32_to_cpu(div->tx_on_a), accum_div->tx_on_a,
1430 delta_div->tx_on_a, max_div->tx_on_a);
1431 pos += scnprintf(buf + pos, bufsz - pos,
1432 fmt_table, "tx_on_b:",
1433 le32_to_cpu(div->tx_on_b), accum_div->tx_on_b,
1434 delta_div->tx_on_b, max_div->tx_on_b);
1435 pos += scnprintf(buf + pos, bufsz - pos,
1436 fmt_table, "exec_time:",
1437 le32_to_cpu(div->exec_time), accum_div->exec_time,
1438 delta_div->exec_time, max_div->exec_time);
1439 pos += scnprintf(buf + pos, bufsz - pos,
1440 fmt_table, "probe_time:",
1441 le32_to_cpu(div->probe_time), accum_div->probe_time,
1442 delta_div->probe_time, max_div->probe_time);
1443 pos += scnprintf(buf + pos, bufsz - pos,
1444 fmt_table, "rx_enable_counter:",
1445 le32_to_cpu(general->rx_enable_counter),
1446 accum_general->rx_enable_counter,
1447 delta_general->rx_enable_counter,
1448 max_general->rx_enable_counter);
1449 pos += scnprintf(buf + pos, bufsz - pos,
1450 fmt_table, "num_of_sos_states:",
1451 le32_to_cpu(general->num_of_sos_states),
1452 accum_general->num_of_sos_states,
1453 delta_general->num_of_sos_states,
1454 max_general->num_of_sos_states);
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001455
1456 spin_unlock_bh(&priv->statistics.lock);
1457
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001458 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1459 kfree(buf);
1460 return ret;
1461}
1462
1463static ssize_t iwl_dbgfs_ucode_bt_stats_read(struct file *file,
1464 char __user *user_buf,
1465 size_t count, loff_t *ppos)
1466{
1467 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1468 int pos = 0;
1469 char *buf;
1470 int bufsz = (sizeof(struct statistics_bt_activity) * 24) + 200;
1471 ssize_t ret;
1472 struct statistics_bt_activity *bt, *accum_bt;
1473
Don Fry83626402012-03-07 09:52:37 -08001474 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001475 return -EAGAIN;
1476
1477 if (!priv->bt_enable_flag)
1478 return -EINVAL;
1479
1480 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001481 mutex_lock(&priv->mutex);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001482 ret = iwl_send_statistics_request(priv, 0, false);
Johannes Bergb1eea292012-03-06 13:30:42 -08001483 mutex_unlock(&priv->mutex);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001484
Johannes Bergf9e75442012-03-30 09:37:39 +02001485 if (ret)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001486 return -EAGAIN;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001487 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001488 if (!buf)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001489 return -ENOMEM;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001490
1491 /*
1492 * the statistic information display here is based on
1493 * the last statistics notification from uCode
1494 * might not reflect the current uCode activity
1495 */
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001496
1497 spin_lock_bh(&priv->statistics.lock);
1498
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001499 bt = &priv->statistics.bt_activity;
1500 accum_bt = &priv->accum_stats.bt_activity;
1501
1502 pos += iwl_statistics_flag(priv, buf, bufsz);
1503 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_BT:\n");
1504 pos += scnprintf(buf + pos, bufsz - pos,
1505 "\t\t\tcurrent\t\t\taccumulative\n");
1506 pos += scnprintf(buf + pos, bufsz - pos,
1507 "hi_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1508 le32_to_cpu(bt->hi_priority_tx_req_cnt),
1509 accum_bt->hi_priority_tx_req_cnt);
1510 pos += scnprintf(buf + pos, bufsz - pos,
1511 "hi_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1512 le32_to_cpu(bt->hi_priority_tx_denied_cnt),
1513 accum_bt->hi_priority_tx_denied_cnt);
1514 pos += scnprintf(buf + pos, bufsz - pos,
1515 "lo_priority_tx_req_cnt:\t\t%u\t\t\t%u\n",
1516 le32_to_cpu(bt->lo_priority_tx_req_cnt),
1517 accum_bt->lo_priority_tx_req_cnt);
1518 pos += scnprintf(buf + pos, bufsz - pos,
1519 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
1520 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
1521 accum_bt->lo_priority_tx_denied_cnt);
1522 pos += scnprintf(buf + pos, bufsz - pos,
1523 "hi_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1524 le32_to_cpu(bt->hi_priority_rx_req_cnt),
1525 accum_bt->hi_priority_rx_req_cnt);
1526 pos += scnprintf(buf + pos, bufsz - pos,
1527 "hi_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1528 le32_to_cpu(bt->hi_priority_rx_denied_cnt),
1529 accum_bt->hi_priority_rx_denied_cnt);
1530 pos += scnprintf(buf + pos, bufsz - pos,
1531 "lo_priority_rx_req_cnt:\t\t%u\t\t\t%u\n",
1532 le32_to_cpu(bt->lo_priority_rx_req_cnt),
1533 accum_bt->lo_priority_rx_req_cnt);
1534 pos += scnprintf(buf + pos, bufsz - pos,
1535 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n",
1536 le32_to_cpu(bt->lo_priority_rx_denied_cnt),
1537 accum_bt->lo_priority_rx_denied_cnt);
1538
1539 pos += scnprintf(buf + pos, bufsz - pos,
1540 "(rx)num_bt_kills:\t\t%u\t\t\t%u\n",
1541 le32_to_cpu(priv->statistics.num_bt_kills),
1542 priv->statistics.accum_num_bt_kills);
1543
Johannes Berg4ff70fc2012-03-05 11:24:26 -08001544 spin_unlock_bh(&priv->statistics.lock);
1545
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001546 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1547 kfree(buf);
1548 return ret;
1549}
1550
1551static ssize_t iwl_dbgfs_reply_tx_error_read(struct file *file,
1552 char __user *user_buf,
1553 size_t count, loff_t *ppos)
1554{
1555 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1556 int pos = 0;
1557 char *buf;
1558 int bufsz = (sizeof(struct reply_tx_error_statistics) * 24) +
1559 (sizeof(struct reply_agg_tx_error_statistics) * 24) + 200;
1560 ssize_t ret;
1561
Don Fry83626402012-03-07 09:52:37 -08001562 if (!iwl_is_alive(priv))
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001563 return -EAGAIN;
1564
1565 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001566 if (!buf)
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001567 return -ENOMEM;
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001568
1569 pos += scnprintf(buf + pos, bufsz - pos, "Statistics_TX_Error:\n");
1570 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t\t%u\n",
1571 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_DELAY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001572 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001573 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1574 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_FEW_BYTES),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001575 priv->reply_tx_stats.pp_few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001576 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1577 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_BT_PRIO),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001578 priv->reply_tx_stats.pp_bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001579 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1580 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_QUIET_PERIOD),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001581 priv->reply_tx_stats.pp_quiet_period);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001582 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1583 iwl_get_tx_fail_reason(TX_STATUS_POSTPONE_CALC_TTAK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001584 priv->reply_tx_stats.pp_calc_ttak);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001585 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1586 iwl_get_tx_fail_reason(
1587 TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001588 priv->reply_tx_stats.int_crossed_retry);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001589 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1590 iwl_get_tx_fail_reason(TX_STATUS_FAIL_SHORT_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001591 priv->reply_tx_stats.short_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001592 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1593 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LONG_LIMIT),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001594 priv->reply_tx_stats.long_limit);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001595 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1596 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_UNDERRUN),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001597 priv->reply_tx_stats.fifo_underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001598 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1599 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DRAIN_FLOW),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001600 priv->reply_tx_stats.drain_flow);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001601 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1602 iwl_get_tx_fail_reason(TX_STATUS_FAIL_RFKILL_FLUSH),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001603 priv->reply_tx_stats.rfkill_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001604 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1605 iwl_get_tx_fail_reason(TX_STATUS_FAIL_LIFE_EXPIRE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001606 priv->reply_tx_stats.life_expire);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001607 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1608 iwl_get_tx_fail_reason(TX_STATUS_FAIL_DEST_PS),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001609 priv->reply_tx_stats.dest_ps);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001610 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1611 iwl_get_tx_fail_reason(TX_STATUS_FAIL_HOST_ABORTED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001612 priv->reply_tx_stats.host_abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001613 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1614 iwl_get_tx_fail_reason(TX_STATUS_FAIL_BT_RETRY),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001615 priv->reply_tx_stats.pp_delay);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001616 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1617 iwl_get_tx_fail_reason(TX_STATUS_FAIL_STA_INVALID),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001618 priv->reply_tx_stats.sta_invalid);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001619 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1620 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FRAG_DROPPED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001621 priv->reply_tx_stats.frag_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001622 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1623 iwl_get_tx_fail_reason(TX_STATUS_FAIL_TID_DISABLE),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001624 priv->reply_tx_stats.tid_disable);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001625 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1626 iwl_get_tx_fail_reason(TX_STATUS_FAIL_FIFO_FLUSHED),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001627 priv->reply_tx_stats.fifo_flush);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001628 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1629 iwl_get_tx_fail_reason(
1630 TX_STATUS_FAIL_INSUFFICIENT_CF_POLL),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001631 priv->reply_tx_stats.insuff_cf_poll);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001632 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1633 iwl_get_tx_fail_reason(TX_STATUS_FAIL_PASSIVE_NO_RX),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001634 priv->reply_tx_stats.fail_hw_drop);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001635 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1636 iwl_get_tx_fail_reason(
1637 TX_STATUS_FAIL_NO_BEACON_ON_RADAR),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001638 priv->reply_tx_stats.sta_color_mismatch);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001639 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001640 priv->reply_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001641
1642 pos += scnprintf(buf + pos, bufsz - pos,
1643 "\nStatistics_Agg_TX_Error:\n");
1644
1645 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1646 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_UNDERRUN_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001647 priv->reply_agg_tx_stats.underrun);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001648 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1649 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_BT_PRIO_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001650 priv->reply_agg_tx_stats.bt_prio);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001651 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1652 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_FEW_BYTES_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001653 priv->reply_agg_tx_stats.few_bytes);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001654 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1655 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_ABORT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001656 priv->reply_agg_tx_stats.abort);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001657 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1658 iwl_get_agg_tx_fail_reason(
1659 AGG_TX_STATE_LAST_SENT_TTL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001660 priv->reply_agg_tx_stats.last_sent_ttl);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001661 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1662 iwl_get_agg_tx_fail_reason(
1663 AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001664 priv->reply_agg_tx_stats.last_sent_try);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001665 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1666 iwl_get_agg_tx_fail_reason(
1667 AGG_TX_STATE_LAST_SENT_BT_KILL_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001668 priv->reply_agg_tx_stats.last_sent_bt_kill);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001669 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1670 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_SCD_QUERY_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001671 priv->reply_agg_tx_stats.scd_query);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001672 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t%u\n",
1673 iwl_get_agg_tx_fail_reason(
1674 AGG_TX_STATE_TEST_BAD_CRC32_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001675 priv->reply_agg_tx_stats.bad_crc32);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001676 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1677 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_RESPONSE_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001678 priv->reply_agg_tx_stats.response);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001679 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1680 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DUMP_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001681 priv->reply_agg_tx_stats.dump_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001682 pos += scnprintf(buf + pos, bufsz - pos, "%s:\t\t\t%u\n",
1683 iwl_get_agg_tx_fail_reason(AGG_TX_STATE_DELAY_TX_MSK),
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001684 priv->reply_agg_tx_stats.delay_tx);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001685 pos += scnprintf(buf + pos, bufsz - pos, "UNKNOWN:\t\t\t%u\n",
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001686 priv->reply_agg_tx_stats.unknown);
Wey-Yi Guyd6d023a2011-04-30 09:10:53 -07001687
1688 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1689 kfree(buf);
1690 return ret;
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001691}
1692
Wey-Yi Guy52259352009-08-07 15:41:43 -07001693static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1694 char __user *user_buf,
1695 size_t count, loff_t *ppos) {
1696
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001697 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001698 int pos = 0;
1699 int cnt = 0;
1700 char *buf;
1701 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1702 ssize_t ret;
1703 struct iwl_sensitivity_data *data;
1704
1705 data = &priv->sensitivity_data;
1706 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001707 if (!buf)
Wey-Yi Guy52259352009-08-07 15:41:43 -07001708 return -ENOMEM;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001709
1710 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1711 data->auto_corr_ofdm);
1712 pos += scnprintf(buf + pos, bufsz - pos,
1713 "auto_corr_ofdm_mrc:\t\t %u\n",
1714 data->auto_corr_ofdm_mrc);
1715 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1716 data->auto_corr_ofdm_x1);
1717 pos += scnprintf(buf + pos, bufsz - pos,
1718 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1719 data->auto_corr_ofdm_mrc_x1);
1720 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1721 data->auto_corr_cck);
1722 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1723 data->auto_corr_cck_mrc);
1724 pos += scnprintf(buf + pos, bufsz - pos,
1725 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1726 data->last_bad_plcp_cnt_ofdm);
1727 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1728 data->last_fa_cnt_ofdm);
1729 pos += scnprintf(buf + pos, bufsz - pos,
1730 "last_bad_plcp_cnt_cck:\t\t %u\n",
1731 data->last_bad_plcp_cnt_cck);
1732 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1733 data->last_fa_cnt_cck);
1734 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1735 data->nrg_curr_state);
1736 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1737 data->nrg_prev_state);
1738 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1739 for (cnt = 0; cnt < 10; cnt++) {
1740 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1741 data->nrg_value[cnt]);
1742 }
1743 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1744 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1745 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1746 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1747 data->nrg_silence_rssi[cnt]);
1748 }
1749 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1750 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1751 data->nrg_silence_ref);
1752 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1753 data->nrg_energy_idx);
1754 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1755 data->nrg_silence_idx);
1756 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1757 data->nrg_th_cck);
1758 pos += scnprintf(buf + pos, bufsz - pos,
1759 "nrg_auto_corr_silence_diff:\t %u\n",
1760 data->nrg_auto_corr_silence_diff);
1761 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1762 data->num_in_cck_no_fa);
1763 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1764 data->nrg_th_ofdm);
1765
1766 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1767 kfree(buf);
1768 return ret;
1769}
1770
1771
1772static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1773 char __user *user_buf,
1774 size_t count, loff_t *ppos) {
1775
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001776 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001777 int pos = 0;
1778 int cnt = 0;
1779 char *buf;
1780 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1781 ssize_t ret;
1782 struct iwl_chain_noise_data *data;
1783
1784 data = &priv->chain_noise_data;
1785 buf = kzalloc(bufsz, GFP_KERNEL);
Johannes Bergf9e75442012-03-30 09:37:39 +02001786 if (!buf)
Wey-Yi Guy52259352009-08-07 15:41:43 -07001787 return -ENOMEM;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001788
1789 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1790 data->active_chains);
1791 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1792 data->chain_noise_a);
1793 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1794 data->chain_noise_b);
1795 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1796 data->chain_noise_c);
1797 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1798 data->chain_signal_a);
1799 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1800 data->chain_signal_b);
1801 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1802 data->chain_signal_c);
1803 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1804 data->beacon_count);
1805
1806 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1807 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1808 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1809 data->disconn_array[cnt]);
1810 }
1811 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1812 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1813 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1814 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1815 data->delta_gain_code[cnt]);
1816 }
1817 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1818 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1819 data->radio_write);
1820 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1821 data->state);
1822
1823 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1824 kfree(buf);
1825 return ret;
1826}
1827
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001828static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1829 char __user *user_buf,
1830 size_t count, loff_t *ppos)
1831{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001832 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001833 char buf[60];
1834 int pos = 0;
1835 const size_t bufsz = sizeof(buf);
1836 u32 pwrsave_status;
1837
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -07001838 pwrsave_status = iwl_read32(priv->trans, CSR_GP_CNTRL) &
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001839 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1840
1841 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1842 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1843 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1844 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1845 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1846 "error");
1847
1848 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1849}
1850
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001851static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001852 const char __user *user_buf,
1853 size_t count, loff_t *ppos)
1854{
1855 struct iwl_priv *priv = file->private_data;
1856 char buf[8];
1857 int buf_size;
1858 int clear;
1859
1860 memset(buf, 0, sizeof(buf));
1861 buf_size = min(count, sizeof(buf) - 1);
1862 if (copy_from_user(buf, user_buf, buf_size))
1863 return -EFAULT;
1864 if (sscanf(buf, "%d", &clear) != 1)
1865 return -EFAULT;
1866
1867 /* make request to uCode to retrieve statistics information */
Johannes Bergb1eea292012-03-06 13:30:42 -08001868 mutex_lock(&priv->mutex);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001869 iwl_send_statistics_request(priv, 0, true);
Johannes Bergb1eea292012-03-06 13:30:42 -08001870 mutex_unlock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001871
1872 return count;
1873}
1874
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001875static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1876 char __user *user_buf,
1877 size_t count, loff_t *ppos) {
1878
Joe Perches57674302010-07-12 13:50:06 -07001879 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001880 int pos = 0;
1881 char buf[128];
1882 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001883
1884 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1885 priv->event_log.ucode_trace ? "On" : "Off");
1886 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1887 priv->event_log.non_wraps_count);
1888 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1889 priv->event_log.wraps_once_count);
1890 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1891 priv->event_log.wraps_more_count);
1892
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001893 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001894}
1895
1896static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1897 const char __user *user_buf,
1898 size_t count, loff_t *ppos)
1899{
1900 struct iwl_priv *priv = file->private_data;
1901 char buf[8];
1902 int buf_size;
1903 int trace;
1904
1905 memset(buf, 0, sizeof(buf));
1906 buf_size = min(count, sizeof(buf) - 1);
1907 if (copy_from_user(buf, user_buf, buf_size))
1908 return -EFAULT;
1909 if (sscanf(buf, "%d", &trace) != 1)
1910 return -EFAULT;
1911
1912 if (trace) {
1913 priv->event_log.ucode_trace = true;
Don Fry83626402012-03-07 09:52:37 -08001914 if (iwl_is_alive(priv)) {
Johannes Berg98d4bf02012-01-13 11:56:11 +01001915 /* start collecting data now */
1916 mod_timer(&priv->ucode_trace, jiffies);
1917 }
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001918 } else {
1919 priv->event_log.ucode_trace = false;
1920 del_timer_sync(&priv->ucode_trace);
1921 }
1922
1923 return count;
1924}
1925
Johannes Berg60987202010-02-18 00:36:07 -08001926static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1927 char __user *user_buf,
1928 size_t count, loff_t *ppos) {
1929
Joe Perches57674302010-07-12 13:50:06 -07001930 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08001931 int len = 0;
1932 char buf[20];
1933
Johannes Berg246ed352010-08-23 10:46:32 +02001934 len = sprintf(buf, "0x%04X\n",
1935 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
Johannes Berg60987202010-02-18 00:36:07 -08001936 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1937}
1938
1939static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1940 char __user *user_buf,
1941 size_t count, loff_t *ppos) {
1942
Joe Perches57674302010-07-12 13:50:06 -07001943 struct iwl_priv *priv = file->private_data;
Johannes Berg60987202010-02-18 00:36:07 -08001944 int len = 0;
1945 char buf[20];
1946
1947 len = sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02001948 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
Johannes Berg60987202010-02-18 00:36:07 -08001949 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1950}
1951
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001952static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1953 char __user *user_buf,
1954 size_t count, loff_t *ppos) {
1955
1956 struct iwl_priv *priv = file->private_data;
1957 int pos = 0;
1958 char buf[12];
1959 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001960
1961 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1962 priv->missed_beacon_threshold);
1963
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001964 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001965}
1966
1967static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1968 const char __user *user_buf,
1969 size_t count, loff_t *ppos)
1970{
1971 struct iwl_priv *priv = file->private_data;
1972 char buf[8];
1973 int buf_size;
1974 int missed;
1975
1976 memset(buf, 0, sizeof(buf));
1977 buf_size = min(count, sizeof(buf) - 1);
1978 if (copy_from_user(buf, user_buf, buf_size))
1979 return -EFAULT;
1980 if (sscanf(buf, "%d", &missed) != 1)
1981 return -EINVAL;
1982
1983 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1984 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1985 priv->missed_beacon_threshold =
1986 IWL_MISSED_BEACON_THRESHOLD_DEF;
1987 else
1988 priv->missed_beacon_threshold = missed;
1989
1990 return count;
1991}
1992
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001993static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1994 char __user *user_buf,
1995 size_t count, loff_t *ppos) {
1996
Joe Perches57674302010-07-12 13:50:06 -07001997 struct iwl_priv *priv = file->private_data;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001998 int pos = 0;
1999 char buf[12];
2000 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002001
2002 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
Johannes Bergab5c0f12012-03-06 13:30:53 -08002003 priv->plcp_delta_threshold);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002004
Wey-Yi Guy4967c312010-02-18 15:22:07 -08002005 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002006}
2007
2008static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
2009 const char __user *user_buf,
2010 size_t count, loff_t *ppos) {
2011
2012 struct iwl_priv *priv = file->private_data;
2013 char buf[8];
2014 int buf_size;
2015 int plcp;
2016
2017 memset(buf, 0, sizeof(buf));
2018 buf_size = min(count, sizeof(buf) - 1);
2019 if (copy_from_user(buf, user_buf, buf_size))
2020 return -EFAULT;
2021 if (sscanf(buf, "%d", &plcp) != 1)
2022 return -EINVAL;
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002023 if ((plcp < IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002024 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
Johannes Bergab5c0f12012-03-06 13:30:53 -08002025 priv->plcp_delta_threshold =
Wey-Yi Guy680788a2010-06-17 15:25:00 -07002026 IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002027 else
Johannes Bergab5c0f12012-03-06 13:30:53 -08002028 priv->plcp_delta_threshold = plcp;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002029 return count;
2030}
2031
Johannes Berg48dffd32012-04-09 17:46:57 -07002032static ssize_t iwl_dbgfs_rf_reset_read(struct file *file,
2033 char __user *user_buf,
2034 size_t count, loff_t *ppos)
Johannes Bergca934b62011-09-15 11:46:48 -07002035{
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002036 struct iwl_priv *priv = file->private_data;
Johannes Berg48dffd32012-04-09 17:46:57 -07002037 int pos = 0;
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002038 char buf[300];
2039 const size_t bufsz = sizeof(buf);
Johannes Berg48dffd32012-04-09 17:46:57 -07002040 struct iwl_rf_reset *rf_reset = &priv->rf_reset;
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002041
Johannes Berg48dffd32012-04-09 17:46:57 -07002042 pos += scnprintf(buf + pos, bufsz - pos,
2043 "RF reset statistics\n");
2044 pos += scnprintf(buf + pos, bufsz - pos,
2045 "\tnumber of reset request: %d\n",
2046 rf_reset->reset_request_count);
2047 pos += scnprintf(buf + pos, bufsz - pos,
2048 "\tnumber of reset request success: %d\n",
2049 rf_reset->reset_success_count);
2050 pos += scnprintf(buf + pos, bufsz - pos,
2051 "\tnumber of reset request reject: %d\n",
2052 rf_reset->reset_reject_count);
2053
Wey-Yi Guy528c3122010-02-18 22:03:07 -08002054 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2055}
2056
Johannes Berg48dffd32012-04-09 17:46:57 -07002057static ssize_t iwl_dbgfs_rf_reset_write(struct file *file,
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002058 const char __user *user_buf,
2059 size_t count, loff_t *ppos) {
2060
2061 struct iwl_priv *priv = file->private_data;
Johannes Berg48dffd32012-04-09 17:46:57 -07002062 int ret;
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002063
Johannes Berg48dffd32012-04-09 17:46:57 -07002064 ret = iwl_force_rf_reset(priv, true);
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08002065 return ret ? ret : count;
2066}
2067
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002068static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
2069 const char __user *user_buf,
2070 size_t count, loff_t *ppos) {
2071
2072 struct iwl_priv *priv = file->private_data;
2073 char buf[8];
2074 int buf_size;
2075 int flush;
2076
2077 memset(buf, 0, sizeof(buf));
2078 buf_size = min(count, sizeof(buf) - 1);
2079 if (copy_from_user(buf, user_buf, buf_size))
2080 return -EFAULT;
2081 if (sscanf(buf, "%d", &flush) != 1)
2082 return -EINVAL;
2083
Don Fry83626402012-03-07 09:52:37 -08002084 if (iwl_is_rfkill(priv))
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002085 return -EFAULT;
2086
Johannes Berga4dece92012-10-31 22:21:28 +01002087 iwlagn_dev_txfifo_flush(priv);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002088
2089 return count;
2090}
2091
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002092static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
2093 char __user *user_buf,
2094 size_t count, loff_t *ppos) {
2095
2096 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2097 int pos = 0;
2098 char buf[200];
2099 const size_t bufsz = sizeof(buf);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002100
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002101 if (!priv->bt_enable_flag) {
2102 pos += scnprintf(buf + pos, bufsz - pos, "BT coex disabled\n");
Johannes Berg08960de2011-04-05 09:41:53 -07002103 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf21dd002010-12-08 15:34:52 -08002104 }
2105 pos += scnprintf(buf + pos, bufsz - pos, "BT enable flag: 0x%x\n",
2106 priv->bt_enable_flag);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002107 pos += scnprintf(buf + pos, bufsz - pos, "BT in %s mode\n",
2108 priv->bt_full_concurrent ? "full concurrency" : "3-wire");
2109 pos += scnprintf(buf + pos, bufsz - pos, "BT status: %s, "
2110 "last traffic notif: %d\n",
Wey-Yi Guy66e863a52010-11-08 14:54:37 -08002111 priv->bt_status ? "On" : "Off", priv->last_bt_traffic_load);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002112 pos += scnprintf(buf + pos, bufsz - pos, "ch_announcement: %d, "
Wey-Yi Guy187bc4f2011-01-27 13:01:33 -08002113 "kill_ack_mask: %x, kill_cts_mask: %x\n",
2114 priv->bt_ch_announce, priv->kill_ack_mask,
2115 priv->kill_cts_mask);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002116
2117 pos += scnprintf(buf + pos, bufsz - pos, "bluetooth traffic load: ");
2118 switch (priv->bt_traffic_load) {
2119 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
2120 pos += scnprintf(buf + pos, bufsz - pos, "Continuous\n");
2121 break;
2122 case IWL_BT_COEX_TRAFFIC_LOAD_HIGH:
2123 pos += scnprintf(buf + pos, bufsz - pos, "High\n");
2124 break;
2125 case IWL_BT_COEX_TRAFFIC_LOAD_LOW:
2126 pos += scnprintf(buf + pos, bufsz - pos, "Low\n");
2127 break;
2128 case IWL_BT_COEX_TRAFFIC_LOAD_NONE:
2129 default:
2130 pos += scnprintf(buf + pos, bufsz - pos, "None\n");
2131 break;
2132 }
2133
Johannes Berg08960de2011-04-05 09:41:53 -07002134 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002135}
2136
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002137static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
2138 char __user *user_buf,
2139 size_t count, loff_t *ppos)
2140{
2141 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
2142
2143 int pos = 0;
2144 char buf[40];
2145 const size_t bufsz = sizeof(buf);
2146
Emmanuel Grumbach21522682012-03-22 17:51:44 +02002147 if (priv->cfg->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002148 pos += scnprintf(buf + pos, bufsz - pos,
2149 "use %s for aggregation\n",
Johannes Berg9e295112012-04-09 17:46:55 -07002150 (priv->hw_params.use_rts_for_aggregation) ?
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002151 "rts/cts" : "cts-to-self");
2152 else
2153 pos += scnprintf(buf + pos, bufsz - pos, "N/A");
2154
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002155 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2156}
2157
2158static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
2159 const char __user *user_buf,
2160 size_t count, loff_t *ppos) {
2161
2162 struct iwl_priv *priv = file->private_data;
2163 char buf[8];
2164 int buf_size;
2165 int rts;
2166
Emmanuel Grumbach21522682012-03-22 17:51:44 +02002167 if (!priv->cfg->ht_params)
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002168 return -EINVAL;
2169
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002170 memset(buf, 0, sizeof(buf));
2171 buf_size = min(count, sizeof(buf) - 1);
2172 if (copy_from_user(buf, user_buf, buf_size))
2173 return -EFAULT;
2174 if (sscanf(buf, "%d", &rts) != 1)
2175 return -EINVAL;
2176 if (rts)
Johannes Berg9e295112012-04-09 17:46:55 -07002177 priv->hw_params.use_rts_for_aggregation = true;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002178 else
Johannes Berg9e295112012-04-09 17:46:55 -07002179 priv->hw_params.use_rts_for_aggregation = false;
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002180 return count;
2181}
2182
Johannes Bergc98c8d92012-04-02 15:15:58 +02002183static int iwl_cmd_echo_test(struct iwl_priv *priv)
2184{
2185 int ret;
2186 struct iwl_host_cmd cmd = {
2187 .id = REPLY_ECHO,
2188 .len = { 0 },
Johannes Bergc98c8d92012-04-02 15:15:58 +02002189 };
2190
2191 ret = iwl_dvm_send_cmd(priv, &cmd);
2192 if (ret)
2193 IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
2194 else
2195 IWL_DEBUG_INFO(priv, "echo testing pass\n");
2196 return ret;
2197}
2198
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002199static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
2200 const char __user *user_buf,
2201 size_t count, loff_t *ppos)
2202{
2203 struct iwl_priv *priv = file->private_data;
2204 char buf[8];
2205 int buf_size;
2206
2207 memset(buf, 0, sizeof(buf));
2208 buf_size = min(count, sizeof(buf) - 1);
2209 if (copy_from_user(buf, user_buf, buf_size))
2210 return -EFAULT;
2211
2212 iwl_cmd_echo_test(priv);
2213 return count;
2214}
2215
Johannes Berg882b7b72012-06-20 08:46:25 +02002216#ifdef CONFIG_IWLWIFI_DEBUG
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002217static ssize_t iwl_dbgfs_log_event_read(struct file *file,
2218 char __user *user_buf,
2219 size_t count, loff_t *ppos)
2220{
2221 struct iwl_priv *priv = file->private_data;
Stanislaw Gruszka3309ccf2013-04-16 15:38:29 +02002222 char *buf = NULL;
2223 ssize_t ret;
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002224
Stanislaw Gruszkaa6db0062013-04-16 15:40:54 +02002225 ret = iwl_dump_nic_event_log(priv, true, &buf);
Stanislaw Gruszkad5578942013-04-17 08:23:50 +02002226 if (ret > 0)
2227 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
Stanislaw Gruszka3309ccf2013-04-16 15:38:29 +02002228 kfree(buf);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002229 return ret;
2230}
2231
2232static ssize_t iwl_dbgfs_log_event_write(struct file *file,
2233 const char __user *user_buf,
2234 size_t count, loff_t *ppos)
2235{
2236 struct iwl_priv *priv = file->private_data;
2237 u32 event_log_flag;
2238 char buf[8];
2239 int buf_size;
2240
Richard A. Griffiths0ff1bd32012-06-28 13:14:11 -07002241 /* check that the interface is up */
2242 if (!iwl_is_ready(priv))
2243 return -EAGAIN;
2244
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002245 memset(buf, 0, sizeof(buf));
2246 buf_size = min(count, sizeof(buf) - 1);
2247 if (copy_from_user(buf, user_buf, buf_size))
2248 return -EFAULT;
2249 if (sscanf(buf, "%d", &event_log_flag) != 1)
2250 return -EFAULT;
2251 if (event_log_flag == 1)
Stanislaw Gruszkaa6db0062013-04-16 15:40:54 +02002252 iwl_dump_nic_event_log(priv, true, NULL);
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002253
2254 return count;
2255}
Johannes Berg882b7b72012-06-20 08:46:25 +02002256#endif
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002257
Dor Shaishbfb45f52012-03-26 08:20:55 -07002258static ssize_t iwl_dbgfs_calib_disabled_read(struct file *file,
2259 char __user *user_buf,
2260 size_t count, loff_t *ppos)
2261{
2262 struct iwl_priv *priv = file->private_data;
2263 char buf[120];
2264 int pos = 0;
2265 const size_t bufsz = sizeof(buf);
2266
2267 pos += scnprintf(buf + pos, bufsz - pos,
2268 "Sensitivity calibrations %s\n",
2269 (priv->calib_disabled &
2270 IWL_SENSITIVITY_CALIB_DISABLED) ?
2271 "DISABLED" : "ENABLED");
2272 pos += scnprintf(buf + pos, bufsz - pos,
2273 "Chain noise calibrations %s\n",
2274 (priv->calib_disabled &
2275 IWL_CHAIN_NOISE_CALIB_DISABLED) ?
2276 "DISABLED" : "ENABLED");
2277 pos += scnprintf(buf + pos, bufsz - pos,
2278 "Tx power calibrations %s\n",
2279 (priv->calib_disabled &
2280 IWL_TX_POWER_CALIB_DISABLED) ?
2281 "DISABLED" : "ENABLED");
2282
2283 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
2284}
2285
David Spinadel647ad132012-03-31 08:31:05 -07002286static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
2287 const char __user *user_buf,
2288 size_t count, loff_t *ppos)
2289{
2290 struct iwl_priv *priv = file->private_data;
2291 char buf[8];
2292 u32 calib_disabled;
2293 int buf_size;
2294
2295 memset(buf, 0, sizeof(buf));
2296 buf_size = min(count, sizeof(buf) - 1);
2297 if (copy_from_user(buf, user_buf, buf_size))
2298 return -EFAULT;
2299 if (sscanf(buf, "%x", &calib_disabled) != 1)
2300 return -EFAULT;
2301
2302 priv->calib_disabled = calib_disabled;
2303
2304 return count;
2305}
2306
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02002307static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
2308 const char __user *user_buf,
2309 size_t count, loff_t *ppos)
2310{
2311 struct iwl_priv *priv = file->private_data;
2312 bool restart_fw = iwlwifi_mod_params.restart_fw;
Luca Coelhoa43ae1d2016-11-09 09:45:58 +02002313 int __maybe_unused ret;
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02002314
2315 iwlwifi_mod_params.restart_fw = true;
2316
2317 mutex_lock(&priv->mutex);
2318
2319 /* take the return value to make compiler happy - it will fail anyway */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002320 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_ERROR, 0, 0, NULL);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02002321
2322 mutex_unlock(&priv->mutex);
2323
2324 iwlwifi_mod_params.restart_fw = restart_fw;
2325
2326 return count;
2327}
2328
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07002329DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
2330DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
2331DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07002332DEBUGFS_READ_FILE_OPS(sensitivity);
2333DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07002334DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08002335DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08002336DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08002337DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08002338DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Johannes Berg48dffd32012-04-09 17:46:57 -07002339DEBUGFS_READ_WRITE_FILE_OPS(rf_reset);
Johannes Berg60987202010-02-18 00:36:07 -08002340DEBUGFS_READ_FILE_OPS(rxon_flags);
2341DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy4bf49a92010-06-24 13:18:36 -07002342DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
Wey-Yi Guyffb7d892010-07-14 08:09:55 -07002343DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002344DEBUGFS_READ_FILE_OPS(bt_traffic);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002345DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002346DEBUGFS_READ_FILE_OPS(reply_tx_error);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002347DEBUGFS_WRITE_FILE_OPS(echo_test);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02002348DEBUGFS_WRITE_FILE_OPS(fw_restart);
Johannes Berg882b7b72012-06-20 08:46:25 +02002349#ifdef CONFIG_IWLWIFI_DEBUG
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002350DEBUGFS_READ_WRITE_FILE_OPS(log_event);
Johannes Berg882b7b72012-06-20 08:46:25 +02002351#endif
David Spinadel647ad132012-03-31 08:31:05 -07002352DEBUGFS_READ_WRITE_FILE_OPS(calib_disabled);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002353
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002354/*
2355 * Create the debugfs files and directories
2356 *
2357 */
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002358int iwl_dbgfs_register(struct iwl_priv *priv, struct dentry *dbgfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002359{
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002360 struct dentry *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002361
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002362 priv->debugfs_dir = dbgfs_dir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002363
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002364 dir_data = debugfs_create_dir("data", dbgfs_dir);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002365 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002366 goto err;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002367 dir_rf = debugfs_create_dir("rf", dbgfs_dir);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002368 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002369 goto err;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002370 dir_debug = debugfs_create_dir("debug", dbgfs_dir);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002371 if (!dir_debug)
2372 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002373
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002374 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
2375 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002376 DEBUGFS_ADD_FILE(wowlan_sram, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002377 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
2378 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
2379 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
Emmanuel Grumbach1f7b6172011-08-25 23:10:59 -07002380 DEBUGFS_ADD_FILE(rx_handlers, dir_data, S_IWUSR | S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002381 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002382 DEBUGFS_ADD_FILE(sleep_level_override, dir_data, S_IWUSR | S_IRUSR);
2383 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002384 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
2385 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
Emmanuel Grumbach511afa32011-09-22 07:15:37 -07002386 DEBUGFS_ADD_FILE(temperature, dir_data, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002387
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002388 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
2389 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002390 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002391 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg48dffd32012-04-09 17:46:57 -07002392 DEBUGFS_ADD_FILE(rf_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07002393 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
2394 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
2395 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07002396 DEBUGFS_ADD_FILE(txfifo_flush, dir_debug, S_IWUSR);
Wey-Yi Guyc6abdc02010-09-01 17:10:51 -07002397 DEBUGFS_ADD_FILE(protection_mode, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy703bc582011-04-03 08:14:41 -07002398 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
2399 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guyb7af6a92011-04-06 15:55:25 -07002400 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002401 DEBUGFS_ADD_FILE(ucode_bt_stats, dir_debug, S_IRUSR);
Wey-Yi Guy54a9aa62010-09-05 10:49:42 -07002402 DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08002403 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
2404 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Wey-Yi Guy7e4005c2011-10-10 07:26:51 -07002405 DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
Emmanuel Grumbach490953a2013-03-04 08:53:07 +02002406 DEBUGFS_ADD_FILE(fw_restart, dir_debug, S_IWUSR);
Johannes Berg882b7b72012-06-20 08:46:25 +02002407#ifdef CONFIG_IWLWIFI_DEBUG
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002408 DEBUGFS_ADD_FILE(log_event, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg882b7b72012-06-20 08:46:25 +02002409#endif
Meenakshi Venkataraman2fdfc472012-03-15 13:26:56 -07002410
Stanislaw Gruszka88e58fc2011-01-28 16:47:47 +01002411 if (iwl_advanced_bt_coexist(priv))
Wey-Yi Guybefe8c42010-08-23 07:57:16 -07002412 DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
Johannes Bergca934b62011-09-15 11:46:48 -07002413
Dor Shaishbfb45f52012-03-26 08:20:55 -07002414 /* Calibrations disabled/enabled status*/
David Spinadel647ad132012-03-31 08:31:05 -07002415 DEBUGFS_ADD_FILE(calib_disabled, dir_rf, S_IWUSR | S_IRUSR);
Emmanuel Grumbach87e56662011-08-25 23:10:50 -07002416
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002417 /*
2418 * Create a symlink with mac80211. This is not very robust, as it does
2419 * not remove the symlink created. The implicit assumption is that
2420 * when the opmode exits, mac80211 will also exit, and will remove
2421 * this symlink as part of its cleanup.
2422 */
2423 if (priv->mac80211_registered) {
2424 char buf[100];
Al Viro27a22092016-08-07 12:21:25 -04002425 struct dentry *mac80211_dir, *dev_dir;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002426
2427 dev_dir = dbgfs_dir->d_parent;
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002428 mac80211_dir = priv->hw->wiphy->debugfsdir;
2429
Al Viro27a22092016-08-07 12:21:25 -04002430 snprintf(buf, 100, "../../%pd2", dev_dir);
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002431
2432 if (!debugfs_create_symlink("iwlwifi", mac80211_dir, buf))
2433 goto err;
2434 }
2435
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002436 return 0;
2437
2438err:
Meenakshi Venkataraman9da987a2012-07-16 18:43:56 -07002439 IWL_ERR(priv, "failed to create the dvm debugfs entries\n");
Johannes Berg4c84a8f2010-01-22 14:22:54 -08002440 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07002441}