blob: 5e12c96cc35e0dfac4e8c666d542b371d885b349 [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];
Johannes Bergda735112010-05-03 01:25:24 -0700306 if (!station->used)
307 continue;
308 pos += scnprintf(buf + pos, bufsz - pos,
309 "station %d - addr: %pM, flags: %#x\n",
310 i, station->sta.sta.addr,
311 station->sta.station_flags_msk);
312 pos += scnprintf(buf + pos, bufsz - pos,
313 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
314 pos += scnprintf(buf + pos, bufsz - pos,
315 "start_idx\tbitmap\t\t\trate_n_flags\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700316
Johannes Bergda735112010-05-03 01:25:24 -0700317 for (j = 0; j < MAX_TID_COUNT; j++) {
318 pos += scnprintf(buf + pos, bufsz - pos,
319 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
320 j, station->tid[j].seq_number,
321 station->tid[j].agg.txq_id,
322 station->tid[j].agg.frame_count,
323 station->tid[j].tfds_in_queue,
324 station->tid[j].agg.start_idx,
325 station->tid[j].agg.bitmap,
326 station->tid[j].agg.rate_n_flags);
327
328 if (station->tid[j].agg.wait_for_ba)
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700329 pos += scnprintf(buf + pos, bufsz - pos,
Johannes Bergda735112010-05-03 01:25:24 -0700330 " - waitforba");
Abhijeet Kolekardb0589f2008-04-14 21:16:04 -0700331 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700332 }
Johannes Bergda735112010-05-03 01:25:24 -0700333
334 pos += scnprintf(buf + pos, bufsz - pos, "\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700335 }
336
337 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
338 kfree(buf);
339 return ret;
340}
341
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700342static ssize_t iwl_dbgfs_nvm_read(struct file *file,
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800343 char __user *user_buf,
344 size_t count,
345 loff_t *ppos)
346{
347 ssize_t ret;
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700348 struct iwl_priv *priv = file->private_data;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800349 int pos = 0, ofs = 0, buf_size = 0;
350 const u8 *ptr;
351 char *buf;
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700352 u16 eeprom_ver;
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800353 size_t eeprom_len = priv->cfg->eeprom_size;
354 buf_size = 4 * eeprom_len + 256;
355
356 if (eeprom_len % 16) {
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700357 IWL_ERR(priv, "NVM size is not multiple of 16.\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800358 return -ENODATA;
359 }
360
Julia Lawallc37457e2009-08-03 11:11:45 +0200361 ptr = priv->eeprom;
362 if (!ptr) {
363 IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
364 return -ENOMEM;
365 }
366
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800367 /* 4 characters for byte 0xYY */
368 buf = kzalloc(buf_size, GFP_KERNEL);
369 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800370 IWL_ERR(priv, "Can not allocate Buffer\n");
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800371 return -ENOMEM;
372 }
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700373 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
374 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
375 "version: 0x%x\n",
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700376 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
Wey-Yi Guye307ddc2009-09-11 10:38:16 -0700377 ? "OTP" : "EEPROM", eeprom_ver);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800378 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
379 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
380 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
381 buf_size - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700382 pos += strlen(buf + pos);
Tomas Winkler8dd266e2008-05-05 10:22:32 +0800383 if (buf_size - pos > 0)
384 buf[pos++] = '\n';
385 }
386
387 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
388 kfree(buf);
389 return ret;
390}
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700391
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800392static ssize_t iwl_dbgfs_log_event_read(struct file *file,
393 char __user *user_buf,
394 size_t count, loff_t *ppos)
395{
396 struct iwl_priv *priv = file->private_data;
397 char *buf;
398 int pos = 0;
399 ssize_t ret = -ENOMEM;
400
Wey-Yi Guy937c3972010-01-15 13:43:36 -0800401 ret = pos = priv->cfg->ops->lib->dump_nic_event_log(
402 priv, true, &buf, true);
403 if (buf) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800404 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
405 kfree(buf);
406 }
407 return ret;
408}
409
Ester Kummer189a2b52008-05-15 13:54:18 +0800410static ssize_t iwl_dbgfs_log_event_write(struct file *file,
411 const char __user *user_buf,
412 size_t count, loff_t *ppos)
413{
414 struct iwl_priv *priv = file->private_data;
415 u32 event_log_flag;
416 char buf[8];
417 int buf_size;
418
419 memset(buf, 0, sizeof(buf));
420 buf_size = min(count, sizeof(buf) - 1);
421 if (copy_from_user(buf, user_buf, buf_size))
422 return -EFAULT;
423 if (sscanf(buf, "%d", &event_log_flag) != 1)
424 return -EFAULT;
425 if (event_log_flag == 1)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800426 priv->cfg->ops->lib->dump_nic_event_log(priv, true,
427 NULL, false);
Ester Kummer189a2b52008-05-15 13:54:18 +0800428
429 return count;
430}
431
Winkler, Tomasd366df52008-12-02 12:14:01 -0800432
433
434static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
435 size_t count, loff_t *ppos)
436{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700437 struct iwl_priv *priv = file->private_data;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800438 struct ieee80211_channel *channels = NULL;
439 const struct ieee80211_supported_band *supp_band = NULL;
440 int pos = 0, i, bufsz = PAGE_SIZE;
441 char *buf;
442 ssize_t ret;
443
444 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
445 return -EAGAIN;
446
447 buf = kzalloc(bufsz, GFP_KERNEL);
448 if (!buf) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800449 IWL_ERR(priv, "Can not allocate Buffer\n");
Winkler, Tomasd366df52008-12-02 12:14:01 -0800450 return -ENOMEM;
451 }
452
453 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700454 if (supp_band) {
455 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800456
Winkler, Tomasd366df52008-12-02 12:14:01 -0800457 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700458 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
459 supp_band->n_channels);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800460
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700461 for (i = 0; i < supp_band->n_channels; i++)
462 pos += scnprintf(buf + pos, bufsz - pos,
463 "%d: %ddBm: BSS%s%s, %s.\n",
464 ieee80211_frequency_to_channel(
465 channels[i].center_freq),
466 channels[i].max_power,
467 channels[i].flags & IEEE80211_CHAN_RADAR ?
468 " (IEEE 802.11h required)" : "",
469 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
470 || (channels[i].flags &
471 IEEE80211_CHAN_RADAR)) ? "" :
472 ", IBSS",
473 channels[i].flags &
474 IEEE80211_CHAN_PASSIVE_SCAN ?
475 "passive only" : "active/passive");
476 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800477 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700478 if (supp_band) {
479 channels = supp_band->channels;
Winkler, Tomasd366df52008-12-02 12:14:01 -0800480
Winkler, Tomasd366df52008-12-02 12:14:01 -0800481 pos += scnprintf(buf + pos, bufsz - pos,
Wey-Yi Guya2e23222009-05-22 11:01:55 -0700482 "Displaying %d channels in 5.2GHz band (802.11a)\n",
483 supp_band->n_channels);
484
485 for (i = 0; i < supp_band->n_channels; i++)
486 pos += scnprintf(buf + pos, bufsz - pos,
487 "%d: %ddBm: BSS%s%s, %s.\n",
488 ieee80211_frequency_to_channel(
489 channels[i].center_freq),
490 channels[i].max_power,
491 channels[i].flags & IEEE80211_CHAN_RADAR ?
492 " (IEEE 802.11h required)" : "",
493 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
494 || (channels[i].flags &
495 IEEE80211_CHAN_RADAR)) ? "" :
496 ", IBSS",
497 channels[i].flags &
498 IEEE80211_CHAN_PASSIVE_SCAN ?
499 "passive only" : "active/passive");
500 }
Winkler, Tomasd366df52008-12-02 12:14:01 -0800501 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
502 kfree(buf);
503 return ret;
504}
505
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700506static ssize_t iwl_dbgfs_status_read(struct file *file,
507 char __user *user_buf,
508 size_t count, loff_t *ppos) {
509
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700510 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700511 char buf[512];
512 int pos = 0;
513 const size_t bufsz = sizeof(buf);
514
515 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
516 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700517 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INT_ENABLED:\t %d\n",
518 test_bit(STATUS_INT_ENABLED, &priv->status));
519 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
520 test_bit(STATUS_RF_KILL_HW, &priv->status));
Wey-Yi Guy7812b162009-10-02 13:43:58 -0700521 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
522 test_bit(STATUS_CT_KILL, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700523 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_INIT:\t\t %d\n",
524 test_bit(STATUS_INIT, &priv->status));
525 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_ALIVE:\t\t %d\n",
526 test_bit(STATUS_ALIVE, &priv->status));
527 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
528 test_bit(STATUS_READY, &priv->status));
529 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_TEMPERATURE:\t %d\n",
530 test_bit(STATUS_TEMPERATURE, &priv->status));
531 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
532 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
533 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
534 test_bit(STATUS_EXIT_PENDING, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700535 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
536 test_bit(STATUS_STATISTICS, &priv->status));
537 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
538 test_bit(STATUS_SCANNING, &priv->status));
539 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_ABORTING:\t %d\n",
540 test_bit(STATUS_SCAN_ABORTING, &priv->status));
541 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCAN_HW:\t\t %d\n",
542 test_bit(STATUS_SCAN_HW, &priv->status));
543 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_POWER_PMI:\t %d\n",
544 test_bit(STATUS_POWER_PMI, &priv->status));
545 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_FW_ERROR:\t %d\n",
546 test_bit(STATUS_FW_ERROR, &priv->status));
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700547 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
548}
549
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700550static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
551 char __user *user_buf,
552 size_t count, loff_t *ppos) {
553
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700554 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700555 int pos = 0;
556 int cnt = 0;
557 char *buf;
558 int bufsz = 24 * 64; /* 24 items * 64 char per item */
559 ssize_t ret;
560
561 buf = kzalloc(bufsz, GFP_KERNEL);
562 if (!buf) {
563 IWL_ERR(priv, "Can not allocate Buffer\n");
564 return -ENOMEM;
565 }
566
567 pos += scnprintf(buf + pos, bufsz - pos,
568 "Interrupt Statistics Report:\n");
569
570 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
571 priv->isr_stats.hw);
572 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
573 priv->isr_stats.sw);
574 if (priv->isr_stats.sw > 0) {
575 pos += scnprintf(buf + pos, bufsz - pos,
576 "\tLast Restarting Code: 0x%X\n",
577 priv->isr_stats.sw_err);
578 }
579#ifdef CONFIG_IWLWIFI_DEBUG
580 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
581 priv->isr_stats.sch);
582 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
583 priv->isr_stats.alive);
584#endif
585 pos += scnprintf(buf + pos, bufsz - pos,
586 "HW RF KILL switch toggled:\t %u\n",
587 priv->isr_stats.rfkill);
588
589 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
590 priv->isr_stats.ctkill);
591
592 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
593 priv->isr_stats.wakeup);
594
595 pos += scnprintf(buf + pos, bufsz - pos,
596 "Rx command responses:\t\t %u\n",
597 priv->isr_stats.rx);
598 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
599 if (priv->isr_stats.rx_handlers[cnt] > 0)
600 pos += scnprintf(buf + pos, bufsz - pos,
601 "\tRx handler[%36s]:\t\t %u\n",
602 get_cmd_string(cnt),
603 priv->isr_stats.rx_handlers[cnt]);
604 }
605
606 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
607 priv->isr_stats.tx);
608
609 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
610 priv->isr_stats.unhandled);
611
612 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
613 kfree(buf);
614 return ret;
615}
616
617static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
618 const char __user *user_buf,
619 size_t count, loff_t *ppos)
620{
621 struct iwl_priv *priv = file->private_data;
622 char buf[8];
623 int buf_size;
624 u32 reset_flag;
625
626 memset(buf, 0, sizeof(buf));
627 buf_size = min(count, sizeof(buf) - 1);
628 if (copy_from_user(buf, user_buf, buf_size))
629 return -EFAULT;
630 if (sscanf(buf, "%x", &reset_flag) != 1)
631 return -EFAULT;
632 if (reset_flag == 0)
633 iwl_clear_isr_stats(priv);
634
635 return count;
636}
637
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700638static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
639 size_t count, loff_t *ppos)
640{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700641 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700642 int pos = 0, i;
643 char buf[256];
644 const size_t bufsz = sizeof(buf);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700645
646 for (i = 0; i < AC_NUM; i++) {
647 pos += scnprintf(buf + pos, bufsz - pos,
648 "\tcw_min\tcw_max\taifsn\ttxop\n");
649 pos += scnprintf(buf + pos, bufsz - pos,
650 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
651 priv->qos_data.def_qos_parm.ac[i].cw_min,
652 priv->qos_data.def_qos_parm.ac[i].cw_max,
653 priv->qos_data.def_qos_parm.ac[i].aifsn,
654 priv->qos_data.def_qos_parm.ac[i].edca_txop);
655 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800656 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700657}
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700658
Wey-Yi Guya283c012009-07-17 09:30:19 -0700659static ssize_t iwl_dbgfs_led_read(struct file *file, char __user *user_buf,
660 size_t count, loff_t *ppos)
661{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700662 struct iwl_priv *priv = file->private_data;
Wey-Yi Guya283c012009-07-17 09:30:19 -0700663 int pos = 0;
664 char buf[256];
665 const size_t bufsz = sizeof(buf);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700666
667 pos += scnprintf(buf + pos, bufsz - pos,
668 "allow blinking: %s\n",
669 (priv->allow_blinking) ? "True" : "False");
670 if (priv->allow_blinking) {
671 pos += scnprintf(buf + pos, bufsz - pos,
672 "Led blinking rate: %u\n",
673 priv->last_blink_rate);
674 pos += scnprintf(buf + pos, bufsz - pos,
675 "Last blink time: %lu\n",
676 priv->last_blink_time);
677 }
678
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800679 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700680}
Wey-Yi Guya283c012009-07-17 09:30:19 -0700681
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700682static ssize_t iwl_dbgfs_thermal_throttling_read(struct file *file,
683 char __user *user_buf,
684 size_t count, loff_t *ppos)
685{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700686 struct iwl_priv *priv = file->private_data;
Johannes Berg3ad3b922009-08-07 15:41:48 -0700687 struct iwl_tt_mgmt *tt = &priv->thermal_throttle;
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700688 struct iwl_tt_restriction *restriction;
689 char buf[100];
690 int pos = 0;
691 const size_t bufsz = sizeof(buf);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700692
693 pos += scnprintf(buf + pos, bufsz - pos,
694 "Thermal Throttling Mode: %s\n",
Johannes Berg3ad3b922009-08-07 15:41:48 -0700695 tt->advanced_tt ? "Advance" : "Legacy");
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700696 pos += scnprintf(buf + pos, bufsz - pos,
697 "Thermal Throttling State: %d\n",
698 tt->state);
Johannes Berg3ad3b922009-08-07 15:41:48 -0700699 if (tt->advanced_tt) {
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700700 restriction = tt->restriction + tt->state;
701 pos += scnprintf(buf + pos, bufsz - pos,
702 "Tx mode: %d\n",
703 restriction->tx_stream);
704 pos += scnprintf(buf + pos, bufsz - pos,
705 "Rx mode: %d\n",
706 restriction->rx_stream);
707 pos += scnprintf(buf + pos, bufsz - pos,
708 "HT mode: %d\n",
709 restriction->is_ht);
710 }
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800711 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700712}
713
Wey-Yi Guy1e4247d42009-07-27 13:50:15 -0700714static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
715 const char __user *user_buf,
716 size_t count, loff_t *ppos)
717{
718 struct iwl_priv *priv = file->private_data;
719 char buf[8];
720 int buf_size;
721 int ht40;
722
723 memset(buf, 0, sizeof(buf));
724 buf_size = min(count, sizeof(buf) - 1);
725 if (copy_from_user(buf, user_buf, buf_size))
726 return -EFAULT;
727 if (sscanf(buf, "%d", &ht40) != 1)
728 return -EFAULT;
729 if (!iwl_is_associated(priv))
730 priv->disable_ht40 = ht40 ? true : false;
731 else {
732 IWL_ERR(priv, "Sta associated with AP - "
733 "Change to 40MHz channel support is not allowed\n");
734 return -EINVAL;
735 }
736
737 return count;
738}
739
740static ssize_t iwl_dbgfs_disable_ht40_read(struct file *file,
741 char __user *user_buf,
742 size_t count, loff_t *ppos)
743{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700744 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy1e4247d42009-07-27 13:50:15 -0700745 char buf[100];
746 int pos = 0;
747 const size_t bufsz = sizeof(buf);
Wey-Yi Guy1e4247d42009-07-27 13:50:15 -0700748
749 pos += scnprintf(buf + pos, bufsz - pos,
750 "11n 40MHz Mode: %s\n",
751 priv->disable_ht40 ? "Disabled" : "Enabled");
Wey-Yi Guy4967c312010-02-18 15:22:07 -0800752 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guy1e4247d42009-07-27 13:50:15 -0700753}
754
Johannes Berge312c242009-08-07 15:41:51 -0700755static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
756 const char __user *user_buf,
757 size_t count, loff_t *ppos)
758{
759 struct iwl_priv *priv = file->private_data;
760 char buf[8];
761 int buf_size;
762 int value;
763
764 memset(buf, 0, sizeof(buf));
765 buf_size = min(count, sizeof(buf) - 1);
766 if (copy_from_user(buf, user_buf, buf_size))
767 return -EFAULT;
768
769 if (sscanf(buf, "%d", &value) != 1)
770 return -EINVAL;
771
772 /*
773 * Our users expect 0 to be "CAM", but 0 isn't actually
774 * valid here. However, let's not confuse them and present
775 * IWL_POWER_INDEX_1 as "1", not "0".
776 */
Reinette Chatre1a34c042009-10-09 13:20:25 -0700777 if (value == 0)
778 return -EINVAL;
779 else if (value > 0)
Johannes Berge312c242009-08-07 15:41:51 -0700780 value -= 1;
781
782 if (value != -1 && (value < 0 || value >= IWL_POWER_NUM))
783 return -EINVAL;
784
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700785 if (!iwl_is_ready_rf(priv))
786 return -EAGAIN;
787
Johannes Berge312c242009-08-07 15:41:51 -0700788 priv->power_data.debug_sleep_level_override = value;
789
Reinette Chatred3a57192010-01-21 11:52:28 -0800790 mutex_lock(&priv->mutex);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700791 iwl_power_update_mode(priv, true);
Reinette Chatred3a57192010-01-21 11:52:28 -0800792 mutex_unlock(&priv->mutex);
Johannes Berge312c242009-08-07 15:41:51 -0700793
794 return count;
795}
796
797static ssize_t iwl_dbgfs_sleep_level_override_read(struct file *file,
798 char __user *user_buf,
799 size_t count, loff_t *ppos)
800{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700801 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700802 char buf[10];
803 int pos, value;
804 const size_t bufsz = sizeof(buf);
805
806 /* see the write function */
807 value = priv->power_data.debug_sleep_level_override;
808 if (value >= 0)
809 value += 1;
810
811 pos = scnprintf(buf, bufsz, "%d\n", value);
812 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
813}
814
815static ssize_t iwl_dbgfs_current_sleep_command_read(struct file *file,
816 char __user *user_buf,
817 size_t count, loff_t *ppos)
818{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700819 struct iwl_priv *priv = file->private_data;
Johannes Berge312c242009-08-07 15:41:51 -0700820 char buf[200];
821 int pos = 0, i;
822 const size_t bufsz = sizeof(buf);
823 struct iwl_powertable_cmd *cmd = &priv->power_data.sleep_cmd;
824
825 pos += scnprintf(buf + pos, bufsz - pos,
826 "flags: %#.2x\n", le16_to_cpu(cmd->flags));
827 pos += scnprintf(buf + pos, bufsz - pos,
828 "RX/TX timeout: %d/%d usec\n",
829 le32_to_cpu(cmd->rx_data_timeout),
830 le32_to_cpu(cmd->tx_data_timeout));
831 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
832 pos += scnprintf(buf + pos, bufsz - pos,
833 "sleep_interval[%d]: %d\n", i,
834 le32_to_cpu(cmd->sleep_interval[i]));
835
836 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
837}
838
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700839DEBUGFS_READ_WRITE_FILE_OPS(sram);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -0800840DEBUGFS_READ_WRITE_FILE_OPS(log_event);
Wey-Yi Guy0848e292009-05-22 11:01:46 -0700841DEBUGFS_READ_FILE_OPS(nvm);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700842DEBUGFS_READ_FILE_OPS(stations);
Winkler, Tomasd366df52008-12-02 12:14:01 -0800843DEBUGFS_READ_FILE_OPS(channels);
Wey-Yi Guy08df05a2009-03-24 10:02:54 -0700844DEBUGFS_READ_FILE_OPS(status);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700845DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
Wey-Yi Guyf5ad69f2009-07-09 10:33:36 -0700846DEBUGFS_READ_FILE_OPS(qos);
Wey-Yi Guya283c012009-07-17 09:30:19 -0700847DEBUGFS_READ_FILE_OPS(led);
Wey-Yi Guyfbf3a2a2009-07-24 11:13:04 -0700848DEBUGFS_READ_FILE_OPS(thermal_throttling);
Wey-Yi Guy1e4247d42009-07-27 13:50:15 -0700849DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
Johannes Berge312c242009-08-07 15:41:51 -0700850DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
851DEBUGFS_READ_FILE_OPS(current_sleep_command);
Tomas Winkler712b6cf2008-03-12 16:58:52 -0700852
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700853static ssize_t iwl_dbgfs_traffic_log_read(struct file *file,
854 char __user *user_buf,
855 size_t count, loff_t *ppos)
856{
857 struct iwl_priv *priv = file->private_data;
858 int pos = 0, ofs = 0;
859 int cnt = 0, entry;
860 struct iwl_tx_queue *txq;
861 struct iwl_queue *q;
862 struct iwl_rx_queue *rxq = &priv->rxq;
863 char *buf;
864 int bufsz = ((IWL_TRAFFIC_ENTRIES * IWL_TRAFFIC_ENTRY_SIZE * 64) * 2) +
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700865 (priv->cfg->num_of_queues * 32 * 8) + 400;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700866 const u8 *ptr;
867 ssize_t ret;
868
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700869 if (!priv->txq) {
870 IWL_ERR(priv, "txq not ready\n");
871 return -EAGAIN;
872 }
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700873 buf = kzalloc(bufsz, GFP_KERNEL);
874 if (!buf) {
875 IWL_ERR(priv, "Can not allocate buffer\n");
876 return -ENOMEM;
877 }
878 pos += scnprintf(buf + pos, bufsz - pos, "Tx Queue\n");
879 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
880 txq = &priv->txq[cnt];
881 q = &txq->q;
882 pos += scnprintf(buf + pos, bufsz - pos,
883 "q[%d]: read_ptr: %u, write_ptr: %u\n",
884 cnt, q->read_ptr, q->write_ptr);
885 }
886 if (priv->tx_traffic && (iwl_debug_level & IWL_DL_TX)) {
887 ptr = priv->tx_traffic;
888 pos += scnprintf(buf + pos, bufsz - pos,
889 "Tx Traffic idx: %u\n", priv->tx_traffic_idx);
890 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
891 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
892 entry++, ofs += 16) {
893 pos += scnprintf(buf + pos, bufsz - pos,
894 "0x%.4x ", ofs);
895 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
896 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700897 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700898 if (bufsz - pos > 0)
899 buf[pos++] = '\n';
900 }
901 }
902 }
903
904 pos += scnprintf(buf + pos, bufsz - pos, "Rx Queue\n");
905 pos += scnprintf(buf + pos, bufsz - pos,
906 "read: %u, write: %u\n",
907 rxq->read, rxq->write);
908
909 if (priv->rx_traffic && (iwl_debug_level & IWL_DL_RX)) {
910 ptr = priv->rx_traffic;
911 pos += scnprintf(buf + pos, bufsz - pos,
912 "Rx Traffic idx: %u\n", priv->rx_traffic_idx);
913 for (cnt = 0, ofs = 0; cnt < IWL_TRAFFIC_ENTRIES; cnt++) {
914 for (entry = 0; entry < IWL_TRAFFIC_ENTRY_SIZE / 16;
915 entry++, ofs += 16) {
916 pos += scnprintf(buf + pos, bufsz - pos,
917 "0x%.4x ", ofs);
918 hex_dump_to_buffer(ptr + ofs, 16, 16, 2,
919 buf + pos, bufsz - pos, 0);
Reinette Chatre2fac9712009-09-25 14:24:21 -0700920 pos += strlen(buf + pos);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700921 if (bufsz - pos > 0)
922 buf[pos++] = '\n';
923 }
924 }
925 }
926
927 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
928 kfree(buf);
929 return ret;
930}
931
932static ssize_t iwl_dbgfs_traffic_log_write(struct file *file,
933 const char __user *user_buf,
934 size_t count, loff_t *ppos)
935{
936 struct iwl_priv *priv = file->private_data;
937 char buf[8];
938 int buf_size;
939 int traffic_log;
940
941 memset(buf, 0, sizeof(buf));
942 buf_size = min(count, sizeof(buf) - 1);
943 if (copy_from_user(buf, user_buf, buf_size))
944 return -EFAULT;
945 if (sscanf(buf, "%d", &traffic_log) != 1)
946 return -EFAULT;
947 if (traffic_log == 0)
948 iwl_reset_traffic_log(priv);
949
950 return count;
951}
952
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700953static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
954 char __user *user_buf,
955 size_t count, loff_t *ppos) {
956
H Hartley Sweeten28f63a42010-01-08 16:14:10 -0700957 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700958 struct iwl_tx_queue *txq;
959 struct iwl_queue *q;
960 char *buf;
961 int pos = 0;
962 int cnt;
963 int ret;
Wey-Yi Guyd23db552009-11-20 12:04:59 -0800964 const size_t bufsz = sizeof(char) * 64 * priv->cfg->num_of_queues;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700965
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700966 if (!priv->txq) {
967 IWL_ERR(priv, "txq not ready\n");
968 return -EAGAIN;
969 }
Wey-Yi Guy141b03e2009-08-07 15:41:41 -0700970 buf = kzalloc(bufsz, GFP_KERNEL);
971 if (!buf)
972 return -ENOMEM;
973
974 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
975 txq = &priv->txq[cnt];
976 q = &txq->q;
977 pos += scnprintf(buf + pos, bufsz - pos,
978 "hwq %.2d: read=%u write=%u stop=%d"
979 " swq_id=%#.2x (ac %d/hwq %d)\n",
980 cnt, q->read_ptr, q->write_ptr,
981 !!test_bit(cnt, priv->queue_stopped),
982 txq->swq_id,
983 txq->swq_id & 0x80 ? txq->swq_id & 3 :
984 txq->swq_id,
985 txq->swq_id & 0x80 ? (txq->swq_id >> 2) &
986 0x1f : txq->swq_id);
987 if (cnt >= 4)
988 continue;
989 /* for the ACs, display the stop count too */
990 pos += scnprintf(buf + pos, bufsz - pos,
991 " stop-count: %d\n",
992 atomic_read(&priv->queue_stop_count[cnt]));
993 }
994 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
995 kfree(buf);
996 return ret;
997}
998
999static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1000 char __user *user_buf,
1001 size_t count, loff_t *ppos) {
1002
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001003 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001004 struct iwl_rx_queue *rxq = &priv->rxq;
1005 char buf[256];
1006 int pos = 0;
1007 const size_t bufsz = sizeof(buf);
1008
1009 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n",
1010 rxq->read);
1011 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n",
1012 rxq->write);
1013 pos += scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
1014 rxq->free_count);
1015 pos += scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
1016 le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF);
1017 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1018}
1019
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001020static ssize_t iwl_dbgfs_ucode_rx_stats_read(struct file *file,
1021 char __user *user_buf,
1022 size_t count, loff_t *ppos)
1023{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001024 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001025 return priv->cfg->ops->lib->debugfs_ops.rx_stats_read(file,
1026 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001027}
1028
1029static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1030 char __user *user_buf,
1031 size_t count, loff_t *ppos)
1032{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001033 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001034 return priv->cfg->ops->lib->debugfs_ops.tx_stats_read(file,
1035 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001036}
1037
1038static ssize_t iwl_dbgfs_ucode_general_stats_read(struct file *file,
1039 char __user *user_buf,
1040 size_t count, loff_t *ppos)
1041{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001042 struct iwl_priv *priv = file->private_data;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07001043 return priv->cfg->ops->lib->debugfs_ops.general_stats_read(file,
1044 user_buf, count, ppos);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001045}
1046
Wey-Yi Guy52259352009-08-07 15:41:43 -07001047static ssize_t iwl_dbgfs_sensitivity_read(struct file *file,
1048 char __user *user_buf,
1049 size_t count, loff_t *ppos) {
1050
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001051 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001052 int pos = 0;
1053 int cnt = 0;
1054 char *buf;
1055 int bufsz = sizeof(struct iwl_sensitivity_data) * 4 + 100;
1056 ssize_t ret;
1057 struct iwl_sensitivity_data *data;
1058
1059 data = &priv->sensitivity_data;
1060 buf = kzalloc(bufsz, GFP_KERNEL);
1061 if (!buf) {
1062 IWL_ERR(priv, "Can not allocate Buffer\n");
1063 return -ENOMEM;
1064 }
1065
1066 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
1067 data->auto_corr_ofdm);
1068 pos += scnprintf(buf + pos, bufsz - pos,
1069 "auto_corr_ofdm_mrc:\t\t %u\n",
1070 data->auto_corr_ofdm_mrc);
1071 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
1072 data->auto_corr_ofdm_x1);
1073 pos += scnprintf(buf + pos, bufsz - pos,
1074 "auto_corr_ofdm_mrc_x1:\t\t %u\n",
1075 data->auto_corr_ofdm_mrc_x1);
1076 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
1077 data->auto_corr_cck);
1078 pos += scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
1079 data->auto_corr_cck_mrc);
1080 pos += scnprintf(buf + pos, bufsz - pos,
1081 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
1082 data->last_bad_plcp_cnt_ofdm);
1083 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
1084 data->last_fa_cnt_ofdm);
1085 pos += scnprintf(buf + pos, bufsz - pos,
1086 "last_bad_plcp_cnt_cck:\t\t %u\n",
1087 data->last_bad_plcp_cnt_cck);
1088 pos += scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1089 data->last_fa_cnt_cck);
1090 pos += scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1091 data->nrg_curr_state);
1092 pos += scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1093 data->nrg_prev_state);
1094 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1095 for (cnt = 0; cnt < 10; cnt++) {
1096 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1097 data->nrg_value[cnt]);
1098 }
1099 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1100 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1101 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
1102 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1103 data->nrg_silence_rssi[cnt]);
1104 }
1105 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1106 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1107 data->nrg_silence_ref);
1108 pos += scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1109 data->nrg_energy_idx);
1110 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1111 data->nrg_silence_idx);
1112 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1113 data->nrg_th_cck);
1114 pos += scnprintf(buf + pos, bufsz - pos,
1115 "nrg_auto_corr_silence_diff:\t %u\n",
1116 data->nrg_auto_corr_silence_diff);
1117 pos += scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1118 data->num_in_cck_no_fa);
1119 pos += scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1120 data->nrg_th_ofdm);
1121
1122 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1123 kfree(buf);
1124 return ret;
1125}
1126
1127
1128static ssize_t iwl_dbgfs_chain_noise_read(struct file *file,
1129 char __user *user_buf,
1130 size_t count, loff_t *ppos) {
1131
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001132 struct iwl_priv *priv = file->private_data;
Wey-Yi Guy52259352009-08-07 15:41:43 -07001133 int pos = 0;
1134 int cnt = 0;
1135 char *buf;
1136 int bufsz = sizeof(struct iwl_chain_noise_data) * 4 + 100;
1137 ssize_t ret;
1138 struct iwl_chain_noise_data *data;
1139
1140 data = &priv->chain_noise_data;
1141 buf = kzalloc(bufsz, GFP_KERNEL);
1142 if (!buf) {
1143 IWL_ERR(priv, "Can not allocate Buffer\n");
1144 return -ENOMEM;
1145 }
1146
1147 pos += scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1148 data->active_chains);
1149 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1150 data->chain_noise_a);
1151 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1152 data->chain_noise_b);
1153 pos += scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1154 data->chain_noise_c);
1155 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1156 data->chain_signal_a);
1157 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1158 data->chain_signal_b);
1159 pos += scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1160 data->chain_signal_c);
1161 pos += scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1162 data->beacon_count);
1163
1164 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1165 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1166 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1167 data->disconn_array[cnt]);
1168 }
1169 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1170 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1171 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
1172 pos += scnprintf(buf + pos, bufsz - pos, " %u",
1173 data->delta_gain_code[cnt]);
1174 }
1175 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1176 pos += scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1177 data->radio_write);
1178 pos += scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1179 data->state);
1180
1181 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1182 kfree(buf);
1183 return ret;
1184}
1185
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001186static ssize_t iwl_dbgfs_power_save_status_read(struct file *file,
1187 char __user *user_buf,
1188 size_t count, loff_t *ppos)
1189{
H Hartley Sweeten28f63a42010-01-08 16:14:10 -07001190 struct iwl_priv *priv = file->private_data;
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001191 char buf[60];
1192 int pos = 0;
1193 const size_t bufsz = sizeof(buf);
1194 u32 pwrsave_status;
1195
1196 pwrsave_status = iwl_read32(priv, CSR_GP_CNTRL) &
1197 CSR_GP_REG_POWER_SAVE_STATUS_MSK;
1198
1199 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
1200 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
1201 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1202 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1203 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1204 "error");
1205
1206 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1207}
1208
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001209static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08001210 const char __user *user_buf,
1211 size_t count, loff_t *ppos)
1212{
1213 struct iwl_priv *priv = file->private_data;
1214 char buf[8];
1215 int buf_size;
1216 int clear;
1217
1218 memset(buf, 0, sizeof(buf));
1219 buf_size = min(count, sizeof(buf) - 1);
1220 if (copy_from_user(buf, user_buf, buf_size))
1221 return -EFAULT;
1222 if (sscanf(buf, "%d", &clear) != 1)
1223 return -EFAULT;
1224
1225 /* make request to uCode to retrieve statistics information */
1226 mutex_lock(&priv->mutex);
1227 iwl_send_statistics_request(priv, CMD_SYNC, true);
1228 mutex_unlock(&priv->mutex);
1229
1230 return count;
1231}
1232
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08001233static ssize_t iwl_dbgfs_csr_write(struct file *file,
1234 const char __user *user_buf,
1235 size_t count, loff_t *ppos)
1236{
1237 struct iwl_priv *priv = file->private_data;
1238 char buf[8];
1239 int buf_size;
1240 int csr;
1241
1242 memset(buf, 0, sizeof(buf));
1243 buf_size = min(count, sizeof(buf) - 1);
1244 if (copy_from_user(buf, user_buf, buf_size))
1245 return -EFAULT;
1246 if (sscanf(buf, "%d", &csr) != 1)
1247 return -EFAULT;
1248
1249 if (priv->cfg->ops->lib->dump_csr)
1250 priv->cfg->ops->lib->dump_csr(priv);
1251
1252 return count;
1253}
1254
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001255static ssize_t iwl_dbgfs_ucode_tracing_read(struct file *file,
1256 char __user *user_buf,
1257 size_t count, loff_t *ppos) {
1258
1259 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1260 int pos = 0;
1261 char buf[128];
1262 const size_t bufsz = sizeof(buf);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001263
1264 pos += scnprintf(buf + pos, bufsz - pos, "ucode trace timer is %s\n",
1265 priv->event_log.ucode_trace ? "On" : "Off");
1266 pos += scnprintf(buf + pos, bufsz - pos, "non_wraps_count:\t\t %u\n",
1267 priv->event_log.non_wraps_count);
1268 pos += scnprintf(buf + pos, bufsz - pos, "wraps_once_count:\t\t %u\n",
1269 priv->event_log.wraps_once_count);
1270 pos += scnprintf(buf + pos, bufsz - pos, "wraps_more_count:\t\t %u\n",
1271 priv->event_log.wraps_more_count);
1272
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001273 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001274}
1275
1276static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
1277 const char __user *user_buf,
1278 size_t count, loff_t *ppos)
1279{
1280 struct iwl_priv *priv = file->private_data;
1281 char buf[8];
1282 int buf_size;
1283 int trace;
1284
1285 memset(buf, 0, sizeof(buf));
1286 buf_size = min(count, sizeof(buf) - 1);
1287 if (copy_from_user(buf, user_buf, buf_size))
1288 return -EFAULT;
1289 if (sscanf(buf, "%d", &trace) != 1)
1290 return -EFAULT;
1291
1292 if (trace) {
1293 priv->event_log.ucode_trace = true;
1294 /* schedule the ucode timer to occur in UCODE_TRACE_PERIOD */
1295 mod_timer(&priv->ucode_trace,
1296 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
1297 } else {
1298 priv->event_log.ucode_trace = false;
1299 del_timer_sync(&priv->ucode_trace);
1300 }
1301
1302 return count;
1303}
1304
Johannes Berg60987202010-02-18 00:36:07 -08001305static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1306 char __user *user_buf,
1307 size_t count, loff_t *ppos) {
1308
1309 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1310 int len = 0;
1311 char buf[20];
1312
1313 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags));
1314 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1315}
1316
1317static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1318 char __user *user_buf,
1319 size_t count, loff_t *ppos) {
1320
1321 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1322 int len = 0;
1323 char buf[20];
1324
1325 len = sprintf(buf, "0x%04X\n",
1326 le32_to_cpu(priv->active_rxon.filter_flags));
1327 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1328}
1329
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08001330static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1331 char __user *user_buf,
1332 size_t count, loff_t *ppos)
1333{
1334 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1335 char *buf;
1336 int pos = 0;
1337 ssize_t ret = -EFAULT;
1338
1339 if (priv->cfg->ops->lib->dump_fh) {
1340 ret = pos = priv->cfg->ops->lib->dump_fh(priv, &buf, true);
1341 if (buf) {
1342 ret = simple_read_from_buffer(user_buf,
1343 count, ppos, buf, pos);
1344 kfree(buf);
1345 }
1346 }
1347
1348 return ret;
1349}
1350
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001351static ssize_t iwl_dbgfs_missed_beacon_read(struct file *file,
1352 char __user *user_buf,
1353 size_t count, loff_t *ppos) {
1354
1355 struct iwl_priv *priv = file->private_data;
1356 int pos = 0;
1357 char buf[12];
1358 const size_t bufsz = sizeof(buf);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001359
1360 pos += scnprintf(buf + pos, bufsz - pos, "%d\n",
1361 priv->missed_beacon_threshold);
1362
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001363 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001364}
1365
1366static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
1367 const char __user *user_buf,
1368 size_t count, loff_t *ppos)
1369{
1370 struct iwl_priv *priv = file->private_data;
1371 char buf[8];
1372 int buf_size;
1373 int missed;
1374
1375 memset(buf, 0, sizeof(buf));
1376 buf_size = min(count, sizeof(buf) - 1);
1377 if (copy_from_user(buf, user_buf, buf_size))
1378 return -EFAULT;
1379 if (sscanf(buf, "%d", &missed) != 1)
1380 return -EINVAL;
1381
1382 if (missed < IWL_MISSED_BEACON_THRESHOLD_MIN ||
1383 missed > IWL_MISSED_BEACON_THRESHOLD_MAX)
1384 priv->missed_beacon_threshold =
1385 IWL_MISSED_BEACON_THRESHOLD_DEF;
1386 else
1387 priv->missed_beacon_threshold = missed;
1388
1389 return count;
1390}
1391
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001392static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file,
1393 char __user *user_buf,
1394 size_t count, loff_t *ppos) {
1395
1396 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
1397 int pos = 0;
1398 char buf[12];
1399 const size_t bufsz = sizeof(buf);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001400
1401 pos += scnprintf(buf + pos, bufsz - pos, "%u\n",
1402 priv->cfg->plcp_delta_threshold);
1403
Wey-Yi Guy4967c312010-02-18 15:22:07 -08001404 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001405}
1406
1407static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
1408 const char __user *user_buf,
1409 size_t count, loff_t *ppos) {
1410
1411 struct iwl_priv *priv = file->private_data;
1412 char buf[8];
1413 int buf_size;
1414 int plcp;
1415
1416 memset(buf, 0, sizeof(buf));
1417 buf_size = min(count, sizeof(buf) - 1);
1418 if (copy_from_user(buf, user_buf, buf_size))
1419 return -EFAULT;
1420 if (sscanf(buf, "%d", &plcp) != 1)
1421 return -EINVAL;
1422 if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) ||
1423 (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX))
1424 priv->cfg->plcp_delta_threshold =
1425 IWL_MAX_PLCP_ERR_THRESHOLD_DEF;
1426 else
1427 priv->cfg->plcp_delta_threshold = plcp;
1428 return count;
1429}
1430
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001431static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
1432 char __user *user_buf,
1433 size_t count, loff_t *ppos) {
1434
1435 struct iwl_priv *priv = file->private_data;
1436 int i, pos = 0;
1437 char buf[300];
1438 const size_t bufsz = sizeof(buf);
1439 struct iwl_force_reset *force_reset;
1440
1441 for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
1442 force_reset = &priv->force_reset[i];
1443 pos += scnprintf(buf + pos, bufsz - pos,
1444 "Force reset method %d\n", i);
1445 pos += scnprintf(buf + pos, bufsz - pos,
1446 "\tnumber of reset request: %d\n",
1447 force_reset->reset_request_count);
1448 pos += scnprintf(buf + pos, bufsz - pos,
1449 "\tnumber of reset request success: %d\n",
1450 force_reset->reset_success_count);
1451 pos += scnprintf(buf + pos, bufsz - pos,
1452 "\tnumber of reset request reject: %d\n",
1453 force_reset->reset_reject_count);
1454 pos += scnprintf(buf + pos, bufsz - pos,
1455 "\treset duration: %lu\n",
1456 force_reset->reset_duration);
1457 }
1458 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1459}
1460
Wey-Yi Guy04cafd72010-02-03 11:47:20 -08001461static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
1462 const char __user *user_buf,
1463 size_t count, loff_t *ppos) {
1464
1465 struct iwl_priv *priv = file->private_data;
1466 char buf[8];
1467 int buf_size;
1468 int reset, ret;
1469
1470 memset(buf, 0, sizeof(buf));
1471 buf_size = min(count, sizeof(buf) - 1);
1472 if (copy_from_user(buf, user_buf, buf_size))
1473 return -EFAULT;
1474 if (sscanf(buf, "%d", &reset) != 1)
1475 return -EINVAL;
1476 switch (reset) {
1477 case IWL_RF_RESET:
1478 case IWL_FW_RESET:
1479 ret = iwl_force_reset(priv, reset);
1480 break;
1481 default:
1482 return -EINVAL;
1483 }
1484 return ret ? ret : count;
1485}
1486
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001487DEBUGFS_READ_FILE_OPS(rx_statistics);
1488DEBUGFS_READ_FILE_OPS(tx_statistics);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001489DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
Wey-Yi Guy141b03e2009-08-07 15:41:41 -07001490DEBUGFS_READ_FILE_OPS(rx_queue);
1491DEBUGFS_READ_FILE_OPS(tx_queue);
Wey-Yi Guye8fe59a2009-08-07 15:41:42 -07001492DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1493DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1494DEBUGFS_READ_FILE_OPS(ucode_general_stats);
Wey-Yi Guy52259352009-08-07 15:41:43 -07001495DEBUGFS_READ_FILE_OPS(sensitivity);
1496DEBUGFS_READ_FILE_OPS(chain_noise);
Wey-Yi Guyc09430a2009-10-16 14:25:50 -07001497DEBUGFS_READ_FILE_OPS(power_save_status);
Wey-Yi Guy7163b8a2009-11-20 12:04:56 -08001498DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics);
1499DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
Wey-Yi Guy696bdee2009-12-10 14:37:25 -08001500DEBUGFS_WRITE_FILE_OPS(csr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08001501DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
Wey-Yi Guy1b3eb822010-01-15 13:43:39 -08001502DEBUGFS_READ_FILE_OPS(fh_reg);
Wey-Yi Guya13d2762010-01-22 14:22:42 -08001503DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -08001504DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001505DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
Johannes Berg60987202010-02-18 00:36:07 -08001506DEBUGFS_READ_FILE_OPS(rxon_flags);
1507DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07001508
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001509/*
1510 * Create the debugfs files and directories
1511 *
1512 */
1513int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
1514{
Zhu Yi95b1a822008-05-29 16:34:50 +08001515 struct dentry *phyd = priv->hw->wiphy->debugfsdir;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001516 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001517
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001518 dir_drv = debugfs_create_dir(name, phyd);
1519 if (!dir_drv)
1520 return -ENOMEM;
1521
1522 priv->debugfs_dir = dir_drv;
1523
1524 dir_data = debugfs_create_dir("data", dir_drv);
1525 if (!dir_data)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001526 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001527 dir_rf = debugfs_create_dir("rf", dir_drv);
1528 if (!dir_rf)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001529 goto err;
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001530 dir_debug = debugfs_create_dir("debug", dir_drv);
1531 if (!dir_debug)
1532 goto err;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001533
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001534 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1535 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
1536 DEBUGFS_ADD_FILE(log_event, dir_data, S_IWUSR | S_IRUSR);
1537 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1538 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1539 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1540 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1541 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1542 DEBUGFS_ADD_FILE(led, dir_data, S_IRUSR);
Wey-Yi Guy381733c2010-04-25 09:39:46 -07001543 if (!priv->cfg->broken_powersave) {
1544 DEBUGFS_ADD_FILE(sleep_level_override, dir_data,
1545 S_IWUSR | S_IRUSR);
1546 DEBUGFS_ADD_FILE(current_sleep_command, dir_data, S_IRUSR);
1547 }
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001548 DEBUGFS_ADD_FILE(thermal_throttling, dir_data, S_IRUSR);
1549 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
1550 DEBUGFS_ADD_FILE(rx_statistics, dir_debug, S_IRUSR);
1551 DEBUGFS_ADD_FILE(tx_statistics, dir_debug, S_IRUSR);
1552 DEBUGFS_ADD_FILE(traffic_log, dir_debug, S_IWUSR | S_IRUSR);
1553 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1554 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001555 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
1556 DEBUGFS_ADD_FILE(clear_ucode_statistics, dir_debug, S_IWUSR);
1557 DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
1558 DEBUGFS_ADD_FILE(csr, dir_debug, S_IWUSR);
1559 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1560 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001561 DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
Wey-Yi Guy528c3122010-02-18 22:03:07 -08001562 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
Abhijeet Kolekarb8c76262010-04-08 15:29:07 -07001563 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1564 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1565 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1566
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001567 if (priv->cfg->sensitivity_calib_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001568 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001569 if (priv->cfg->chain_noise_calib_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001570 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
Wey-Yi Guy6e5c8002010-04-27 14:00:28 -07001571 if (priv->cfg->ucode_tracing)
1572 DEBUGFS_ADD_FILE(ucode_tracing, dir_debug, S_IWUSR | S_IRUSR);
Johannes Berg60987202010-02-18 00:36:07 -08001573 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1574 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
Wey-Yi Guy65d1f892010-04-25 15:41:43 -07001575 if (priv->cfg->sensitivity_calib_by_driver)
1576 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
1577 &priv->disable_sens_cal);
1578 if (priv->cfg->chain_noise_calib_by_driver)
1579 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
1580 &priv->disable_chain_noise_cal);
Wey-Yi Guy4e7033e2010-04-27 14:33:33 -07001581 if (priv->cfg->tx_power_by_driver)
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001582 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf,
Wey-Yi Guy030b8652009-06-12 13:22:55 -07001583 &priv->disable_tx_power_cal);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001584 return 0;
1585
1586err:
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001587 IWL_ERR(priv, "Can't create the debugfs directory\n");
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001588 iwl_dbgfs_unregister(priv);
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001589 return -ENOMEM;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001590}
1591EXPORT_SYMBOL(iwl_dbgfs_register);
1592
1593/**
1594 * Remove the debugfs files and directories
1595 *
1596 */
1597void iwl_dbgfs_unregister(struct iwl_priv *priv)
1598{
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001599 if (!priv->debugfs_dir)
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001600 return;
1601
Johannes Berg4c84a8f2010-01-22 14:22:54 -08001602 debugfs_remove_recursive(priv->debugfs_dir);
1603 priv->debugfs_dir = NULL;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001604}
1605EXPORT_SYMBOL(iwl_dbgfs_unregister);
1606
1607
Tomas Winkler445c2df2008-05-15 13:54:16 +08001608