Merge tag 'for_linus-3.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/jwesse...
[deliverable/linux.git] / drivers / net / wireless / iwlegacy / debug.c
CommitLineData
be663ab6
WYG
1/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
5 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
6 *
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:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#include <linux/ieee80211.h>
515db093 29#include <linux/export.h>
be663ab6
WYG
30#include <net/mac80211.h>
31
98613be0 32#include "common.h"
be663ab6 33
288f9954
SG
34void
35il_clear_traffic_stats(struct il_priv *il)
36{
37 memset(&il->tx_stats, 0, sizeof(struct traffic_stats));
38 memset(&il->rx_stats, 0, sizeof(struct traffic_stats));
39}
40
41/*
42 * il_update_stats function record all the MGMT, CTRL and DATA pkt for
43 * both TX and Rx . Use debugfs to display the rx/rx_stats
44 */
45void
46il_update_stats(struct il_priv *il, bool is_tx, __le16 fc, u16 len)
47{
48 struct traffic_stats *stats;
49
50 if (is_tx)
51 stats = &il->tx_stats;
52 else
53 stats = &il->rx_stats;
54
55 if (ieee80211_is_mgmt(fc)) {
56 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
57 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
58 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
59 break;
60 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
61 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
62 break;
63 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
64 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
65 break;
66 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
67 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
68 break;
69 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
70 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
71 break;
72 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
73 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
74 break;
75 case cpu_to_le16(IEEE80211_STYPE_BEACON):
76 stats->mgmt[MANAGEMENT_BEACON]++;
77 break;
78 case cpu_to_le16(IEEE80211_STYPE_ATIM):
79 stats->mgmt[MANAGEMENT_ATIM]++;
80 break;
81 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
82 stats->mgmt[MANAGEMENT_DISASSOC]++;
83 break;
84 case cpu_to_le16(IEEE80211_STYPE_AUTH):
85 stats->mgmt[MANAGEMENT_AUTH]++;
86 break;
87 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
88 stats->mgmt[MANAGEMENT_DEAUTH]++;
89 break;
90 case cpu_to_le16(IEEE80211_STYPE_ACTION):
91 stats->mgmt[MANAGEMENT_ACTION]++;
92 break;
93 }
94 } else if (ieee80211_is_ctl(fc)) {
95 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
96 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
97 stats->ctrl[CONTROL_BACK_REQ]++;
98 break;
99 case cpu_to_le16(IEEE80211_STYPE_BACK):
100 stats->ctrl[CONTROL_BACK]++;
101 break;
102 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
103 stats->ctrl[CONTROL_PSPOLL]++;
104 break;
105 case cpu_to_le16(IEEE80211_STYPE_RTS):
106 stats->ctrl[CONTROL_RTS]++;
107 break;
108 case cpu_to_le16(IEEE80211_STYPE_CTS):
109 stats->ctrl[CONTROL_CTS]++;
110 break;
111 case cpu_to_le16(IEEE80211_STYPE_ACK):
112 stats->ctrl[CONTROL_ACK]++;
113 break;
114 case cpu_to_le16(IEEE80211_STYPE_CFEND):
115 stats->ctrl[CONTROL_CFEND]++;
116 break;
117 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
118 stats->ctrl[CONTROL_CFENDACK]++;
119 break;
120 }
121 } else {
122 /* data */
123 stats->data_cnt++;
124 stats->data_bytes += len;
125 }
126}
127EXPORT_SYMBOL(il_update_stats);
128
be663ab6
WYG
129/* create and remove of files */
130#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
46bc8d4b 131 if (!debugfs_create_file(#name, mode, parent, il, \
e2ebc833 132 &il_dbgfs_##name##_ops)) \
be663ab6
WYG
133 goto err; \
134} while (0)
135
136#define DEBUGFS_ADD_BOOL(name, parent, ptr) do { \
137 struct dentry *__tmp; \
138 __tmp = debugfs_create_bool(#name, S_IWUSR | S_IRUSR, \
139 parent, ptr); \
140 if (IS_ERR(__tmp) || !__tmp) \
141 goto err; \
142} while (0)
143
144#define DEBUGFS_ADD_X32(name, parent, ptr) do { \
145 struct dentry *__tmp; \
146 __tmp = debugfs_create_x32(#name, S_IWUSR | S_IRUSR, \
147 parent, ptr); \
148 if (IS_ERR(__tmp) || !__tmp) \
149 goto err; \
150} while (0)
151
152/* file operation */
153#define DEBUGFS_READ_FUNC(name) \
e2ebc833 154static ssize_t il_dbgfs_##name##_read(struct file *file, \
be663ab6
WYG
155 char __user *user_buf, \
156 size_t count, loff_t *ppos);
157
158#define DEBUGFS_WRITE_FUNC(name) \
e2ebc833 159static ssize_t il_dbgfs_##name##_write(struct file *file, \
be663ab6
WYG
160 const char __user *user_buf, \
161 size_t count, loff_t *ppos);
162
be663ab6 163static int
e2ebc833 164il_dbgfs_open_file_generic(struct inode *inode, struct file *file)
be663ab6
WYG
165{
166 file->private_data = inode->i_private;
167 return 0;
168}
169
1722f8e1
SG
170#define DEBUGFS_READ_FILE_OPS(name) \
171 DEBUGFS_READ_FUNC(name); \
e2ebc833
SG
172static const struct file_operations il_dbgfs_##name##_ops = { \
173 .read = il_dbgfs_##name##_read, \
1722f8e1
SG
174 .open = il_dbgfs_open_file_generic, \
175 .llseek = generic_file_llseek, \
be663ab6
WYG
176};
177
1722f8e1
SG
178#define DEBUGFS_WRITE_FILE_OPS(name) \
179 DEBUGFS_WRITE_FUNC(name); \
e2ebc833
SG
180static const struct file_operations il_dbgfs_##name##_ops = { \
181 .write = il_dbgfs_##name##_write, \
1722f8e1
SG
182 .open = il_dbgfs_open_file_generic, \
183 .llseek = generic_file_llseek, \
be663ab6
WYG
184};
185
1722f8e1
SG
186#define DEBUGFS_READ_WRITE_FILE_OPS(name) \
187 DEBUGFS_READ_FUNC(name); \
188 DEBUGFS_WRITE_FUNC(name); \
e2ebc833
SG
189static const struct file_operations il_dbgfs_##name##_ops = { \
190 .write = il_dbgfs_##name##_write, \
191 .read = il_dbgfs_##name##_read, \
192 .open = il_dbgfs_open_file_generic, \
1722f8e1 193 .llseek = generic_file_llseek, \
be663ab6
WYG
194};
195
288f9954
SG
196static const char *
197il_get_mgmt_string(int cmd)
198{
199 switch (cmd) {
200 IL_CMD(MANAGEMENT_ASSOC_REQ);
201 IL_CMD(MANAGEMENT_ASSOC_RESP);
202 IL_CMD(MANAGEMENT_REASSOC_REQ);
203 IL_CMD(MANAGEMENT_REASSOC_RESP);
204 IL_CMD(MANAGEMENT_PROBE_REQ);
205 IL_CMD(MANAGEMENT_PROBE_RESP);
206 IL_CMD(MANAGEMENT_BEACON);
207 IL_CMD(MANAGEMENT_ATIM);
208 IL_CMD(MANAGEMENT_DISASSOC);
209 IL_CMD(MANAGEMENT_AUTH);
210 IL_CMD(MANAGEMENT_DEAUTH);
211 IL_CMD(MANAGEMENT_ACTION);
212 default:
213 return "UNKNOWN";
214
215 }
216}
217
218static const char *
219il_get_ctrl_string(int cmd)
220{
221 switch (cmd) {
222 IL_CMD(CONTROL_BACK_REQ);
223 IL_CMD(CONTROL_BACK);
224 IL_CMD(CONTROL_PSPOLL);
225 IL_CMD(CONTROL_RTS);
226 IL_CMD(CONTROL_CTS);
227 IL_CMD(CONTROL_ACK);
228 IL_CMD(CONTROL_CFEND);
229 IL_CMD(CONTROL_CFENDACK);
230 default:
231 return "UNKNOWN";
232
233 }
234}
235
e7392364 236static ssize_t
1722f8e1
SG
237il_dbgfs_tx_stats_read(struct file *file, char __user *user_buf, size_t count,
238 loff_t *ppos)
e7392364 239{
be663ab6 240
46bc8d4b 241 struct il_priv *il = file->private_data;
be663ab6
WYG
242 char *buf;
243 int pos = 0;
244
245 int cnt;
246 ssize_t ret;
e7392364
SG
247 const size_t bufsz =
248 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
be663ab6
WYG
249 buf = kzalloc(bufsz, GFP_KERNEL);
250 if (!buf)
251 return -ENOMEM;
252 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
253 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
e7392364
SG
254 pos +=
255 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
256 il_get_mgmt_string(cnt), il->tx_stats.mgmt[cnt]);
be663ab6
WYG
257 }
258 pos += scnprintf(buf + pos, bufsz - pos, "Control\n");
259 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
e7392364
SG
260 pos +=
261 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
262 il_get_ctrl_string(cnt), il->tx_stats.ctrl[cnt]);
be663ab6
WYG
263 }
264 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
e7392364
SG
265 pos +=
266 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
267 il->tx_stats.data_cnt);
268 pos +=
269 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
270 il->tx_stats.data_bytes);
be663ab6
WYG
271 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
272 kfree(buf);
273 return ret;
274}
275
276static ssize_t
ebf0d90d 277il_dbgfs_clear_traffic_stats_write(struct file *file,
1722f8e1
SG
278 const char __user *user_buf, size_t count,
279 loff_t *ppos)
be663ab6 280{
46bc8d4b 281 struct il_priv *il = file->private_data;
be663ab6
WYG
282 u32 clear_flag;
283 char buf[8];
284 int buf_size;
285
286 memset(buf, 0, sizeof(buf));
e7392364 287 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
288 if (copy_from_user(buf, user_buf, buf_size))
289 return -EFAULT;
290 if (sscanf(buf, "%x", &clear_flag) != 1)
291 return -EFAULT;
46bc8d4b 292 il_clear_traffic_stats(il);
be663ab6
WYG
293
294 return count;
295}
296
e7392364 297static ssize_t
1722f8e1
SG
298il_dbgfs_rx_stats_read(struct file *file, char __user *user_buf, size_t count,
299 loff_t *ppos)
e7392364 300{
be663ab6 301
46bc8d4b 302 struct il_priv *il = file->private_data;
be663ab6
WYG
303 char *buf;
304 int pos = 0;
305 int cnt;
306 ssize_t ret;
e7392364
SG
307 const size_t bufsz =
308 100 + sizeof(char) * 50 * (MANAGEMENT_MAX + CONTROL_MAX);
be663ab6
WYG
309 buf = kzalloc(bufsz, GFP_KERNEL);
310 if (!buf)
311 return -ENOMEM;
312
313 pos += scnprintf(buf + pos, bufsz - pos, "Management:\n");
314 for (cnt = 0; cnt < MANAGEMENT_MAX; cnt++) {
e7392364
SG
315 pos +=
316 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
317 il_get_mgmt_string(cnt), il->rx_stats.mgmt[cnt]);
be663ab6
WYG
318 }
319 pos += scnprintf(buf + pos, bufsz - pos, "Control:\n");
320 for (cnt = 0; cnt < CONTROL_MAX; cnt++) {
e7392364
SG
321 pos +=
322 scnprintf(buf + pos, bufsz - pos, "\t%25s\t\t: %u\n",
323 il_get_ctrl_string(cnt), il->rx_stats.ctrl[cnt]);
be663ab6
WYG
324 }
325 pos += scnprintf(buf + pos, bufsz - pos, "Data:\n");
e7392364
SG
326 pos +=
327 scnprintf(buf + pos, bufsz - pos, "\tcnt: %u\n",
328 il->rx_stats.data_cnt);
329 pos +=
330 scnprintf(buf + pos, bufsz - pos, "\tbytes: %llu\n",
331 il->rx_stats.data_bytes);
be663ab6
WYG
332
333 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
334 kfree(buf);
335 return ret;
336}
337
338#define BYTE1_MASK 0x000000ff;
339#define BYTE2_MASK 0x0000ffff;
340#define BYTE3_MASK 0x00ffffff;
e7392364 341static ssize_t
1722f8e1
SG
342il_dbgfs_sram_read(struct file *file, char __user *user_buf, size_t count,
343 loff_t *ppos)
be663ab6
WYG
344{
345 u32 val;
346 char *buf;
347 ssize_t ret;
348 int i;
349 int pos = 0;
46bc8d4b 350 struct il_priv *il = file->private_data;
be663ab6
WYG
351 size_t bufsz;
352
353 /* default is to dump the entire data segment */
46bc8d4b
SG
354 if (!il->dbgfs_sram_offset && !il->dbgfs_sram_len) {
355 il->dbgfs_sram_offset = 0x800000;
356 if (il->ucode_type == UCODE_INIT)
357 il->dbgfs_sram_len = il->ucode_init_data.len;
be663ab6 358 else
46bc8d4b 359 il->dbgfs_sram_len = il->ucode_data.len;
be663ab6 360 }
e7392364 361 bufsz = 30 + il->dbgfs_sram_len * sizeof(char) * 10;
be663ab6
WYG
362 buf = kmalloc(bufsz, GFP_KERNEL);
363 if (!buf)
364 return -ENOMEM;
e7392364
SG
365 pos +=
366 scnprintf(buf + pos, bufsz - pos, "sram_len: 0x%x\n",
367 il->dbgfs_sram_len);
368 pos +=
369 scnprintf(buf + pos, bufsz - pos, "sram_offset: 0x%x\n",
370 il->dbgfs_sram_offset);
46bc8d4b 371 for (i = il->dbgfs_sram_len; i > 0; i -= 4) {
e7392364
SG
372 val =
373 il_read_targ_mem(il,
374 il->dbgfs_sram_offset +
375 il->dbgfs_sram_len - i);
be663ab6
WYG
376 if (i < 4) {
377 switch (i) {
378 case 1:
379 val &= BYTE1_MASK;
380 break;
381 case 2:
382 val &= BYTE2_MASK;
383 break;
384 case 3:
385 val &= BYTE3_MASK;
386 break;
387 }
388 }
389 if (!(i % 16))
390 pos += scnprintf(buf + pos, bufsz - pos, "\n");
391 pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
392 }
393 pos += scnprintf(buf + pos, bufsz - pos, "\n");
394
395 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
396 kfree(buf);
397 return ret;
398}
399
e7392364 400static ssize_t
1722f8e1
SG
401il_dbgfs_sram_write(struct file *file, const char __user *user_buf,
402 size_t count, loff_t *ppos)
be663ab6 403{
46bc8d4b 404 struct il_priv *il = file->private_data;
be663ab6
WYG
405 char buf[64];
406 int buf_size;
407 u32 offset, len;
408
409 memset(buf, 0, sizeof(buf));
e7392364 410 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
411 if (copy_from_user(buf, user_buf, buf_size))
412 return -EFAULT;
413
414 if (sscanf(buf, "%x,%x", &offset, &len) == 2) {
46bc8d4b
SG
415 il->dbgfs_sram_offset = offset;
416 il->dbgfs_sram_len = len;
be663ab6 417 } else {
46bc8d4b
SG
418 il->dbgfs_sram_offset = 0;
419 il->dbgfs_sram_len = 0;
be663ab6
WYG
420 }
421
422 return count;
423}
424
425static ssize_t
1722f8e1
SG
426il_dbgfs_stations_read(struct file *file, char __user *user_buf, size_t count,
427 loff_t *ppos)
be663ab6 428{
46bc8d4b 429 struct il_priv *il = file->private_data;
e2ebc833 430 struct il_station_entry *station;
46bc8d4b 431 int max_sta = il->hw_params.max_stations;
be663ab6
WYG
432 char *buf;
433 int i, j, pos = 0;
434 ssize_t ret;
435 /* Add 30 for initial string */
46bc8d4b 436 const size_t bufsz = 30 + sizeof(char) * 500 * (il->num_stations);
be663ab6
WYG
437
438 buf = kmalloc(bufsz, GFP_KERNEL);
439 if (!buf)
440 return -ENOMEM;
441
e7392364
SG
442 pos +=
443 scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
444 il->num_stations);
be663ab6
WYG
445
446 for (i = 0; i < max_sta; i++) {
46bc8d4b 447 station = &il->stations[i];
be663ab6
WYG
448 if (!station->used)
449 continue;
e7392364
SG
450 pos +=
451 scnprintf(buf + pos, bufsz - pos,
452 "station %d - addr: %pM, flags: %#x\n", i,
453 station->sta.sta.addr,
454 station->sta.station_flags_msk);
455 pos +=
456 scnprintf(buf + pos, bufsz - pos,
457 "TID\tseq_num\ttxq_id\tframes\ttfds\t");
458 pos +=
459 scnprintf(buf + pos, bufsz - pos,
460 "start_idx\tbitmap\t\t\trate_n_flags\n");
be663ab6
WYG
461
462 for (j = 0; j < MAX_TID_COUNT; j++) {
e7392364
SG
463 pos +=
464 scnprintf(buf + pos, bufsz - pos,
465 "%d:\t%#x\t%#x\t%u\t%u\t%u\t\t%#.16llx\t%#x",
466 j, station->tid[j].seq_number,
467 station->tid[j].agg.txq_id,
468 station->tid[j].agg.frame_count,
469 station->tid[j].tfds_in_queue,
470 station->tid[j].agg.start_idx,
471 station->tid[j].agg.bitmap,
472 station->tid[j].agg.rate_n_flags);
be663ab6
WYG
473
474 if (station->tid[j].agg.wait_for_ba)
e7392364
SG
475 pos +=
476 scnprintf(buf + pos, bufsz - pos,
477 " - waitforba");
be663ab6
WYG
478 pos += scnprintf(buf + pos, bufsz - pos, "\n");
479 }
480
481 pos += scnprintf(buf + pos, bufsz - pos, "\n");
482 }
483
484 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
485 kfree(buf);
486 return ret;
487}
488
e7392364 489static ssize_t
1722f8e1
SG
490il_dbgfs_nvm_read(struct file *file, char __user *user_buf, size_t count,
491 loff_t *ppos)
be663ab6
WYG
492{
493 ssize_t ret;
46bc8d4b 494 struct il_priv *il = file->private_data;
be663ab6
WYG
495 int pos = 0, ofs = 0, buf_size = 0;
496 const u8 *ptr;
497 char *buf;
498 u16 eeprom_ver;
89ef1ed2 499 size_t eeprom_len = il->cfg->eeprom_size;
be663ab6
WYG
500 buf_size = 4 * eeprom_len + 256;
501
502 if (eeprom_len % 16) {
9406f797 503 IL_ERR("NVM size is not multiple of 16.\n");
be663ab6
WYG
504 return -ENODATA;
505 }
506
46bc8d4b 507 ptr = il->eeprom;
be663ab6 508 if (!ptr) {
9406f797 509 IL_ERR("Invalid EEPROM memory\n");
be663ab6
WYG
510 return -ENOMEM;
511 }
512
513 /* 4 characters for byte 0xYY */
514 buf = kzalloc(buf_size, GFP_KERNEL);
515 if (!buf) {
9406f797 516 IL_ERR("Can not allocate Buffer\n");
be663ab6
WYG
517 return -ENOMEM;
518 }
46bc8d4b 519 eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
e7392364
SG
520 pos +=
521 scnprintf(buf + pos, buf_size - pos, "EEPROM " "version: 0x%x\n",
522 eeprom_ver);
523 for (ofs = 0; ofs < eeprom_len; ofs += 16) {
be663ab6 524 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
e7392364 525 hex_dump_to_buffer(ptr + ofs, 16, 16, 2, buf + pos,
be663ab6
WYG
526 buf_size - pos, 0);
527 pos += strlen(buf + pos);
528 if (buf_size - pos > 0)
529 buf[pos++] = '\n';
530 }
531
532 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
533 kfree(buf);
534 return ret;
535}
536
be663ab6 537static ssize_t
1722f8e1
SG
538il_dbgfs_channels_read(struct file *file, char __user *user_buf, size_t count,
539 loff_t *ppos)
be663ab6 540{
46bc8d4b 541 struct il_priv *il = file->private_data;
be663ab6
WYG
542 struct ieee80211_channel *channels = NULL;
543 const struct ieee80211_supported_band *supp_band = NULL;
544 int pos = 0, i, bufsz = PAGE_SIZE;
545 char *buf;
546 ssize_t ret;
547
a6766ccd 548 if (!test_bit(S_GEO_CONFIGURED, &il->status))
be663ab6
WYG
549 return -EAGAIN;
550
551 buf = kzalloc(bufsz, GFP_KERNEL);
552 if (!buf) {
9406f797 553 IL_ERR("Can not allocate Buffer\n");
be663ab6
WYG
554 return -ENOMEM;
555 }
556
46bc8d4b 557 supp_band = il_get_hw_mode(il, IEEE80211_BAND_2GHZ);
be663ab6
WYG
558 if (supp_band) {
559 channels = supp_band->channels;
560
e7392364
SG
561 pos +=
562 scnprintf(buf + pos, bufsz - pos,
563 "Displaying %d channels in 2.4GHz band 802.11bg):\n",
564 supp_band->n_channels);
be663ab6
WYG
565
566 for (i = 0; i < supp_band->n_channels; i++)
e7392364
SG
567 pos +=
568 scnprintf(buf + pos, bufsz - pos,
569 "%d: %ddBm: BSS%s%s, %s.\n",
570 channels[i].hw_value,
571 channels[i].max_power,
572 channels[i].
573 flags & IEEE80211_CHAN_RADAR ?
574 " (IEEE 802.11h required)" : "",
575 ((channels[i].
576 flags & IEEE80211_CHAN_NO_IBSS) ||
577 (channels[i].
578 flags & IEEE80211_CHAN_RADAR)) ? "" :
579 ", IBSS",
580 channels[i].
581 flags & IEEE80211_CHAN_PASSIVE_SCAN ?
582 "passive only" : "active/passive");
be663ab6 583 }
46bc8d4b 584 supp_band = il_get_hw_mode(il, IEEE80211_BAND_5GHZ);
be663ab6
WYG
585 if (supp_band) {
586 channels = supp_band->channels;
587
e7392364
SG
588 pos +=
589 scnprintf(buf + pos, bufsz - pos,
590 "Displaying %d channels in 5.2GHz band (802.11a)\n",
591 supp_band->n_channels);
be663ab6
WYG
592
593 for (i = 0; i < supp_band->n_channels; i++)
e7392364
SG
594 pos +=
595 scnprintf(buf + pos, bufsz - pos,
596 "%d: %ddBm: BSS%s%s, %s.\n",
597 channels[i].hw_value,
598 channels[i].max_power,
599 channels[i].
600 flags & IEEE80211_CHAN_RADAR ?
601 " (IEEE 802.11h required)" : "",
602 ((channels[i].
603 flags & IEEE80211_CHAN_NO_IBSS) ||
604 (channels[i].
605 flags & IEEE80211_CHAN_RADAR)) ? "" :
606 ", IBSS",
607 channels[i].
608 flags & IEEE80211_CHAN_PASSIVE_SCAN ?
609 "passive only" : "active/passive");
be663ab6
WYG
610 }
611 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
612 kfree(buf);
613 return ret;
614}
615
e7392364 616static ssize_t
1722f8e1
SG
617il_dbgfs_status_read(struct file *file, char __user *user_buf, size_t count,
618 loff_t *ppos)
e7392364 619{
be663ab6 620
46bc8d4b 621 struct il_priv *il = file->private_data;
be663ab6
WYG
622 char buf[512];
623 int pos = 0;
624 const size_t bufsz = sizeof(buf);
625
e7392364
SG
626 pos +=
627 scnprintf(buf + pos, bufsz - pos, "S_HCMD_ACTIVE:\t %d\n",
628 test_bit(S_HCMD_ACTIVE, &il->status));
629 pos +=
630 scnprintf(buf + pos, bufsz - pos, "S_INT_ENABLED:\t %d\n",
631 test_bit(S_INT_ENABLED, &il->status));
632 pos +=
bc269a8e
SG
633 scnprintf(buf + pos, bufsz - pos, "S_RFKILL:\t %d\n",
634 test_bit(S_RFKILL, &il->status));
e7392364
SG
635 pos +=
636 scnprintf(buf + pos, bufsz - pos, "S_CT_KILL:\t\t %d\n",
637 test_bit(S_CT_KILL, &il->status));
638 pos +=
639 scnprintf(buf + pos, bufsz - pos, "S_INIT:\t\t %d\n",
640 test_bit(S_INIT, &il->status));
641 pos +=
642 scnprintf(buf + pos, bufsz - pos, "S_ALIVE:\t\t %d\n",
643 test_bit(S_ALIVE, &il->status));
644 pos +=
645 scnprintf(buf + pos, bufsz - pos, "S_READY:\t\t %d\n",
646 test_bit(S_READY, &il->status));
647 pos +=
648 scnprintf(buf + pos, bufsz - pos, "S_TEMPERATURE:\t %d\n",
649 test_bit(S_TEMPERATURE, &il->status));
650 pos +=
651 scnprintf(buf + pos, bufsz - pos, "S_GEO_CONFIGURED:\t %d\n",
652 test_bit(S_GEO_CONFIGURED, &il->status));
653 pos +=
654 scnprintf(buf + pos, bufsz - pos, "S_EXIT_PENDING:\t %d\n",
655 test_bit(S_EXIT_PENDING, &il->status));
656 pos +=
657 scnprintf(buf + pos, bufsz - pos, "S_STATS:\t %d\n",
658 test_bit(S_STATS, &il->status));
659 pos +=
660 scnprintf(buf + pos, bufsz - pos, "S_SCANNING:\t %d\n",
661 test_bit(S_SCANNING, &il->status));
662 pos +=
663 scnprintf(buf + pos, bufsz - pos, "S_SCAN_ABORTING:\t %d\n",
664 test_bit(S_SCAN_ABORTING, &il->status));
665 pos +=
666 scnprintf(buf + pos, bufsz - pos, "S_SCAN_HW:\t\t %d\n",
667 test_bit(S_SCAN_HW, &il->status));
668 pos +=
669 scnprintf(buf + pos, bufsz - pos, "S_POWER_PMI:\t %d\n",
670 test_bit(S_POWER_PMI, &il->status));
671 pos +=
672 scnprintf(buf + pos, bufsz - pos, "S_FW_ERROR:\t %d\n",
673 test_bit(S_FW_ERROR, &il->status));
be663ab6
WYG
674 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
675}
676
e7392364 677static ssize_t
1722f8e1
SG
678il_dbgfs_interrupt_read(struct file *file, char __user *user_buf, size_t count,
679 loff_t *ppos)
e7392364 680{
be663ab6 681
46bc8d4b 682 struct il_priv *il = file->private_data;
be663ab6
WYG
683 int pos = 0;
684 int cnt = 0;
685 char *buf;
e7392364 686 int bufsz = 24 * 64; /* 24 items * 64 char per item */
be663ab6
WYG
687 ssize_t ret;
688
689 buf = kzalloc(bufsz, GFP_KERNEL);
690 if (!buf) {
9406f797 691 IL_ERR("Can not allocate Buffer\n");
be663ab6
WYG
692 return -ENOMEM;
693 }
694
e7392364
SG
695 pos +=
696 scnprintf(buf + pos, bufsz - pos, "Interrupt Statistics Report:\n");
be663ab6 697
e7392364
SG
698 pos +=
699 scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
700 il->isr_stats.hw);
701 pos +=
702 scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
703 il->isr_stats.sw);
46bc8d4b 704 if (il->isr_stats.sw || il->isr_stats.hw) {
e7392364
SG
705 pos +=
706 scnprintf(buf + pos, bufsz - pos,
707 "\tLast Restarting Code: 0x%X\n",
708 il->isr_stats.err_code);
be663ab6 709 }
d3175167 710#ifdef CONFIG_IWLEGACY_DEBUG
e7392364
SG
711 pos +=
712 scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
713 il->isr_stats.sch);
714 pos +=
715 scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
716 il->isr_stats.alive);
be663ab6 717#endif
e7392364
SG
718 pos +=
719 scnprintf(buf + pos, bufsz - pos,
720 "HW RF KILL switch toggled:\t %u\n",
721 il->isr_stats.rfkill);
722
723 pos +=
724 scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
725 il->isr_stats.ctkill);
726
727 pos +=
728 scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
729 il->isr_stats.wakeup);
730
731 pos +=
732 scnprintf(buf + pos, bufsz - pos, "Rx command responses:\t\t %u\n",
733 il->isr_stats.rx);
4d69c752 734 for (cnt = 0; cnt < IL_CN_MAX; cnt++) {
d0c72347 735 if (il->isr_stats.handlers[cnt] > 0)
e7392364
SG
736 pos +=
737 scnprintf(buf + pos, bufsz - pos,
738 "\tRx handler[%36s]:\t\t %u\n",
739 il_get_cmd_string(cnt),
740 il->isr_stats.handlers[cnt]);
be663ab6
WYG
741 }
742
e7392364
SG
743 pos +=
744 scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
745 il->isr_stats.tx);
be663ab6 746
e7392364
SG
747 pos +=
748 scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
749 il->isr_stats.unhandled);
be663ab6
WYG
750
751 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
752 kfree(buf);
753 return ret;
754}
755
e7392364 756static ssize_t
1722f8e1
SG
757il_dbgfs_interrupt_write(struct file *file, const char __user *user_buf,
758 size_t count, loff_t *ppos)
be663ab6 759{
46bc8d4b 760 struct il_priv *il = file->private_data;
be663ab6
WYG
761 char buf[8];
762 int buf_size;
763 u32 reset_flag;
764
765 memset(buf, 0, sizeof(buf));
e7392364 766 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
767 if (copy_from_user(buf, user_buf, buf_size))
768 return -EFAULT;
769 if (sscanf(buf, "%x", &reset_flag) != 1)
770 return -EFAULT;
771 if (reset_flag == 0)
46bc8d4b 772 il_clear_isr_stats(il);
be663ab6
WYG
773
774 return count;
775}
776
777static ssize_t
1722f8e1
SG
778il_dbgfs_qos_read(struct file *file, char __user *user_buf, size_t count,
779 loff_t *ppos)
be663ab6 780{
46bc8d4b 781 struct il_priv *il = file->private_data;
be663ab6 782 int pos = 0, i;
7c2cde2e 783 char buf[256];
be663ab6
WYG
784 const size_t bufsz = sizeof(buf);
785
17d6e557 786 for (i = 0; i < AC_NUM; i++) {
e7392364
SG
787 pos +=
788 scnprintf(buf + pos, bufsz - pos,
789 "\tcw_min\tcw_max\taifsn\ttxop\n");
790 pos +=
791 scnprintf(buf + pos, bufsz - pos,
792 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
8d44f2bd
SG
793 il->qos_data.def_qos_parm.ac[i].cw_min,
794 il->qos_data.def_qos_parm.ac[i].cw_max,
795 il->qos_data.def_qos_parm.ac[i].aifsn,
796 il->qos_data.def_qos_parm.ac[i].edca_txop);
be663ab6 797 }
17d6e557 798
be663ab6
WYG
799 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
800}
801
e7392364 802static ssize_t
1722f8e1
SG
803il_dbgfs_disable_ht40_write(struct file *file, const char __user *user_buf,
804 size_t count, loff_t *ppos)
be663ab6 805{
46bc8d4b 806 struct il_priv *il = file->private_data;
be663ab6
WYG
807 char buf[8];
808 int buf_size;
809 int ht40;
810
811 memset(buf, 0, sizeof(buf));
e7392364 812 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
813 if (copy_from_user(buf, user_buf, buf_size))
814 return -EFAULT;
815 if (sscanf(buf, "%d", &ht40) != 1)
816 return -EFAULT;
46bc8d4b
SG
817 if (!il_is_any_associated(il))
818 il->disable_ht40 = ht40 ? true : false;
be663ab6 819 else {
9406f797 820 IL_ERR("Sta associated with AP - "
e7392364 821 "Change to 40MHz channel support is not allowed\n");
be663ab6
WYG
822 return -EINVAL;
823 }
824
825 return count;
826}
827
e7392364 828static ssize_t
1722f8e1
SG
829il_dbgfs_disable_ht40_read(struct file *file, char __user *user_buf,
830 size_t count, loff_t *ppos)
be663ab6 831{
46bc8d4b 832 struct il_priv *il = file->private_data;
be663ab6
WYG
833 char buf[100];
834 int pos = 0;
835 const size_t bufsz = sizeof(buf);
836
e7392364
SG
837 pos +=
838 scnprintf(buf + pos, bufsz - pos, "11n 40MHz Mode: %s\n",
839 il->disable_ht40 ? "Disabled" : "Enabled");
be663ab6
WYG
840 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
841}
842
843DEBUGFS_READ_WRITE_FILE_OPS(sram);
be663ab6
WYG
844DEBUGFS_READ_FILE_OPS(nvm);
845DEBUGFS_READ_FILE_OPS(stations);
846DEBUGFS_READ_FILE_OPS(channels);
847DEBUGFS_READ_FILE_OPS(status);
848DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
849DEBUGFS_READ_FILE_OPS(qos);
850DEBUGFS_READ_WRITE_FILE_OPS(disable_ht40);
851
e7392364 852static ssize_t
1722f8e1
SG
853il_dbgfs_tx_queue_read(struct file *file, char __user *user_buf, size_t count,
854 loff_t *ppos)
e7392364 855{
be663ab6 856
46bc8d4b 857 struct il_priv *il = file->private_data;
e2ebc833
SG
858 struct il_tx_queue *txq;
859 struct il_queue *q;
be663ab6
WYG
860 char *buf;
861 int pos = 0;
862 int cnt;
863 int ret;
e7392364 864 const size_t bufsz =
89ef1ed2 865 sizeof(char) * 64 * il->cfg->num_of_queues;
be663ab6 866
46bc8d4b 867 if (!il->txq) {
9406f797 868 IL_ERR("txq not ready\n");
be663ab6
WYG
869 return -EAGAIN;
870 }
871 buf = kzalloc(bufsz, GFP_KERNEL);
872 if (!buf)
873 return -ENOMEM;
874
46bc8d4b
SG
875 for (cnt = 0; cnt < il->hw_params.max_txq_num; cnt++) {
876 txq = &il->txq[cnt];
be663ab6 877 q = &txq->q;
e7392364
SG
878 pos +=
879 scnprintf(buf + pos, bufsz - pos,
880 "hwq %.2d: read=%u write=%u stop=%d"
881 " swq_id=%#.2x (ac %d/hwq %d)\n", cnt,
1722f8e1
SG
882 q->read_ptr, q->write_ptr,
883 !!test_bit(cnt, il->queue_stopped),
e7392364
SG
884 txq->swq_id, txq->swq_id & 3,
885 (txq->swq_id >> 2) & 0x1f);
be663ab6
WYG
886 if (cnt >= 4)
887 continue;
888 /* for the ACs, display the stop count too */
e7392364
SG
889 pos +=
890 scnprintf(buf + pos, bufsz - pos,
891 " stop-count: %d\n",
892 atomic_read(&il->queue_stop_count[cnt]));
be663ab6
WYG
893 }
894 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
895 kfree(buf);
896 return ret;
897}
898
e7392364 899static ssize_t
1722f8e1
SG
900il_dbgfs_rx_queue_read(struct file *file, char __user *user_buf, size_t count,
901 loff_t *ppos)
e7392364 902{
be663ab6 903
46bc8d4b
SG
904 struct il_priv *il = file->private_data;
905 struct il_rx_queue *rxq = &il->rxq;
be663ab6
WYG
906 char buf[256];
907 int pos = 0;
908 const size_t bufsz = sizeof(buf);
909
e7392364
SG
910 pos += scnprintf(buf + pos, bufsz - pos, "read: %u\n", rxq->read);
911 pos += scnprintf(buf + pos, bufsz - pos, "write: %u\n", rxq->write);
912 pos +=
913 scnprintf(buf + pos, bufsz - pos, "free_count: %u\n",
914 rxq->free_count);
be663ab6 915 if (rxq->rb_stts) {
e7392364
SG
916 pos +=
917 scnprintf(buf + pos, bufsz - pos, "closed_rb_num: %u\n",
918 le16_to_cpu(rxq->rb_stts->
919 closed_rb_num) & 0x0FFF);
be663ab6 920 } else {
e7392364
SG
921 pos +=
922 scnprintf(buf + pos, bufsz - pos,
923 "closed_rb_num: Not Allocated\n");
be663ab6
WYG
924 }
925 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
926}
927
e7392364 928static ssize_t
1722f8e1
SG
929il_dbgfs_ucode_rx_stats_read(struct file *file, char __user *user_buf,
930 size_t count, loff_t *ppos)
be663ab6 931{
46bc8d4b 932 struct il_priv *il = file->private_data;
93b7654e
SG
933
934 return il->debugfs_ops->rx_stats_read(file, user_buf, count, ppos);
be663ab6
WYG
935}
936
e7392364 937static ssize_t
1722f8e1
SG
938il_dbgfs_ucode_tx_stats_read(struct file *file, char __user *user_buf,
939 size_t count, loff_t *ppos)
be663ab6 940{
46bc8d4b 941 struct il_priv *il = file->private_data;
93b7654e
SG
942
943 return il->debugfs_ops->tx_stats_read(file, user_buf, count, ppos);
be663ab6
WYG
944}
945
e7392364 946static ssize_t
1722f8e1
SG
947il_dbgfs_ucode_general_stats_read(struct file *file, char __user *user_buf,
948 size_t count, loff_t *ppos)
be663ab6 949{
46bc8d4b 950 struct il_priv *il = file->private_data;
93b7654e
SG
951
952 return il->debugfs_ops->general_stats_read(file, user_buf, count, ppos);
be663ab6
WYG
953}
954
e7392364 955static ssize_t
1722f8e1
SG
956il_dbgfs_sensitivity_read(struct file *file, char __user *user_buf,
957 size_t count, loff_t *ppos)
e7392364 958{
be663ab6 959
46bc8d4b 960 struct il_priv *il = file->private_data;
be663ab6
WYG
961 int pos = 0;
962 int cnt = 0;
963 char *buf;
e2ebc833 964 int bufsz = sizeof(struct il_sensitivity_data) * 4 + 100;
be663ab6 965 ssize_t ret;
e2ebc833 966 struct il_sensitivity_data *data;
be663ab6 967
46bc8d4b 968 data = &il->sensitivity_data;
be663ab6
WYG
969 buf = kzalloc(bufsz, GFP_KERNEL);
970 if (!buf) {
9406f797 971 IL_ERR("Can not allocate Buffer\n");
be663ab6
WYG
972 return -ENOMEM;
973 }
974
e7392364
SG
975 pos +=
976 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm:\t\t\t %u\n",
977 data->auto_corr_ofdm);
978 pos +=
979 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc:\t\t %u\n",
980 data->auto_corr_ofdm_mrc);
981 pos +=
982 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_x1:\t\t %u\n",
983 data->auto_corr_ofdm_x1);
984 pos +=
985 scnprintf(buf + pos, bufsz - pos, "auto_corr_ofdm_mrc_x1:\t\t %u\n",
986 data->auto_corr_ofdm_mrc_x1);
987 pos +=
988 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck:\t\t\t %u\n",
989 data->auto_corr_cck);
990 pos +=
991 scnprintf(buf + pos, bufsz - pos, "auto_corr_cck_mrc:\t\t %u\n",
992 data->auto_corr_cck_mrc);
993 pos +=
994 scnprintf(buf + pos, bufsz - pos,
995 "last_bad_plcp_cnt_ofdm:\t\t %u\n",
996 data->last_bad_plcp_cnt_ofdm);
997 pos +=
998 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_ofdm:\t\t %u\n",
999 data->last_fa_cnt_ofdm);
1000 pos +=
1001 scnprintf(buf + pos, bufsz - pos, "last_bad_plcp_cnt_cck:\t\t %u\n",
1002 data->last_bad_plcp_cnt_cck);
1003 pos +=
1004 scnprintf(buf + pos, bufsz - pos, "last_fa_cnt_cck:\t\t %u\n",
1005 data->last_fa_cnt_cck);
1006 pos +=
1007 scnprintf(buf + pos, bufsz - pos, "nrg_curr_state:\t\t\t %u\n",
1008 data->nrg_curr_state);
1009 pos +=
1010 scnprintf(buf + pos, bufsz - pos, "nrg_prev_state:\t\t\t %u\n",
1011 data->nrg_prev_state);
be663ab6
WYG
1012 pos += scnprintf(buf + pos, bufsz - pos, "nrg_value:\t\t\t");
1013 for (cnt = 0; cnt < 10; cnt++) {
e7392364
SG
1014 pos +=
1015 scnprintf(buf + pos, bufsz - pos, " %u",
1016 data->nrg_value[cnt]);
be663ab6
WYG
1017 }
1018 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1019 pos += scnprintf(buf + pos, bufsz - pos, "nrg_silence_rssi:\t\t");
1020 for (cnt = 0; cnt < NRG_NUM_PREV_STAT_L; cnt++) {
e7392364
SG
1021 pos +=
1022 scnprintf(buf + pos, bufsz - pos, " %u",
1023 data->nrg_silence_rssi[cnt]);
be663ab6
WYG
1024 }
1025 pos += scnprintf(buf + pos, bufsz - pos, "\n");
e7392364
SG
1026 pos +=
1027 scnprintf(buf + pos, bufsz - pos, "nrg_silence_ref:\t\t %u\n",
1028 data->nrg_silence_ref);
1029 pos +=
1030 scnprintf(buf + pos, bufsz - pos, "nrg_energy_idx:\t\t\t %u\n",
1031 data->nrg_energy_idx);
1032 pos +=
1033 scnprintf(buf + pos, bufsz - pos, "nrg_silence_idx:\t\t %u\n",
1034 data->nrg_silence_idx);
1035 pos +=
1036 scnprintf(buf + pos, bufsz - pos, "nrg_th_cck:\t\t\t %u\n",
1037 data->nrg_th_cck);
1038 pos +=
1039 scnprintf(buf + pos, bufsz - pos,
1040 "nrg_auto_corr_silence_diff:\t %u\n",
1041 data->nrg_auto_corr_silence_diff);
1042 pos +=
1043 scnprintf(buf + pos, bufsz - pos, "num_in_cck_no_fa:\t\t %u\n",
1044 data->num_in_cck_no_fa);
1045 pos +=
1046 scnprintf(buf + pos, bufsz - pos, "nrg_th_ofdm:\t\t\t %u\n",
1047 data->nrg_th_ofdm);
be663ab6
WYG
1048
1049 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1050 kfree(buf);
1051 return ret;
1052}
1053
e7392364 1054static ssize_t
1722f8e1
SG
1055il_dbgfs_chain_noise_read(struct file *file, char __user *user_buf,
1056 size_t count, loff_t *ppos)
e7392364 1057{
be663ab6 1058
46bc8d4b 1059 struct il_priv *il = file->private_data;
be663ab6
WYG
1060 int pos = 0;
1061 int cnt = 0;
1062 char *buf;
e2ebc833 1063 int bufsz = sizeof(struct il_chain_noise_data) * 4 + 100;
be663ab6 1064 ssize_t ret;
e2ebc833 1065 struct il_chain_noise_data *data;
be663ab6 1066
46bc8d4b 1067 data = &il->chain_noise_data;
be663ab6
WYG
1068 buf = kzalloc(bufsz, GFP_KERNEL);
1069 if (!buf) {
9406f797 1070 IL_ERR("Can not allocate Buffer\n");
be663ab6
WYG
1071 return -ENOMEM;
1072 }
1073
e7392364
SG
1074 pos +=
1075 scnprintf(buf + pos, bufsz - pos, "active_chains:\t\t\t %u\n",
1076 data->active_chains);
1077 pos +=
1078 scnprintf(buf + pos, bufsz - pos, "chain_noise_a:\t\t\t %u\n",
1079 data->chain_noise_a);
1080 pos +=
1081 scnprintf(buf + pos, bufsz - pos, "chain_noise_b:\t\t\t %u\n",
1082 data->chain_noise_b);
1083 pos +=
1084 scnprintf(buf + pos, bufsz - pos, "chain_noise_c:\t\t\t %u\n",
1085 data->chain_noise_c);
1086 pos +=
1087 scnprintf(buf + pos, bufsz - pos, "chain_signal_a:\t\t\t %u\n",
1088 data->chain_signal_a);
1089 pos +=
1090 scnprintf(buf + pos, bufsz - pos, "chain_signal_b:\t\t\t %u\n",
1091 data->chain_signal_b);
1092 pos +=
1093 scnprintf(buf + pos, bufsz - pos, "chain_signal_c:\t\t\t %u\n",
1094 data->chain_signal_c);
1095 pos +=
1096 scnprintf(buf + pos, bufsz - pos, "beacon_count:\t\t\t %u\n",
1097 data->beacon_count);
be663ab6
WYG
1098
1099 pos += scnprintf(buf + pos, bufsz - pos, "disconn_array:\t\t\t");
1100 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
e7392364
SG
1101 pos +=
1102 scnprintf(buf + pos, bufsz - pos, " %u",
1103 data->disconn_array[cnt]);
be663ab6
WYG
1104 }
1105 pos += scnprintf(buf + pos, bufsz - pos, "\n");
1106 pos += scnprintf(buf + pos, bufsz - pos, "delta_gain_code:\t\t");
1107 for (cnt = 0; cnt < NUM_RX_CHAINS; cnt++) {
e7392364
SG
1108 pos +=
1109 scnprintf(buf + pos, bufsz - pos, " %u",
1110 data->delta_gain_code[cnt]);
be663ab6
WYG
1111 }
1112 pos += scnprintf(buf + pos, bufsz - pos, "\n");
e7392364
SG
1113 pos +=
1114 scnprintf(buf + pos, bufsz - pos, "radio_write:\t\t\t %u\n",
1115 data->radio_write);
1116 pos +=
1117 scnprintf(buf + pos, bufsz - pos, "state:\t\t\t\t %u\n",
1118 data->state);
be663ab6
WYG
1119
1120 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1121 kfree(buf);
1122 return ret;
1123}
1124
e7392364 1125static ssize_t
1722f8e1
SG
1126il_dbgfs_power_save_status_read(struct file *file, char __user *user_buf,
1127 size_t count, loff_t *ppos)
be663ab6 1128{
46bc8d4b 1129 struct il_priv *il = file->private_data;
be663ab6
WYG
1130 char buf[60];
1131 int pos = 0;
1132 const size_t bufsz = sizeof(buf);
1133 u32 pwrsave_status;
1134
e7392364
SG
1135 pwrsave_status =
1136 _il_rd(il, CSR_GP_CNTRL) & CSR_GP_REG_POWER_SAVE_STATUS_MSK;
be663ab6
WYG
1137
1138 pos += scnprintf(buf + pos, bufsz - pos, "Power Save Status: ");
e7392364
SG
1139 pos +=
1140 scnprintf(buf + pos, bufsz - pos, "%s\n",
1722f8e1
SG
1141 (pwrsave_status == CSR_GP_REG_NO_POWER_SAVE) ? "none" :
1142 (pwrsave_status == CSR_GP_REG_MAC_POWER_SAVE) ? "MAC" :
1143 (pwrsave_status == CSR_GP_REG_PHY_POWER_SAVE) ? "PHY" :
1144 "error");
be663ab6
WYG
1145
1146 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1147}
1148
e7392364
SG
1149static ssize_t
1150il_dbgfs_clear_ucode_stats_write(struct file *file,
1722f8e1
SG
1151 const char __user *user_buf, size_t count,
1152 loff_t *ppos)
be663ab6 1153{
46bc8d4b 1154 struct il_priv *il = file->private_data;
be663ab6
WYG
1155 char buf[8];
1156 int buf_size;
1157 int clear;
1158
1159 memset(buf, 0, sizeof(buf));
e7392364 1160 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
1161 if (copy_from_user(buf, user_buf, buf_size))
1162 return -EFAULT;
1163 if (sscanf(buf, "%d", &clear) != 1)
1164 return -EFAULT;
1165
ebf0d90d 1166 /* make request to uCode to retrieve stats information */
46bc8d4b 1167 mutex_lock(&il->mutex);
ebf0d90d 1168 il_send_stats_request(il, CMD_SYNC, true);
46bc8d4b 1169 mutex_unlock(&il->mutex);
be663ab6
WYG
1170
1171 return count;
1172}
1173
e7392364 1174static ssize_t
1722f8e1
SG
1175il_dbgfs_rxon_flags_read(struct file *file, char __user *user_buf,
1176 size_t count, loff_t *ppos)
e7392364 1177{
be663ab6 1178
46bc8d4b 1179 struct il_priv *il = file->private_data;
be663ab6
WYG
1180 int len = 0;
1181 char buf[20];
1182
c8b03958 1183 len = sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.flags));
be663ab6
WYG
1184 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1185}
1186
e7392364 1187static ssize_t
1722f8e1
SG
1188il_dbgfs_rxon_filter_flags_read(struct file *file, char __user *user_buf,
1189 size_t count, loff_t *ppos)
e7392364 1190{
be663ab6 1191
46bc8d4b 1192 struct il_priv *il = file->private_data;
be663ab6
WYG
1193 int len = 0;
1194 char buf[20];
1195
e7392364 1196 len =
c8b03958 1197 sprintf(buf, "0x%04X\n", le32_to_cpu(il->active.filter_flags));
be663ab6
WYG
1198 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1199}
1200
e7392364 1201static ssize_t
1722f8e1
SG
1202il_dbgfs_fh_reg_read(struct file *file, char __user *user_buf, size_t count,
1203 loff_t *ppos)
be663ab6 1204{
46bc8d4b 1205 struct il_priv *il = file->private_data;
be663ab6
WYG
1206 char *buf;
1207 int pos = 0;
1208 ssize_t ret = -EFAULT;
1209
1600b875
SG
1210 if (il->ops->dump_fh) {
1211 ret = pos = il->ops->dump_fh(il, &buf, true);
be663ab6 1212 if (buf) {
e7392364
SG
1213 ret =
1214 simple_read_from_buffer(user_buf, count, ppos, buf,
1215 pos);
be663ab6
WYG
1216 kfree(buf);
1217 }
1218 }
1219
1220 return ret;
1221}
1222
e7392364 1223static ssize_t
1722f8e1
SG
1224il_dbgfs_missed_beacon_read(struct file *file, char __user *user_buf,
1225 size_t count, loff_t *ppos)
e7392364 1226{
be663ab6 1227
46bc8d4b 1228 struct il_priv *il = file->private_data;
be663ab6
WYG
1229 int pos = 0;
1230 char buf[12];
1231 const size_t bufsz = sizeof(buf);
1232
e7392364
SG
1233 pos +=
1234 scnprintf(buf + pos, bufsz - pos, "%d\n",
1235 il->missed_beacon_threshold);
be663ab6
WYG
1236
1237 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1238}
1239
e7392364 1240static ssize_t
1722f8e1
SG
1241il_dbgfs_missed_beacon_write(struct file *file, const char __user *user_buf,
1242 size_t count, loff_t *ppos)
be663ab6 1243{
46bc8d4b 1244 struct il_priv *il = file->private_data;
be663ab6
WYG
1245 char buf[8];
1246 int buf_size;
1247 int missed;
1248
1249 memset(buf, 0, sizeof(buf));
e7392364 1250 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
1251 if (copy_from_user(buf, user_buf, buf_size))
1252 return -EFAULT;
1253 if (sscanf(buf, "%d", &missed) != 1)
1254 return -EINVAL;
1255
e2ebc833
SG
1256 if (missed < IL_MISSED_BEACON_THRESHOLD_MIN ||
1257 missed > IL_MISSED_BEACON_THRESHOLD_MAX)
e7392364 1258 il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
be663ab6 1259 else
46bc8d4b 1260 il->missed_beacon_threshold = missed;
be663ab6
WYG
1261
1262 return count;
1263}
1264
e7392364 1265static ssize_t
1722f8e1
SG
1266il_dbgfs_force_reset_read(struct file *file, char __user *user_buf,
1267 size_t count, loff_t *ppos)
e7392364 1268{
be663ab6 1269
46bc8d4b 1270 struct il_priv *il = file->private_data;
dd6d2a8a 1271 int pos = 0;
be663ab6
WYG
1272 char buf[300];
1273 const size_t bufsz = sizeof(buf);
e2ebc833 1274 struct il_force_reset *force_reset;
be663ab6 1275
46bc8d4b 1276 force_reset = &il->force_reset;
dd6d2a8a 1277
e7392364
SG
1278 pos +=
1279 scnprintf(buf + pos, bufsz - pos, "\tnumber of reset request: %d\n",
1280 force_reset->reset_request_count);
1281 pos +=
1282 scnprintf(buf + pos, bufsz - pos,
1283 "\tnumber of reset request success: %d\n",
1284 force_reset->reset_success_count);
1285 pos +=
1286 scnprintf(buf + pos, bufsz - pos,
1287 "\tnumber of reset request reject: %d\n",
1288 force_reset->reset_reject_count);
1289 pos +=
1290 scnprintf(buf + pos, bufsz - pos, "\treset duration: %lu\n",
1291 force_reset->reset_duration);
dd6d2a8a 1292
be663ab6
WYG
1293 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
1294}
1295
e7392364 1296static ssize_t
1722f8e1
SG
1297il_dbgfs_force_reset_write(struct file *file, const char __user *user_buf,
1298 size_t count, loff_t *ppos)
e7392364 1299{
be663ab6 1300
dd6d2a8a 1301 int ret;
46bc8d4b 1302 struct il_priv *il = file->private_data;
be663ab6 1303
46bc8d4b 1304 ret = il_force_reset(il, true);
dd6d2a8a 1305
be663ab6
WYG
1306 return ret ? ret : count;
1307}
1308
e7392364 1309static ssize_t
1722f8e1
SG
1310il_dbgfs_wd_timeout_write(struct file *file, const char __user *user_buf,
1311 size_t count, loff_t *ppos)
e7392364 1312{
be663ab6 1313
46bc8d4b 1314 struct il_priv *il = file->private_data;
be663ab6
WYG
1315 char buf[8];
1316 int buf_size;
1317 int timeout;
1318
1319 memset(buf, 0, sizeof(buf));
e7392364 1320 buf_size = min(count, sizeof(buf) - 1);
be663ab6
WYG
1321 if (copy_from_user(buf, user_buf, buf_size))
1322 return -EFAULT;
1323 if (sscanf(buf, "%d", &timeout) != 1)
1324 return -EINVAL;
e2ebc833
SG
1325 if (timeout < 0 || timeout > IL_MAX_WD_TIMEOUT)
1326 timeout = IL_DEF_WD_TIMEOUT;
be663ab6 1327
89ef1ed2 1328 il->cfg->wd_timeout = timeout;
46bc8d4b 1329 il_setup_watchdog(il);
be663ab6
WYG
1330 return count;
1331}
1332
ebf0d90d
SG
1333DEBUGFS_READ_FILE_OPS(rx_stats);
1334DEBUGFS_READ_FILE_OPS(tx_stats);
be663ab6
WYG
1335DEBUGFS_READ_FILE_OPS(rx_queue);
1336DEBUGFS_READ_FILE_OPS(tx_queue);
1337DEBUGFS_READ_FILE_OPS(ucode_rx_stats);
1338DEBUGFS_READ_FILE_OPS(ucode_tx_stats);
1339DEBUGFS_READ_FILE_OPS(ucode_general_stats);
1340DEBUGFS_READ_FILE_OPS(sensitivity);
1341DEBUGFS_READ_FILE_OPS(chain_noise);
1342DEBUGFS_READ_FILE_OPS(power_save_status);
ebf0d90d
SG
1343DEBUGFS_WRITE_FILE_OPS(clear_ucode_stats);
1344DEBUGFS_WRITE_FILE_OPS(clear_traffic_stats);
be663ab6
WYG
1345DEBUGFS_READ_FILE_OPS(fh_reg);
1346DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
be663ab6
WYG
1347DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
1348DEBUGFS_READ_FILE_OPS(rxon_flags);
1349DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
1350DEBUGFS_WRITE_FILE_OPS(wd_timeout);
1351
1352/*
1353 * Create the debugfs files and directories
1354 *
1355 */
e7392364
SG
1356int
1357il_dbgfs_register(struct il_priv *il, const char *name)
be663ab6 1358{
46bc8d4b 1359 struct dentry *phyd = il->hw->wiphy->debugfsdir;
be663ab6
WYG
1360 struct dentry *dir_drv, *dir_data, *dir_rf, *dir_debug;
1361
1362 dir_drv = debugfs_create_dir(name, phyd);
1363 if (!dir_drv)
1364 return -ENOMEM;
1365
46bc8d4b 1366 il->debugfs_dir = dir_drv;
be663ab6
WYG
1367
1368 dir_data = debugfs_create_dir("data", dir_drv);
1369 if (!dir_data)
1370 goto err;
1371 dir_rf = debugfs_create_dir("rf", dir_drv);
1372 if (!dir_rf)
1373 goto err;
1374 dir_debug = debugfs_create_dir("debug", dir_drv);
1375 if (!dir_debug)
1376 goto err;
1377
1378 DEBUGFS_ADD_FILE(nvm, dir_data, S_IRUSR);
1379 DEBUGFS_ADD_FILE(sram, dir_data, S_IWUSR | S_IRUSR);
be663ab6
WYG
1380 DEBUGFS_ADD_FILE(stations, dir_data, S_IRUSR);
1381 DEBUGFS_ADD_FILE(channels, dir_data, S_IRUSR);
1382 DEBUGFS_ADD_FILE(status, dir_data, S_IRUSR);
1383 DEBUGFS_ADD_FILE(interrupt, dir_data, S_IWUSR | S_IRUSR);
1384 DEBUGFS_ADD_FILE(qos, dir_data, S_IRUSR);
1385 DEBUGFS_ADD_FILE(disable_ht40, dir_data, S_IWUSR | S_IRUSR);
ebf0d90d
SG
1386 DEBUGFS_ADD_FILE(rx_stats, dir_debug, S_IRUSR);
1387 DEBUGFS_ADD_FILE(tx_stats, dir_debug, S_IRUSR);
be663ab6
WYG
1388 DEBUGFS_ADD_FILE(rx_queue, dir_debug, S_IRUSR);
1389 DEBUGFS_ADD_FILE(tx_queue, dir_debug, S_IRUSR);
1390 DEBUGFS_ADD_FILE(power_save_status, dir_debug, S_IRUSR);
ebf0d90d
SG
1391 DEBUGFS_ADD_FILE(clear_ucode_stats, dir_debug, S_IWUSR);
1392 DEBUGFS_ADD_FILE(clear_traffic_stats, dir_debug, S_IWUSR);
be663ab6
WYG
1393 DEBUGFS_ADD_FILE(fh_reg, dir_debug, S_IRUSR);
1394 DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
be663ab6
WYG
1395 DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
1396 DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
1397 DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
1398 DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
1399
89ef1ed2 1400 if (il->cfg->sensitivity_calib_by_driver)
be663ab6 1401 DEBUGFS_ADD_FILE(sensitivity, dir_debug, S_IRUSR);
89ef1ed2 1402 if (il->cfg->chain_noise_calib_by_driver)
be663ab6 1403 DEBUGFS_ADD_FILE(chain_noise, dir_debug, S_IRUSR);
be663ab6
WYG
1404 DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
1405 DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
1406 DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
89ef1ed2 1407 if (il->cfg->sensitivity_calib_by_driver)
be663ab6 1408 DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
46bc8d4b 1409 &il->disable_sens_cal);
89ef1ed2 1410 if (il->cfg->chain_noise_calib_by_driver)
be663ab6 1411 DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
46bc8d4b 1412 &il->disable_chain_noise_cal);
e7392364 1413 DEBUGFS_ADD_BOOL(disable_tx_power, dir_rf, &il->disable_tx_power_cal);
be663ab6
WYG
1414 return 0;
1415
1416err:
9406f797 1417 IL_ERR("Can't create the debugfs directory\n");
46bc8d4b 1418 il_dbgfs_unregister(il);
be663ab6
WYG
1419 return -ENOMEM;
1420}
e2ebc833 1421EXPORT_SYMBOL(il_dbgfs_register);
be663ab6
WYG
1422
1423/**
1424 * Remove the debugfs files and directories
1425 *
1426 */
e7392364
SG
1427void
1428il_dbgfs_unregister(struct il_priv *il)
be663ab6 1429{
46bc8d4b 1430 if (!il->debugfs_dir)
be663ab6
WYG
1431 return;
1432
46bc8d4b
SG
1433 debugfs_remove_recursive(il->debugfs_dir);
1434 il->debugfs_dir = NULL;
be663ab6 1435}
e2ebc833 1436EXPORT_SYMBOL(il_dbgfs_unregister);
This page took 0.420532 seconds and 5 git commands to generate.