blob: b42165c402889f13272ba87e961b4c5bccb70dc0 [file] [log] [blame]
Zhu Yibb9f8692009-05-21 21:20:45 +08001/*
2 * Intel Wireless Multicomm 3200 WiFi driver
3 *
4 * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
5 * Samuel Ortiz <samuel.ortiz@intel.com>
6 * Zhu Yi <yi.zhu@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/bitops.h>
26#include <linux/debugfs.h>
27
28#include "iwm.h"
29#include "bus.h"
30#include "rx.h"
31#include "debug.h"
32
33static struct {
34 u8 id;
35 char *name;
36} iwm_debug_module[__IWM_DM_NR] = {
37 {IWM_DM_BOOT, "boot"},
38 {IWM_DM_FW, "fw"},
39 {IWM_DM_SDIO, "sdio"},
40 {IWM_DM_NTF, "ntf"},
41 {IWM_DM_RX, "rx"},
42 {IWM_DM_TX, "tx"},
43 {IWM_DM_MLME, "mlme"},
44 {IWM_DM_CMD, "cmd"},
45 {IWM_DM_WEXT, "wext"},
46};
47
48#define add_dbg_module(dbg, name, id, initlevel) \
49do { \
Zhu Yibb9f8692009-05-21 21:20:45 +080050 dbg.dbg_module[id] = (initlevel); \
John W. Linville1f55c122010-05-03 14:46:05 -040051 dbg.dbg_module_dentries[id] = \
52 debugfs_create_x8(name, 0600, \
53 dbg.dbgdir, \
54 &(dbg.dbg_module[id])); \
Zhu Yibb9f8692009-05-21 21:20:45 +080055} while (0)
56
57static int iwm_debugfs_u32_read(void *data, u64 *val)
58{
59 struct iwm_priv *iwm = data;
60
61 *val = iwm->dbg.dbg_level;
62 return 0;
63}
64
65static int iwm_debugfs_dbg_level_write(void *data, u64 val)
66{
67 struct iwm_priv *iwm = data;
68 int i;
69
70 iwm->dbg.dbg_level = val;
71
72 for (i = 0; i < __IWM_DM_NR; i++)
73 iwm->dbg.dbg_module[i] = val;
74
75 return 0;
76}
77DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_level,
78 iwm_debugfs_u32_read, iwm_debugfs_dbg_level_write,
79 "%llu\n");
80
81static int iwm_debugfs_dbg_modules_write(void *data, u64 val)
82{
83 struct iwm_priv *iwm = data;
84 int i, bit;
85
86 iwm->dbg.dbg_modules = val;
87
88 for (i = 0; i < __IWM_DM_NR; i++)
89 iwm->dbg.dbg_module[i] = 0;
90
91 for_each_bit(bit, &iwm->dbg.dbg_modules, __IWM_DM_NR)
92 iwm->dbg.dbg_module[bit] = iwm->dbg.dbg_level;
93
94 return 0;
95}
96DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules,
97 iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write,
98 "%llu\n");
99
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200100static int iwm_generic_open(struct inode *inode, struct file *filp)
Zhu Yibb9f8692009-05-21 21:20:45 +0800101{
102 filp->private_data = inode->i_private;
103 return 0;
104}
105
106
107static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer,
108 size_t count, loff_t *ppos)
109{
110 struct iwm_priv *iwm = filp->private_data;
111 char *buf;
112 int i, buf_len = 4096;
113 size_t len = 0;
114 ssize_t ret;
115
116 if (*ppos != 0)
117 return 0;
118 if (count < sizeof(buf))
119 return -ENOSPC;
120
121 buf = kzalloc(buf_len, GFP_KERNEL);
122 if (!buf)
123 return -ENOMEM;
124
125 for (i = 0; i < IWM_TX_QUEUES; i++) {
126 struct iwm_tx_queue *txq = &iwm->txq[i];
127 struct sk_buff *skb;
128 int j;
129 unsigned long flags;
130
131 spin_lock_irqsave(&txq->queue.lock, flags);
132
133 skb = (struct sk_buff *)&txq->queue;
134
135 len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i);
136 len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n",
137 __netif_subqueue_stopped(iwm_to_ndev(iwm),
138 txq->id));
139 len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n",
140 txq->concat_count);
141 len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n",
142 skb_queue_len(&txq->queue));
143 for (j = 0; j < skb_queue_len(&txq->queue); j++) {
144 struct iwm_tx_info *tx_info;
145
146 skb = skb->next;
147 tx_info = skb_to_tx_info(skb);
148
149 len += snprintf(buf + len, buf_len - len,
150 "\tSKB #%d\n", j);
151 len += snprintf(buf + len, buf_len - len,
152 "\t\tsta: %d\n", tx_info->sta);
153 len += snprintf(buf + len, buf_len - len,
154 "\t\tcolor: %d\n", tx_info->color);
155 len += snprintf(buf + len, buf_len - len,
156 "\t\ttid: %d\n", tx_info->tid);
157 }
158
159 spin_unlock_irqrestore(&txq->queue.lock, flags);
Samuel Ortizb136b3a2009-11-24 11:33:32 +0800160
161 spin_lock_irqsave(&txq->stopped_queue.lock, flags);
162
163 len += snprintf(buf + len, buf_len - len,
164 "\tStopped Queue len: %d\n",
165 skb_queue_len(&txq->stopped_queue));
166 for (j = 0; j < skb_queue_len(&txq->stopped_queue); j++) {
167 struct iwm_tx_info *tx_info;
168
169 skb = skb->next;
170 tx_info = skb_to_tx_info(skb);
171
172 len += snprintf(buf + len, buf_len - len,
173 "\tSKB #%d\n", j);
174 len += snprintf(buf + len, buf_len - len,
175 "\t\tsta: %d\n", tx_info->sta);
176 len += snprintf(buf + len, buf_len - len,
177 "\t\tcolor: %d\n", tx_info->color);
178 len += snprintf(buf + len, buf_len - len,
179 "\t\ttid: %d\n", tx_info->tid);
180 }
181
182 spin_unlock_irqrestore(&txq->stopped_queue.lock, flags);
Zhu Yibb9f8692009-05-21 21:20:45 +0800183 }
184
185 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
186 kfree(buf);
187
188 return ret;
189}
190
191static ssize_t iwm_debugfs_tx_credit_read(struct file *filp,
192 char __user *buffer,
193 size_t count, loff_t *ppos)
194{
195 struct iwm_priv *iwm = filp->private_data;
196 struct iwm_tx_credit *credit = &iwm->tx_credit;
197 char *buf;
198 int i, buf_len = 4096;
199 size_t len = 0;
200 ssize_t ret;
201
202 if (*ppos != 0)
203 return 0;
204 if (count < sizeof(buf))
205 return -ENOSPC;
206
207 buf = kzalloc(buf_len, GFP_KERNEL);
208 if (!buf)
209 return -ENOMEM;
210
211 len += snprintf(buf + len, buf_len - len,
212 "NR pools: %d\n", credit->pool_nr);
213 len += snprintf(buf + len, buf_len - len,
214 "pools map: 0x%lx\n", credit->full_pools_map);
215
216 len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n");
217 for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) {
218 len += snprintf(buf + len, buf_len - len,
219 "pools entry #%d\n", i);
220 len += snprintf(buf + len, buf_len - len,
221 "\tid: %d\n",
222 credit->pools[i].id);
223 len += snprintf(buf + len, buf_len - len,
224 "\tsid: %d\n",
225 credit->pools[i].sid);
226 len += snprintf(buf + len, buf_len - len,
227 "\tmin_pages: %d\n",
228 credit->pools[i].min_pages);
229 len += snprintf(buf + len, buf_len - len,
230 "\tmax_pages: %d\n",
231 credit->pools[i].max_pages);
232 len += snprintf(buf + len, buf_len - len,
233 "\talloc_pages: %d\n",
234 credit->pools[i].alloc_pages);
235 len += snprintf(buf + len, buf_len - len,
236 "\tfreed_pages: %d\n",
237 credit->pools[i].total_freed_pages);
238 }
239
240 len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n");
241 for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) {
242 len += snprintf(buf + len, buf_len - len,
243 "spools entry #%d\n", i);
244 len += snprintf(buf + len, buf_len - len,
245 "\tid: %d\n",
246 credit->spools[i].id);
247 len += snprintf(buf + len, buf_len - len,
248 "\tmax_pages: %d\n",
249 credit->spools[i].max_pages);
250 len += snprintf(buf + len, buf_len - len,
251 "\talloc_pages: %d\n",
252 credit->spools[i].alloc_pages);
253
254 }
255
256 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
257 kfree(buf);
258
259 return ret;
260}
261
262static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp,
263 char __user *buffer,
264 size_t count, loff_t *ppos)
265{
266 struct iwm_priv *iwm = filp->private_data;
Zhu Yi04d1c222010-02-25 14:15:26 +0800267 struct iwm_rx_ticket_node *ticket;
Zhu Yibb9f8692009-05-21 21:20:45 +0800268 char *buf;
269 int buf_len = 4096, i;
270 size_t len = 0;
271 ssize_t ret;
272
273 if (*ppos != 0)
274 return 0;
275 if (count < sizeof(buf))
276 return -ENOSPC;
277
278 buf = kzalloc(buf_len, GFP_KERNEL);
279 if (!buf)
280 return -ENOMEM;
281
Zhu Yic03c6ae2010-02-25 14:15:28 +0800282 spin_lock(&iwm->ticket_lock);
Zhu Yi04d1c222010-02-25 14:15:26 +0800283 list_for_each_entry(ticket, &iwm->rx_tickets, node) {
Zhu Yibb9f8692009-05-21 21:20:45 +0800284 len += snprintf(buf + len, buf_len - len, "Ticket #%d\n",
285 ticket->ticket->id);
286 len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n",
287 ticket->ticket->action);
288 len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n",
289 ticket->ticket->flags);
290 }
Zhu Yic03c6ae2010-02-25 14:15:28 +0800291 spin_unlock(&iwm->ticket_lock);
Zhu Yibb9f8692009-05-21 21:20:45 +0800292
293 for (i = 0; i < IWM_RX_ID_HASH; i++) {
Zhu Yi04d1c222010-02-25 14:15:26 +0800294 struct iwm_rx_packet *packet;
Zhu Yibb9f8692009-05-21 21:20:45 +0800295 struct list_head *pkt_list = &iwm->rx_packets[i];
Zhu Yi04d1c222010-02-25 14:15:26 +0800296
Zhu Yibb9f8692009-05-21 21:20:45 +0800297 if (!list_empty(pkt_list)) {
298 len += snprintf(buf + len, buf_len - len,
299 "Packet hash #%d\n", i);
Zhu Yic03c6ae2010-02-25 14:15:28 +0800300 spin_lock(&iwm->packet_lock[i]);
Zhu Yi04d1c222010-02-25 14:15:26 +0800301 list_for_each_entry(packet, pkt_list, node) {
Zhu Yibb9f8692009-05-21 21:20:45 +0800302 len += snprintf(buf + len, buf_len - len,
303 "\tPacket id: %d\n",
304 packet->id);
305 len += snprintf(buf + len, buf_len - len,
306 "\tPacket length: %lu\n",
307 packet->pkt_size);
308 }
Zhu Yic03c6ae2010-02-25 14:15:28 +0800309 spin_unlock(&iwm->packet_lock[i]);
Zhu Yibb9f8692009-05-21 21:20:45 +0800310 }
311 }
312
313 ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
314 kfree(buf);
315
316 return ret;
317}
318
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200319static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
320 char __user *buffer,
321 size_t count, loff_t *ppos)
322{
323
324 struct iwm_priv *iwm = filp->private_data;
325 char buf[512];
326 int buf_len = 512;
327 size_t len = 0;
328
329 if (*ppos != 0)
330 return 0;
331 if (count < sizeof(buf))
332 return -ENOSPC;
333
334 if (!iwm->last_fw_err)
335 return -ENOMEM;
336
337 if (iwm->last_fw_err->line_num == 0)
338 goto out;
339
340 len += snprintf(buf + len, buf_len - len, "%cMAC FW ERROR:\n",
341 (le32_to_cpu(iwm->last_fw_err->category) == UMAC_SYS_ERR_CAT_LMAC)
342 ? 'L' : 'U');
343 len += snprintf(buf + len, buf_len - len,
344 "\tCategory: %d\n",
345 le32_to_cpu(iwm->last_fw_err->category));
346
347 len += snprintf(buf + len, buf_len - len,
348 "\tStatus: 0x%x\n",
349 le32_to_cpu(iwm->last_fw_err->status));
350
351 len += snprintf(buf + len, buf_len - len,
352 "\tPC: 0x%x\n",
353 le32_to_cpu(iwm->last_fw_err->pc));
354
355 len += snprintf(buf + len, buf_len - len,
356 "\tblink1: %d\n",
357 le32_to_cpu(iwm->last_fw_err->blink1));
358
359 len += snprintf(buf + len, buf_len - len,
360 "\tblink2: %d\n",
361 le32_to_cpu(iwm->last_fw_err->blink2));
362
363 len += snprintf(buf + len, buf_len - len,
364 "\tilink1: %d\n",
365 le32_to_cpu(iwm->last_fw_err->ilink1));
366
367 len += snprintf(buf + len, buf_len - len,
368 "\tilink2: %d\n",
369 le32_to_cpu(iwm->last_fw_err->ilink2));
370
371 len += snprintf(buf + len, buf_len - len,
372 "\tData1: 0x%x\n",
373 le32_to_cpu(iwm->last_fw_err->data1));
374
375 len += snprintf(buf + len, buf_len - len,
376 "\tData2: 0x%x\n",
377 le32_to_cpu(iwm->last_fw_err->data2));
378
379 len += snprintf(buf + len, buf_len - len,
380 "\tLine number: %d\n",
381 le32_to_cpu(iwm->last_fw_err->line_num));
382
383 len += snprintf(buf + len, buf_len - len,
384 "\tUMAC status: 0x%x\n",
385 le32_to_cpu(iwm->last_fw_err->umac_status));
386
387 len += snprintf(buf + len, buf_len - len,
388 "\tLMAC status: 0x%x\n",
389 le32_to_cpu(iwm->last_fw_err->lmac_status));
390
391 len += snprintf(buf + len, buf_len - len,
392 "\tSDIO status: 0x%x\n",
393 le32_to_cpu(iwm->last_fw_err->sdio_status));
394
395out:
396
397 return simple_read_from_buffer(buffer, len, ppos, buf, buf_len);
398}
Zhu Yibb9f8692009-05-21 21:20:45 +0800399
400static const struct file_operations iwm_debugfs_txq_fops = {
401 .owner = THIS_MODULE,
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200402 .open = iwm_generic_open,
Zhu Yibb9f8692009-05-21 21:20:45 +0800403 .read = iwm_debugfs_txq_read,
404};
405
406static const struct file_operations iwm_debugfs_tx_credit_fops = {
407 .owner = THIS_MODULE,
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200408 .open = iwm_generic_open,
Zhu Yibb9f8692009-05-21 21:20:45 +0800409 .read = iwm_debugfs_tx_credit_read,
410};
411
412static const struct file_operations iwm_debugfs_rx_ticket_fops = {
413 .owner = THIS_MODULE,
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200414 .open = iwm_generic_open,
Zhu Yibb9f8692009-05-21 21:20:45 +0800415 .read = iwm_debugfs_rx_ticket_read,
416};
417
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200418static const struct file_operations iwm_debugfs_fw_err_fops = {
419 .owner = THIS_MODULE,
420 .open = iwm_generic_open,
421 .read = iwm_debugfs_fw_err_read,
422};
423
John W. Linville1f55c122010-05-03 14:46:05 -0400424void iwm_debugfs_init(struct iwm_priv *iwm)
Zhu Yibb9f8692009-05-21 21:20:45 +0800425{
John W. Linville1f55c122010-05-03 14:46:05 -0400426 int i;
Zhu Yibb9f8692009-05-21 21:20:45 +0800427
428 iwm->dbg.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
John W. Linville1f55c122010-05-03 14:46:05 -0400429 iwm->dbg.devdir = debugfs_create_dir(wiphy_name(iwm_to_wiphy(iwm)),
430 iwm->dbg.rootdir);
Zhu Yibb9f8692009-05-21 21:20:45 +0800431 iwm->dbg.dbgdir = debugfs_create_dir("debug", iwm->dbg.devdir);
Zhu Yibb9f8692009-05-21 21:20:45 +0800432 iwm->dbg.rxdir = debugfs_create_dir("rx", iwm->dbg.devdir);
Zhu Yibb9f8692009-05-21 21:20:45 +0800433 iwm->dbg.txdir = debugfs_create_dir("tx", iwm->dbg.devdir);
Zhu Yibb9f8692009-05-21 21:20:45 +0800434 iwm->dbg.busdir = debugfs_create_dir("bus", iwm->dbg.devdir);
John W. Linville1f55c122010-05-03 14:46:05 -0400435 if (iwm->bus_ops->debugfs_init)
436 iwm->bus_ops->debugfs_init(iwm, iwm->dbg.busdir);
Zhu Yibb9f8692009-05-21 21:20:45 +0800437
Zhu Yibb9f8692009-05-21 21:20:45 +0800438 iwm->dbg.dbg_level = IWM_DL_NONE;
439 iwm->dbg.dbg_level_dentry =
440 debugfs_create_file("level", 0200, iwm->dbg.dbgdir, iwm,
441 &fops_iwm_dbg_level);
Zhu Yibb9f8692009-05-21 21:20:45 +0800442
443 iwm->dbg.dbg_modules = IWM_DM_DEFAULT;
444 iwm->dbg.dbg_modules_dentry =
445 debugfs_create_file("modules", 0200, iwm->dbg.dbgdir, iwm,
446 &fops_iwm_dbg_modules);
Zhu Yibb9f8692009-05-21 21:20:45 +0800447
448 for (i = 0; i < __IWM_DM_NR; i++)
449 add_dbg_module(iwm->dbg, iwm_debug_module[i].name,
450 iwm_debug_module[i].id, IWM_DL_DEFAULT);
451
452 iwm->dbg.txq_dentry = debugfs_create_file("queues", 0200,
453 iwm->dbg.txdir, iwm,
454 &iwm_debugfs_txq_fops);
Zhu Yibb9f8692009-05-21 21:20:45 +0800455 iwm->dbg.tx_credit_dentry = debugfs_create_file("credits", 0200,
456 iwm->dbg.txdir, iwm,
457 &iwm_debugfs_tx_credit_fops);
Zhu Yibb9f8692009-05-21 21:20:45 +0800458 iwm->dbg.rx_ticket_dentry = debugfs_create_file("tickets", 0200,
459 iwm->dbg.rxdir, iwm,
460 &iwm_debugfs_rx_ticket_fops);
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200461 iwm->dbg.fw_err_dentry = debugfs_create_file("last_fw_err", 0200,
462 iwm->dbg.dbgdir, iwm,
463 &iwm_debugfs_fw_err_fops);
Zhu Yibb9f8692009-05-21 21:20:45 +0800464}
465
466void iwm_debugfs_exit(struct iwm_priv *iwm)
467{
468 int i;
469
470 for (i = 0; i < __IWM_DM_NR; i++)
471 debugfs_remove(iwm->dbg.dbg_module_dentries[i]);
472
473 debugfs_remove(iwm->dbg.dbg_modules_dentry);
474 debugfs_remove(iwm->dbg.dbg_level_dentry);
475 debugfs_remove(iwm->dbg.txq_dentry);
476 debugfs_remove(iwm->dbg.tx_credit_dentry);
477 debugfs_remove(iwm->dbg.rx_ticket_dentry);
Samuel Ortiz04e715c2009-09-01 15:14:06 +0200478 debugfs_remove(iwm->dbg.fw_err_dentry);
Zhu Yibb9f8692009-05-21 21:20:45 +0800479 if (iwm->bus_ops->debugfs_exit)
480 iwm->bus_ops->debugfs_exit(iwm);
481
482 debugfs_remove(iwm->dbg.busdir);
483 debugfs_remove(iwm->dbg.dbgdir);
484 debugfs_remove(iwm->dbg.txdir);
485 debugfs_remove(iwm->dbg.rxdir);
486 debugfs_remove(iwm->dbg.devdir);
487 debugfs_remove(iwm->dbg.rootdir);
488}