blob: 9793050e715a6b621f20d63d4e5e7fbe8f825d98 [file] [log] [blame]
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
Reinette Chatre1f447802010-01-15 13:43:41 -08005 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
Tomas Winkler712b6cf2008-03-12 16:58:52 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winkler712b6cf2008-03-12 16:58:52 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
Tomas Winkler712b6cf2008-03-12 16:58:52 -070028#include <linux/ieee80211.h>
29#include <net/mac80211.h>
30
31
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070032#include "iwl-dev.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070033#include "iwl-debug.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070034#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070035#include "iwl-io.h"
Wey-Yi Guy52259352009-08-07 15:41:43 -070036#include "iwl-calib.h"
Tomas Winkler712b6cf2008-03-12 16:58:52 -070037
38/* create and remove of files */
Johannes Berg4c84a8f2010-01-22 14:22:54 -080039#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
40 if (!debugfs_create_file(#name, mode, parent, priv, \
41 &iwl_dbgfs_##name##_ops)) \
42 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070043} while (0)
44
Johannes Berg4c84a8f2010-01-22 14:22:54 -080045#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
46 struct dentry *__tmp; \
47 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
48 parent, ptr); \
49 if (IS_ERR(__tmp) || !__tmp) \
50 goto err; \
Tomas Winkler712b6cf2008-03-12 16:58:52 -070051} while (0)
52
Johannes Berg4c84a8f2010-01-22 14:22:54 -080053#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
54 struct dentry *__tmp; \
55 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
56 parent, ptr); \
57 if (IS_ERR(__tmp) || !__tmp) \
58 goto err; \
Tomas Winkler445c2df2008-05-15 13:54:16 +080059} while (0)
60
Tomas Winkler712b6cf2008-03-12 16:58:52 -070061/* file operation */
62#define DEBUGFS_READ_FUNC(name) \
63static ssize_t iwl_dbgfs_##name##_read(struct file *file, \
64 char __user *user_buf, \
65 size_t count, loff_t *ppos);
66
67#define DEBUGFS_WRITE_FUNC(name) \
68static ssize_t iwl_dbgfs_##name##_write(struct file *file, \
69 const char __user *user_buf, \
70 size_t count, loff_t *ppos);
71
72
73static int iwl_dbgfs_open_file_generic(struct inode *inode, struct file *file)
74{
75 file->private_data = inode->i_private;
76 return 0;
77}
78
79#define DEBUGFS_READ_FILE_OPS(name) \
80 DEBUGFS_READ_FUNC(name); \
81static const struct file_operations iwl_dbgfs_##name##_ops = { \
82 .read = iwl_dbgfs_##name##_read, \
83 .open = iwl_dbgfs_open_file_generic, \
84};
85
Ester Kummer189a2b52008-05-15 13:54:18 +080086#define DEBUGFS_WRITE_FILE_OPS(name) \
87 DEBUGFS_WRITE_FUNC(name); \
88static const struct file_operations iwl_dbgfs_##name##_ops = { \
89 .write = iwl_dbgfs_##name##_write, \
90 .open = iwl_dbgfs_open_file_generic, \
91};
92
93
Tomas Winkler712b6cf2008-03-12 16:58:52 -070094#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
95 DEBUGFS_READ_FUNC(name); \
96 DEBUGFS_WRITE_FUNC(name); \
97static const struct file_operations iwl_dbgfs_##name##_ops = { \
98 .write = iwl_dbgfs_##name##_write, \
99 .read = iwl_dbgfs_##name##_read, \
100 .open = iwl_dbgfs_open_file_generic, \
101};
102
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700103static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
104 char __user *user_buf,
105 size_t count, loff_t *ppos) {
106
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700107 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700108 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700109 int pos = 0;
110
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700111 int cnt;
112 ssize_t ret;
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800113 const size_t bufsz = 100 +
114 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700115 buf = kzalloc(bufsz, GFP_KERNEL);
116 if (!buf)
117 return -ENOMEM;
118 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
119 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
120 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800121 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700122 get_mgmt_string(cnt),
123 priv->tx_stats.mgmt[cnt]);
124 }
125 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
126 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
127 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800128 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700129 get_ctrl_string(cnt),
130 priv->tx_stats.ctrl[cnt]);
131 }
132 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
133 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
134 priv->tx_stats.data_cnt);
135 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
136 priv->tx_stats.data_bytes);
137 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
138 kfree(buf);
139 return ret;
140}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700141
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800142static ssize_t iwl_dbgfs_clear_traffic_statistics_write(struct file *file,
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700143 const char __user *user_buf,
144 size_t count, loff_t *ppos)
145{
146 struct iwl_priv *priv = file->private_data;
147 u32 clear_flag;
148 char buf[8];
149 int buf_size;
150
151 memset(buf, 0, sizeof(buf));
152 buf_size = min(count, sizeof(buf) - 1);
153 if (copy_from_user(buf, user_buf, buf_size))
154 return -EFAULT;
155 if (sscanf(buf, "%x", &clear_flag) != 1)
156 return -EFAULT;
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -0800157 iwl_clear_traffic_stats(priv);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700158
159 return count;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700160}
161
162static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
163 char __user *user_buf,
164 size_t count, loff_t *ppos) {
165
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700166 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700167 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700168 int pos = 0;
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700169 int cnt;
170 ssize_t ret;
171 const size_t bufsz = 100 +
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800172 sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700173 buf = kzalloc(bufsz, GFP_KERNEL);
174 if (!buf)
175 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700176
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700177 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
178 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
179 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800180 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700181 get_mgmt_string(cnt),
182 priv->rx_stats.mgmt[cnt]);
183 }
184 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
185 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
186 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guy98a7b432009-11-13 11:56:31 -0800187 "\t%25s\t\t: %u\n",
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700188 get_ctrl_string(cnt),
189 priv->rx_stats.ctrl[cnt]);
190 }
191 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
192 pos += scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
193 priv->rx_stats.data_cnt);
194 pos += scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
195 priv->rx_stats.data_bytes);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700196
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700197 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
198 kfree(buf);
199 return ret;
200}
201
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700202#define BYTE1_MASK 0x000000ff;
203#define BYTE2_MASK 0x0000ffff;
204#define BYTE3_MASK 0x00ffffff;
205static ssize_t iwl_dbgfs_sram_read(struct file *file,
206 char __user *user_buf,
207 size_t count, loff_t *ppos)
208{
209 u32 val;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800210 char *buf;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700211 ssize_t ret;
212 int i;
213 int pos = 0;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700214 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800215 size_t bufsz;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700216
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800217 /* default is to dump the entire data segment */
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800218 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
219 priv->dbgfs_sram_offset = 0x800000;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800220 if (priv->ucode_type == UCODE_INIT)
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800221 priv->dbgfs_sram_len = priv->ucode_init_data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800222 else
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800223 priv->dbgfs_sram_len = priv->ucode_data.len;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800224 }
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800225 bufsz = 30 + priv->dbgfs_sram_len * sizeof(char) * 10;
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800226 buf = kmalloc(bufsz, GFP_KERNEL);
227 if (!buf)
228 return -ENOMEM;
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800229 pos += scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800230 priv->dbgfs_sram_len);
Wey-Yi Guy5ade1e42009-11-20 12:05:04 -0800231 pos += scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800232 priv->dbgfs_sram_offset);
233 for (i = priv->dbgfs_sram_len; i > 0; i -= 4) {
234 val = iwl_read_targ_mem(priv, priv->dbgfs_sram_offset + \
235 priv->dbgfs_sram_len - i);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700236 if (i < 4) {
237 switch (i) {
238 case 1:
239 val &= BYTE1_MASK;
240 break;
241 case 2:
242 val &= BYTE2_MASK;
243 break;
244 case 3:
245 val &= BYTE3_MASK;
246 break;
247 }
248 }
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800249 if (!(i % 16))
250 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700251 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700252 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700253 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700254
255 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy2943f132009-11-20 12:05:00 -0800256 kfree(buf);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700257 return ret;
258}
259
260static ssize_t iwl_dbgfs_sram_write(struct file *file,
261 const char __user *user_buf,
262 size_t count, loff_t *ppos)
263{
264 struct iwl_priv *priv = file->private_data;
265 char buf[64];
266 int buf_size;
267 u32 offset, len;
268
269 memset(buf, 0, sizeof(buf));
270 buf_size = min(count, sizeof(buf) - 1);
271 if (copy_from_user(buf, user_buf, buf_size))
272 return -EFAULT;
273
274 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800275 priv->dbgfs_sram_offset = offset;
276 priv->dbgfs_sram_len = len;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700277 } else {
Johannes Berg4c84a8f2010-01-22 14:22:54 -0800278 priv->dbgfs_sram_offset = 0;
279 priv->dbgfs_sram_len = 0;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700280 }
281
282 return count;
283}
284
285static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
286 size_t count, loff_t *ppos)
287{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700288 struct iwl_priv *priv = file->private_data;
Tomas Winkler6def9762008-05-05 10:22:31 +0800289 struct iwl_station_entry *station;
Tomas Winkler5425e492008-04-15 16:01:38 -0700290 int max_sta = priv->hw_params.max_stations;
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700291 char *buf;
292 int i, j, pos = 0;
293 ssize_t ret;
294 /* Add 30 for initial string */
295 const size_t bufsz = 30 + sizeof(char) * 500 * (priv->num_stations);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700296
297 buf = kmalloc(bufsz, GFP_KERNEL);
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300298 if (!buf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700299 return -ENOMEM;
300
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700301 pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700302 priv->num_stations);
303
304 for (i = 0; i < max_sta; i++) {
305 station = &priv->stations[i];
306 if (station->used) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700307 pos += scnprintf(buf + pos, bufsz - pos,
308 "station %d:\ngeneral data:\n", i+1);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700309 pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700310 station->sta.sta.sta_id);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700311 pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700312 station->sta.mode);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700313 pos += scnprintf(buf + pos, bufsz - pos,
314 "flags: 0x%x\n",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700315 station->sta.station_flags_msk);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700316 pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
317 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700318 "seq_num\t\ttxq_id");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700319 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700320 "\tframe_count\twait_for_ba\t");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700321 pos += scnprintf(buf + pos, bufsz - pos,
322 "start_idx\tbitmap0\t");
323 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700324 "bitmap1\trate_n_flags");
David S. Miller344234d2008-04-19 18:09:39 -0700325 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700326
327 for (j = 0; j < MAX_TID_COUNT; j++) {
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700328 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700329 "[%d]:\t\t%u", j,
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700330 station->tid[j].seq_number);
331 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700332 "\t%u\t\t%u\t\t%u\t\t",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700333 station->tid[j].agg.txq_id,
334 station->tid[j].agg.frame_count,
335 station->tid[j].agg.wait_for_ba);
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700336 pos += scnprintf(buf + pos, bufsz - pos,
David S. Miller344234d2008-04-19 18:09:39 -0700337 "%u\t%llu\t%u",
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700338 station->tid[j].agg.start_idx,
John W. Linville16788592008-04-01 20:59:32 -0400339 (unsigned long long)station->tid[j].agg.bitmap,
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700340 station->tid[j].agg.rate_n_flags);
David S. Miller344234d2008-04-19 18:09:39 -0700341 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700342 }
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700343 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700344 }
345 }
346
347 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
348 kfree(buf);
349 return ret;
350}
351
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700352static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800353 char __user *user_buf,
354 size_t count,
355 loff_t *ppos)
356{
357 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700358 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800359 int pos = 0, ofs = 0, buf_size = 0;
360 const u8 *ptr;
361 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700362 u16 eeprom_ver;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800363 size_t eeprom_len = priv->cfg->eeprom_size;
364 buf_size = 4 * eeprom_len + 256;
365
366 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700367 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800368 return -ENODATA;
369 }
370
Julia Lawallc37457e2009-08-03 11:11:45 +0200371 ptr = priv->eeprom;
372 if (!ptr) {
373 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
374 return -ENOMEM;
375 }
376
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800377 /* 4 characters for byte 0xYY */
378 buf = kzalloc(buf_size, GFP_KERNEL);
379 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800380 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800381 return -ENOMEM;
382 }
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700383 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
384 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
385 "version: 0x%x\n",
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700386 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700387 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800388 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
389 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
390 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
391 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700392 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800393 if (buf_size - pos > 0)
394 buf[pos++] = '\n';
395 }
396
397 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
398 kfree(buf);
399 return ret;
400}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700401
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800402static ssize_t iwl_dbgfs_log_event_read(struct file *file,
403 char __user *user_buf,
404 size_t count, loff_t *ppos)
405{
406 struct iwl_priv *priv = file->private_data;
407 char *buf;
408 int pos = 0;
409 ssize_t ret = -ENOMEM;
410
Wey-Yi Guy937c3972010-01-15 13:43:36 -0800411 ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
412 priv, true, &buf, true);
413 if (buf) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800414 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
415 kfree(buf);
416 }
417 return ret;
418}
419
Ester Kummer189a2b52008-05-15 13:54:18 +0800420static ssize_t iwl_dbgfs_log_event_write(struct file *file,
421 const char __user *user_buf,
422 size_t count, loff_t *ppos)
423{
424 struct iwl_priv *priv = file->private_data;
425 u32 event_log_flag;
426 char buf[8];
427 int buf_size;
428
429 memset(buf, 0, sizeof(buf));
430 buf_size = min(count, sizeof(buf) - 1);
431 if (copy_from_user(buf, user_buf, buf_size))
432 return -EFAULT;
433 if (sscanf(buf, "%d", &event_log_flag) != 1)
434 return -EFAULT;
435 if (event_log_flag == 1)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800436 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
437 NULL, false);
Ester Kummer189a2b52008-05-15 13:54:18 +0800438
439 return count;
440}
441
Winkler, Tomasd366df52008-12-02 12:14:01 -0800442
443
444static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
445 size_t count, loff_t *ppos)
446{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700447 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800448 struct ieee80211_channel *channels = NULL;
449 const struct ieee80211_supported_band *supp_band = NULL;
450 int pos = 0, i, bufsz = PAGE_SIZE;
451 char *buf;
452 ssize_t ret;
453
454 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
455 return -EAGAIN;
456
457 buf = kzalloc(bufsz, GFP_KERNEL);
458 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800459 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800460 return -ENOMEM;
461 }
462
463 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700464 if (supp_band) {
465 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800466
Winkler, Tomasd366df52008-12-02 12:14:01 -0800467 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700468 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
469 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800470
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700471 for (i = 0; i < supp_band->n_channels; i++)
472 pos += scnprintf(buf + pos, bufsz - pos,
473 "%d: %ddBm: BSS%s%s, %s.\n",
474 ieee80211_frequency_to_channel(
475 channels[i].center_freq),
476 channels[i].max_power,
477 channels[i].flags & IEEE80211_CHAN_RADAR ?
478 " (IEEE 802.11h required)" : "",
479 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
480 || (channels[i].flags &
481 IEEE80211_CHAN_RADAR)) ? "" :
482 ", IBSS",
483 channels[i].flags &
484 IEEE80211_CHAN_PASSIVE_SCAN ?
485 "passive only" : "active/passive");
486 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800487 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700488 if (supp_band) {
489 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800490
Winkler, Tomasd366df52008-12-02 12:14:01 -0800491 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700492 "Displaying %d channels in 5.2GHz band (802.11a)\n",
493 supp_band->n_channels);
494
495 for (i = 0; i < supp_band->n_channels; i++)
496 pos += scnprintf(buf + pos, bufsz - pos,
497 "%d: %ddBm: BSS%s%s, %s.\n",
498 ieee80211_frequency_to_channel(
499 channels[i].center_freq),
500 channels[i].max_power,
501 channels[i].flags & IEEE80211_CHAN_RADAR ?
502 " (IEEE 802.11h required)" : "",
503 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
504 || (channels[i].flags &
505 IEEE80211_CHAN_RADAR)) ? "" :
506 ", IBSS",
507 channels[i].flags &
508 IEEE80211_CHAN_PASSIVE_SCAN ?
509 "passive only" : "active/passive");
510 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800511 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
512 kfree(buf);
513 return ret;
514}
515
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700516static ssize_t iwl_dbgfs_status_read(struct file *file,
517 char __user *user_buf,
518 size_t count, loff_t *ppos) {
519
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700520 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700521 char buf[512];
522 int pos = 0;
523 const size_t bufsz = sizeof(buf);
524
525 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
526 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
528 test_bit(STATUS_INT_ENABLED, &priv->status));
529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
530 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
532 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
534 test_bit(STATUS_INIT, &priv->status));
535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
536 test_bit(STATUS_ALIVE, &priv->status));
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
538 test_bit(STATUS_READY, &priv->status));
539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
540 test_bit(STATUS_TEMPERATURE, &priv->status));
541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
542 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
544 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
546 test_bit(STATUS_STATISTICS, &priv->status));
547 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
548 test_bit(STATUS_SCANNING, &priv->status));
549 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
550 test_bit(STATUS_SCAN_ABORTING, &priv->status));
551 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
552 test_bit(STATUS_SCAN_HW, &priv->status));
553 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
554 test_bit(STATUS_POWER_PMI, &priv->status));
555 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
556 test_bit(STATUS_FW_ERROR, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700557 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
558}
559
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700560static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
561 char __user *user_buf,
562 size_t count, loff_t *ppos) {
563
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700564 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700565 int pos = 0;
566 int cnt = 0;
567 char *buf;
568 int bufsz = 24 * 64; /* 24 items * 64 char per item */
569 ssize_t ret;
570
571 buf = kzalloc(bufsz, GFP_KERNEL);
572 if (!buf) {
573 IWL_ERR(priv, "Can not allocate Buffer\n");
574 return -ENOMEM;
575 }
576
577 pos += scnprintf(buf + pos, bufsz - pos,
578 "Interrupt Statistics Report:\n");
579
580 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
581 priv->isr_stats.hw);
582 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
583 priv->isr_stats.sw);
584 if (priv->isr_stats.sw > 0) {
585 pos += scnprintf(buf + pos, bufsz - pos,
586 "\tLast Restarting Code: 0x%X\n",
587 priv->isr_stats.sw_err);
588 }
589#ifdef CONFIG_IWLWIFI_DEBUG
590 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
591 priv->isr_stats.sch);
592 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
593 priv->isr_stats.alive);
594#endif
595 pos += scnprintf(buf + pos, bufsz - pos,
596 "HW RF KILL switch toggled:\t %u\n",
597 priv->isr_stats.rfkill);
598
599 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
600 priv->isr_stats.ctkill);
601
602 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
603 priv->isr_stats.wakeup);
604
605 pos += scnprintf(buf + pos, bufsz - pos,
606 "Rx command responses:\t\t %u\n",
607 priv->isr_stats.rx);
608 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
609 if (priv->isr_stats.rx_handlers[cnt] > 0)
610 pos += scnprintf(buf + pos, bufsz - pos,
611 "\tRx handler[%36s]:\t\t %u\n",
612 get_cmd_string(cnt),
613 priv->isr_stats.rx_handlers[cnt]);
614 }
615
616 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
617 priv->isr_stats.tx);
618
619 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
620 priv->isr_stats.unhandled);
621
622 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
623 kfree(buf);
624 return ret;
625}
626
627static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
628 const char __user *user_buf,
629 size_t count, loff_t *ppos)
630{
631 struct iwl_priv *priv = file->private_data;
632 char buf[8];
633 int buf_size;
634 u32 reset_flag;
635
636 memset(buf, 0, sizeof(buf));
637 buf_size = min(count, sizeof(buf) - 1);
638 if (copy_from_user(buf, user_buf, buf_size))
639 return -EFAULT;
640 if (sscanf(buf, "%x", &reset_flag) != 1)
641 return -EFAULT;
642 if (reset_flag == 0)
643 iwl_clear_isr_stats(priv);
644
645 return count;
646}
647
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700648static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
649 size_t count, loff_t *ppos)
650{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700651 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700652 int pos = 0, i;
653 char buf[256];
654 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700655
656 for (i = 0; i < AC_NUM; i++) {
657 pos += scnprintf(buf + pos, bufsz - pos,
658 "\tcw_min\tcw_max\taifsn\ttxop\n");
659 pos += scnprintf(buf + pos, bufsz - pos,
660 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
661 priv->qos_data.def_qos_parm.ac[i].cw_min,
662 priv->qos_data.def_qos_parm.ac[i].cw_max,
663 priv->qos_data.def_qos_parm.ac[i].aifsn,
664 priv->qos_data.def_qos_parm.ac[i].edca_txop);
665 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800666 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700667}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700668
Wey-Yi Guya283c012009-07-17 09:30:19 -0700669static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
670 size_t count, loff_t *ppos)
671{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700672 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya283c012009-07-17 09:30:19 -0700673 int pos = 0;
674 char buf[256];
675 const size_t bufsz = sizeof(buf);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700676
677 pos += scnprintf(buf + pos, bufsz - pos,
678 "allow blinking: %s\n",
679 (priv->allow_blinking) ? "True" : "False");
680 if (priv->allow_blinking) {
681 pos += scnprintf(buf + pos, bufsz - pos,
682 "Led blinking rate: %u\n",
683 priv->last_blink_rate);
684 pos += scnprintf(buf + pos, bufsz - pos,
685 "Last blink time: %lu\n",
686 priv->last_blink_time);
687 }
688
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800689 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700690}
Wey-Yi Guya283c012009-07-17 09:30:19 -0700691
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700692static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
693 char __user *user_buf,
694 size_t count, loff_t *ppos)
695{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700696 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700697 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700698 struct iwl_tt_restriction *restriction;
699 char buf[100];
700 int pos = 0;
701 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700702
703 pos += scnprintf(buf + pos, bufsz - pos,
704 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700705 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700706 pos += scnprintf(buf + pos, bufsz - pos,
707 "Thermal Throttling State: %d\n",
708 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700709 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700710 restriction = tt->restriction + tt->state;
711 pos += scnprintf(buf + pos, bufsz - pos,
712 "Tx mode: %d\n",
713 restriction->tx_stream);
714 pos += scnprintf(buf + pos, bufsz - pos,
715 "Rx mode: %d\n",
716 restriction->rx_stream);
717 pos += scnprintf(buf + pos, bufsz - pos,
718 "HT mode: %d\n",
719 restriction->is_ht);
720 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800721 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700722}
723
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700724static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
725 const char __user *user_buf,
726 size_t count, loff_t *ppos)
727{
728 struct iwl_priv *priv = file->private_data;
729 char buf[8];
730 int buf_size;
731 int ht40;
732
733 memset(buf, 0, sizeof(buf));
734 buf_size = min(count, sizeof(buf) - 1);
735 if (copy_from_user(buf, user_buf, buf_size))
736 return -EFAULT;
737 if (sscanf(buf, "%d", &ht40) != 1)
738 return -EFAULT;
739 if (!iwl_is_associated(priv))
740 priv->disable_ht40 = ht40 ? true : false;
741 else {
742 IWL_ERR(priv, "Sta associated with AP - "
743 "Change to 40MHz channel support is not allowed\n");
744 return -EINVAL;
745 }
746
747 return count;
748}
749
750static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
751 char __user *user_buf,
752 size_t count, loff_t *ppos)
753{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700754 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700755 char buf[100];
756 int pos = 0;
757 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700758
759 pos += scnprintf(buf + pos, bufsz - pos,
760 "11n 40MHz Mode: %s\n",
761 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800762 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700763}
764
Johannes Berge312c242009-08-07 15:41:51 -0700765static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
766 const char __user *user_buf,
767 size_t count, loff_t *ppos)
768{
769 struct iwl_priv *priv = file->private_data;
770 char buf[8];
771 int buf_size;
772 int value;
773
774 memset(buf, 0, sizeof(buf));
775 buf_size = min(count, sizeof(buf) - 1);
776 if (copy_from_user(buf, user_buf, buf_size))
777 return -EFAULT;
778
779 if (sscanf(buf, "%d", &value) != 1)
780 return -EINVAL;
781
782 /*
783 * Our users expect 0 to be "CAM", but 0 isn't actually
784 * valid here. However, let's not confuse them and present
785 * IWL_POWER_INDEX_1 as "1", not "0".
786 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700787 if (value == 0)
788 return -EINVAL;
789 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700790 value -= 1;
791
792 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
793 return -EINVAL;
794
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700795 if (!iwl_is_ready_rf(priv))
796 return -EAGAIN;
797
Johannes Berge312c242009-08-07 15:41:51 -0700798 priv->power_data.debug_sleep_level_override = value;
799
Reinette Chatred3a57192010-01-21 11:52:28 -0800800 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700801 iwl_power_update_mode(priv, true);
Reinette Chatred3a57192010-01-21 11:52:28 -0800802 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700803
804 return count;
805}
806
807static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
808 char __user *user_buf,
809 size_t count, loff_t *ppos)
810{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700811 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700812 char buf[10];
813 int pos, value;
814 const size_t bufsz = sizeof(buf);
815
816 /* see the write function */
817 value = priv->power_data.debug_sleep_level_override;
818 if (value >= 0)
819 value += 1;
820
821 pos = scnprintf(buf, bufsz, "%d\n", value);
822 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
823}
824
825static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
826 char __user *user_buf,
827 size_t count, loff_t *ppos)
828{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700829 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700830 char buf[200];
831 int pos = 0, i;
832 const size_t bufsz = sizeof(buf);
833 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
834
835 pos += scnprintf(buf + pos, bufsz - pos,
836 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
837 pos += scnprintf(buf + pos, bufsz - pos,
838 "RX/TX timeout: %d/%d usec\n",
839 le32_to_cpu(cmd->rx_data_timeout),
840 le32_to_cpu(cmd->tx_data_timeout));
841 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
842 pos += scnprintf(buf + pos, bufsz - pos,
843 "sleep_interval[%d]: %d\n", i,
844 le32_to_cpu(cmd->sleep_interval[i]));
845
846 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
847}
848
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700849DEBUGFS_READ_WRITE_FILE_OPS(sram);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800850DEBUGFS_READ_WRITE_FILE_OPS(log_event);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700851DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700852DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800853DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700854DEBUGFS_READ_FILE_OPS(status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700855DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700856DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700857DEBUGFS_READ_FILE_OPS(led);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700858DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d2009-07-27 13:50:15 -0700859DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Johannes Berge312c242009-08-07 15:41:51 -0700860DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
861DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700862
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700863static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
864 char __user *user_buf,
865 size_t count, loff_t *ppos)
866{
867 struct iwl_priv *priv = file->private_data;
868 int pos = 0, ofs = 0;
869 int cnt = 0, entry;
870 struct iwl_tx_queue *txq;
871 struct iwl_queue *q;
872 struct iwl_rx_queue *rxq = &priv->rxq;
873 char *buf;
874 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700875 (priv->cfg->num_of_queues * 32 * 8) + 400;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700876 const u8 *ptr;
877 ssize_t ret;
878
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700879 if (!priv->txq) {
880 IWL_ERR(priv, "txq not ready\n");
881 return -EAGAIN;
882 }
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700883 buf = kzalloc(bufsz, GFP_KERNEL);
884 if (!buf) {
885 IWL_ERR(priv, "Can not allocate buffer\n");
886 return -ENOMEM;
887 }
888 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
889 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
890 txq = &priv->txq[cnt];
891 q = &txq->q;
892 pos += scnprintf(buf + pos, bufsz - pos,
893 "q[%d]: read_ptr: %u, write_ptr: %u\n",
894 cnt, q->read_ptr, q->write_ptr);
895 }
896 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
897 ptr = priv->tx_traffic;
898 pos += scnprintf(buf + pos, bufsz - pos,
899 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
900 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
901 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
902 entry++, ofs += 16) {
903 pos += scnprintf(buf + pos, bufsz - pos,
904 "0x%.4x ", ofs);
905 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
906 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700907 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700908 if (bufsz - pos > 0)
909 buf[pos++] = '\n';
910 }
911 }
912 }
913
914 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
915 pos += scnprintf(buf + pos, bufsz - pos,
916 "read: %u, write: %u\n",
917 rxq->read, rxq->write);
918
919 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
920 ptr = priv->rx_traffic;
921 pos += scnprintf(buf + pos, bufsz - pos,
922 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
923 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
924 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
925 entry++, ofs += 16) {
926 pos += scnprintf(buf + pos, bufsz - pos,
927 "0x%.4x ", ofs);
928 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
929 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700930 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700931 if (bufsz - pos > 0)
932 buf[pos++] = '\n';
933 }
934 }
935 }
936
937 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
938 kfree(buf);
939 return ret;
940}
941
942static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
943 const char __user *user_buf,
944 size_t count, loff_t *ppos)
945{
946 struct iwl_priv *priv = file->private_data;
947 char buf[8];
948 int buf_size;
949 int traffic_log;
950
951 memset(buf, 0, sizeof(buf));
952 buf_size = min(count, sizeof(buf) - 1);
953 if (copy_from_user(buf, user_buf, buf_size))
954 return -EFAULT;
955 if (sscanf(buf, "%d", &traffic_log) != 1)
956 return -EFAULT;
957 if (traffic_log == 0)
958 iwl_reset_traffic_log(priv);
959
960 return count;
961}
962
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700963static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
964 char __user *user_buf,
965 size_t count, loff_t *ppos) {
966
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700967 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700968 struct iwl_tx_queue *txq;
969 struct iwl_queue *q;
970 char *buf;
971 int pos = 0;
972 int cnt;
973 int ret;
Wey-Yi Guyd23db552009-11-20 12:04:59 -0800974 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700975
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700976 if (!priv->txq) {
977 IWL_ERR(priv, "txq not ready\n");
978 return -EAGAIN;
979 }
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700980 buf = kzalloc(bufsz, GFP_KERNEL);
981 if (!buf)
982 return -ENOMEM;
983
984 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
985 txq = &priv->txq[cnt];
986 q = &txq->q;
987 pos += scnprintf(buf + pos, bufsz - pos,
988 "hwq %.2d: read=%u write=%u stop=%d"
989 " swq_id=%#.2x (ac %d/hwq %d)\n",
990 cnt, q->read_ptr, q->write_ptr,
991 !!test_bit(cnt, priv->queue_stopped),
992 txq->swq_id,
993 txq->swq_id & 0x80 ? txq->swq_id & 3 :
994 txq->swq_id,
995 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
996 0x1f : txq->swq_id);
997 if (cnt >= 4)
998 continue;
999 /* for the ACs, display the stop count too */
1000 pos += scnprintf(buf + pos, bufsz - pos,
1001 " stop-count: %d\n",
1002 atomic_read(&priv->queue_stop_count[cnt]));
1003 }
1004 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1005 kfree(buf);
1006 return ret;
1007}
1008
1009static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1010 char __user *user_buf,
1011 size_t count, loff_t *ppos) {
1012
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001013 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001014 struct iwl_rx_queue *rxq = &priv->rxq;
1015 char buf[256];
1016 int pos = 0;
1017 const size_t bufsz = sizeof(buf);
1018
1019 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1020 rxq->read);
1021 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1022 rxq->write);
1023 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1024 rxq->free_count);
1025 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1026 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1027 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1028}
1029
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001030static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1031 char __user *user_buf,
1032 size_t count, loff_t *ppos)
1033{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001034 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001035 return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1036 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001037}
1038
1039static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1040 char __user *user_buf,
1041 size_t count, loff_t *ppos)
1042{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001043 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001044 return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1045 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001046}
1047
1048static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1049 char __user *user_buf,
1050 size_t count, loff_t *ppos)
1051{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001052 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001053 return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1054 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001055}
1056
Wey-Yi Guy52259352009-08-07 15:41:43 -07001057static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1058 char __user *user_buf,
1059 size_t count, loff_t *ppos) {
1060
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001061 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001062 int pos = 0;
1063 int cnt = 0;
1064 char *buf;
1065 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1066 ssize_t ret;
1067 struct iwl_sensitivity_data *data;
1068
1069 data = &priv->sensitivity_data;
1070 buf = kzalloc(bufsz, GFP_KERNEL);
1071 if (!buf) {
1072 IWL_ERR(priv, "Can not allocate Buffer\n");
1073 return -ENOMEM;
1074 }
1075
1076 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1077 data->auto_corr_ofdm);
1078 pos += scnprintf(buf + pos, bufsz - pos,
1079 "auto_corr_ofdm_mrc:\t\t %u\n",
1080 data->auto_corr_ofdm_mrc);
1081 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1082 data->auto_corr_ofdm_x1);
1083 pos += scnprintf(buf + pos, bufsz - pos,
1084 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1085 data->auto_corr_ofdm_mrc_x1);
1086 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1087 data->auto_corr_cck);
1088 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1089 data->auto_corr_cck_mrc);
1090 pos += scnprintf(buf + pos, bufsz - pos,
1091 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1092 data->last_bad_plcp_cnt_ofdm);
1093 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1094 data->last_fa_cnt_ofdm);
1095 pos += scnprintf(buf + pos, bufsz - pos,
1096 "last_bad_plcp_cnt_cck:\t\t %u\n",
1097 data->last_bad_plcp_cnt_cck);
1098 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1099 data->last_fa_cnt_cck);
1100 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1101 data->nrg_curr_state);
1102 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1103 data->nrg_prev_state);
1104 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1105 for (cnt = 0; cnt < 10; cnt++) {
1106 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1107 data->nrg_value[cnt]);
1108 }
1109 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1110 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1111 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1112 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1113 data->nrg_silence_rssi[cnt]);
1114 }
1115 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1116 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1117 data->nrg_silence_ref);
1118 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1119 data->nrg_energy_idx);
1120 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1121 data->nrg_silence_idx);
1122 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1123 data->nrg_th_cck);
1124 pos += scnprintf(buf + pos, bufsz - pos,
1125 "nrg_auto_corr_silence_diff:\t %u\n",
1126 data->nrg_auto_corr_silence_diff);
1127 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1128 data->num_in_cck_no_fa);
1129 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1130 data->nrg_th_ofdm);
1131
1132 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1133 kfree(buf);
1134 return ret;
1135}
1136
1137
1138static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1139 char __user *user_buf,
1140 size_t count, loff_t *ppos) {
1141
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001142 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001143 int pos = 0;
1144 int cnt = 0;
1145 char *buf;
1146 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1147 ssize_t ret;
1148 struct iwl_chain_noise_data *data;
1149
1150 data = &priv->chain_noise_data;
1151 buf = kzalloc(bufsz, GFP_KERNEL);
1152 if (!buf) {
1153 IWL_ERR(priv, "Can not allocate Buffer\n");
1154 return -ENOMEM;
1155 }
1156
1157 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1158 data->active_chains);
1159 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1160 data->chain_noise_a);
1161 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1162 data->chain_noise_b);
1163 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1164 data->chain_noise_c);
1165 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1166 data->chain_signal_a);
1167 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1168 data->chain_signal_b);
1169 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1170 data->chain_signal_c);
1171 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1172 data->beacon_count);
1173
1174 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1175 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1176 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1177 data->disconn_array[cnt]);
1178 }
1179 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1180 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1181 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1182 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1183 data->delta_gain_code[cnt]);
1184 }
1185 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1186 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1187 data->radio_write);
1188 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1189 data->state);
1190
1191 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1192 kfree(buf);
1193 return ret;
1194}
1195
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001196static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1197 char __user *user_buf,
1198 size_t count, loff_t *ppos)
1199{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001200 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001201 char buf[60];
1202 int pos = 0;
1203 const size_t bufsz = sizeof(buf);
1204 u32 pwrsave_status;
1205
1206 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1207 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1208
1209 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1210 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1211 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1212 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1213 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1214 "error");
1215
1216 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1217}
1218
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001219static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001220 const char __user *user_buf,
1221 size_t count, loff_t *ppos)
1222{
1223 struct iwl_priv *priv = file->private_data;
1224 char buf[8];
1225 int buf_size;
1226 int clear;
1227
1228 memset(buf, 0, sizeof(buf));
1229 buf_size = min(count, sizeof(buf) - 1);
1230 if (copy_from_user(buf, user_buf, buf_size))
1231 return -EFAULT;
1232 if (sscanf(buf, "%d", &clear) != 1)
1233 return -EFAULT;
1234
1235 /* make request to uCode to retrieve statistics information */
1236 mutex_lock(&priv->mutex);
1237 iwl_send_statistics_request(priv, CMD_SYNC, true);
1238 mutex_unlock(&priv->mutex);
1239
1240 return count;
1241}
1242
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08001243static ssize_t iwl_dbgfs_csr_write(struct file *file,
1244 const char __user *user_buf,
1245 size_t count, loff_t *ppos)
1246{
1247 struct iwl_priv *priv = file->private_data;
1248 char buf[8];
1249 int buf_size;
1250 int csr;
1251
1252 memset(buf, 0, sizeof(buf));
1253 buf_size = min(count, sizeof(buf) - 1);
1254 if (copy_from_user(buf, user_buf, buf_size))
1255 return -EFAULT;
1256 if (sscanf(buf, "%d", &csr) != 1)
1257 return -EFAULT;
1258
1259 if (priv->cfg->ops->lib->dump_csr)
1260 priv->cfg->ops->lib->dump_csr(priv);
1261
1262 return count;
1263}
1264
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001265static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1266 char __user *user_buf,
1267 size_t count, loff_t *ppos) {
1268
1269 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1270 int pos = 0;
1271 char buf[128];
1272 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001273
1274 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1275 priv->event_log.ucode_trace ? "On" : "Off");
1276 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1277 priv->event_log.non_wraps_count);
1278 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1279 priv->event_log.wraps_once_count);
1280 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1281 priv->event_log.wraps_more_count);
1282
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001283 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001284}
1285
1286static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1287 const char __user *user_buf,
1288 size_t count, loff_t *ppos)
1289{
1290 struct iwl_priv *priv = file->private_data;
1291 char buf[8];
1292 int buf_size;
1293 int trace;
1294
1295 memset(buf, 0, sizeof(buf));
1296 buf_size = min(count, sizeof(buf) - 1);
1297 if (copy_from_user(buf, user_buf, buf_size))
1298 return -EFAULT;
1299 if (sscanf(buf, "%d", &trace) != 1)
1300 return -EFAULT;
1301
1302 if (trace) {
1303 priv->event_log.ucode_trace = true;
1304 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1305 mod_timer(&priv->ucode_trace,
1306 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1307 } else {
1308 priv->event_log.ucode_trace = false;
1309 del_timer_sync(&priv->ucode_trace);
1310 }
1311
1312 return count;
1313}
1314
Johannes Berg60987202010-02-18 00:36:07 -08001315static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1316 char __user *user_buf,
1317 size_t count, loff_t *ppos) {
1318
1319 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1320 int len = 0;
1321 char buf[20];
1322
1323 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1324 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1325}
1326
1327static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1328 char __user *user_buf,
1329 size_t count, loff_t *ppos) {
1330
1331 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1332 int len = 0;
1333 char buf[20];
1334
1335 len = sprintf(buf, "0x%04X\n",
1336 le32_to_cpu(priv->active_rxon.filter_flags));
1337 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1338}
1339
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08001340static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1341 char __user *user_buf,
1342 size_t count, loff_t *ppos)
1343{
1344 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1345 char *buf;
1346 int pos = 0;
1347 ssize_t ret = -EFAULT;
1348
1349 if (priv->cfg->ops->lib->dump_fh) {
1350 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1351 if (buf) {
1352 ret = simple_read_from_buffer(user_buf,
1353 count, ppos, buf, pos);
1354 kfree(buf);
1355 }
1356 }
1357
1358 return ret;
1359}
1360
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001361static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1362 char __user *user_buf,
1363 size_t count, loff_t *ppos) {
1364
1365 struct iwl_priv *priv = file->private_data;
1366 int pos = 0;
1367 char buf[12];
1368 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001369
1370 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1371 priv->missed_beacon_threshold);
1372
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001373 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001374}
1375
1376static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1377 const char __user *user_buf,
1378 size_t count, loff_t *ppos)
1379{
1380 struct iwl_priv *priv = file->private_data;
1381 char buf[8];
1382 int buf_size;
1383 int missed;
1384
1385 memset(buf, 0, sizeof(buf));
1386 buf_size = min(count, sizeof(buf) - 1);
1387 if (copy_from_user(buf, user_buf, buf_size))
1388 return -EFAULT;
1389 if (sscanf(buf, "%d", &missed) != 1)
1390 return -EINVAL;
1391
1392 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1393 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1394 priv->missed_beacon_threshold =
1395 IWL_MISSED_BEACON_THRESHOLD_DEF;
1396 else
1397 priv->missed_beacon_threshold = missed;
1398
1399 return count;
1400}
1401
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001402static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1403 char __user *user_buf,
1404 size_t count, loff_t *ppos) {
1405
1406 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1407 int pos = 0;
1408 char buf[12];
1409 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001410
1411 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1412 priv->cfg->plcp_delta_threshold);
1413
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001414 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001415}
1416
1417static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1418 const char __user *user_buf,
1419 size_t count, loff_t *ppos) {
1420
1421 struct iwl_priv *priv = file->private_data;
1422 char buf[8];
1423 int buf_size;
1424 int plcp;
1425
1426 memset(buf, 0, sizeof(buf));
1427 buf_size = min(count, sizeof(buf) - 1);
1428 if (copy_from_user(buf, user_buf, buf_size))
1429 return -EFAULT;
1430 if (sscanf(buf, "%d", &plcp) != 1)
1431 return -EINVAL;
1432 if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1433 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1434 priv->cfg->plcp_delta_threshold =
1435 IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1436 else
1437 priv->cfg->plcp_delta_threshold = plcp;
1438 return count;
1439}
1440
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001441static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1442 char __user *user_buf,
1443 size_t count, loff_t *ppos) {
1444
1445 struct iwl_priv *priv = file->private_data;
1446 int i, pos = 0;
1447 char buf[300];
1448 const size_t bufsz = sizeof(buf);
1449 struct iwl_force_reset *force_reset;
1450
1451 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1452 force_reset = &priv->force_reset[i];
1453 pos += scnprintf(buf + pos, bufsz - pos,
1454 "Force reset method %d\n", i);
1455 pos += scnprintf(buf + pos, bufsz - pos,
1456 "\tnumber of reset request: %d\n",
1457 force_reset->reset_request_count);
1458 pos += scnprintf(buf + pos, bufsz - pos,
1459 "\tnumber of reset request success: %d\n",
1460 force_reset->reset_success_count);
1461 pos += scnprintf(buf + pos, bufsz - pos,
1462 "\tnumber of reset request reject: %d\n",
1463 force_reset->reset_reject_count);
1464 pos += scnprintf(buf + pos, bufsz - pos,
1465 "\treset duration: %lu\n",
1466 force_reset->reset_duration);
1467 }
1468 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1469}
1470
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08001471static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1472 const char __user *user_buf,
1473 size_t count, loff_t *ppos) {
1474
1475 struct iwl_priv *priv = file->private_data;
1476 char buf[8];
1477 int buf_size;
1478 int reset, ret;
1479
1480 memset(buf, 0, sizeof(buf));
1481 buf_size = min(count, sizeof(buf) - 1);
1482 if (copy_from_user(buf, user_buf, buf_size))
1483 return -EFAULT;
1484 if (sscanf(buf, "%d", &reset) != 1)
1485 return -EINVAL;
1486 switch (reset) {
1487 case IWL_RF_RESET:
1488 case IWL_FW_RESET:
1489 ret = iwl_force_reset(priv, reset);
1490 break;
1491 default:
1492 return -EINVAL;
1493 }
1494 return ret ? ret : count;
1495}
1496
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001497DEBUGFS_READ_FILE_OPS(rx_statistics);
1498DEBUGFS_READ_FILE_OPS(tx_statistics);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001499DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001500DEBUGFS_READ_FILE_OPS(rx_queue);
1501DEBUGFS_READ_FILE_OPS(tx_queue);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001502DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1503DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1504DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07001505DEBUGFS_READ_FILE_OPS(sensitivity);
1506DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001507DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001508DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1509DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08001510DEBUGFS_WRITE_FILE_OPS(csr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001511DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08001512DEBUGFS_READ_FILE_OPS(fh_reg);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001513DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001514DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001515DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08001516DEBUGFS_READ_FILE_OPS(rxon_flags);
1517DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001518
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001519/*
1520 * Create the debugfs files and directories
1521 *
1522 */
1523int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1524{
Zhu Yi95b1a822008-05-29 16:34:50 +08001525 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001526 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001527
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001528 dir_drv = debugfs_create_dir(name, phyd);
1529 if (!dir_drv)
1530 return -ENOMEM;
1531
1532 priv->debugfs_dir = dir_drv;
1533
1534 dir_data = debugfs_create_dir("data", dir_drv);
1535 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001536 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001537 dir_rf = debugfs_create_dir("rf", dir_drv);
1538 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001539 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001540 dir_debug = debugfs_create_dir("debug", dir_drv);
1541 if (!dir_debug)
1542 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001543
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001544 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1545 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1546 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1547 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1548 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1549 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1550 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1551 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1552 DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
Wey-Yi Guy381733c2010-04-25 09:39:46 -07001553 if (!priv->cfg->broken_powersave) {
1554 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1555 S_IWUSR | S_IRUSR);
1556 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1557 }
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001558 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1559 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1560 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1561 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1562 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1563 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1564 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001565 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1566 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1567 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1568 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1569 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1570 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001571 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001572 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07001573 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1574 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1575 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1576
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001577 if (priv->cfg->sensitivity_calib_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001578 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001579 if (priv->cfg->chain_noise_calib_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001580 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guy6e5c8002010-04-27 14:00:28 -07001581 if (priv->cfg->ucode_tracing)
1582 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08001583 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1584 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001585 if (priv->cfg->sensitivity_calib_by_driver)
1586 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1587 &priv->disable_sens_cal);
1588 if (priv->cfg->chain_noise_calib_by_driver)
1589 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1590 &priv->disable_chain_noise_cal);
Wey-Yi Guy4e7033e2010-04-27 14:33:33 -07001591 if (priv->cfg->tx_power_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001592 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
Wey-Yi Guy030b8652009-06-12 13:22:55 -07001593 &priv->disable_tx_power_cal);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001594 return 0;
1595
1596err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001597 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001598 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001599 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001600}
1601EXPORT_SYMBOL(iwl_dbgfs_register);
1602
1603/**
1604 * Remove the debugfs files and directories
1605 *
1606 */
1607void iwl_dbgfs_unregister(struct iwl_priv *priv)
1608{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001609 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001610 return;
1611
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001612 debugfs_remove_recursive(priv->debugfs_dir);
1613 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001614}
1615EXPORT_SYMBOL(iwl_dbgfs_unregister);
1616
1617
Tomas Winkler445c2df2008-05-15 13:54:16 +08001618