Commit | Line | Data |
---|---|---|
bb9f8692 ZY |
1 | /* |
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 | ||
5a0e3ad6 | 24 | #include <linux/slab.h> |
bb9f8692 ZY |
25 | #include <linux/kernel.h> |
26 | #include <linux/bitops.h> | |
27 | #include <linux/debugfs.h> | |
ee40fa06 | 28 | #include <linux/export.h> |
bb9f8692 ZY |
29 | |
30 | #include "iwm.h" | |
31 | #include "bus.h" | |
32 | #include "rx.h" | |
33 | #include "debug.h" | |
34 | ||
35 | static struct { | |
36 | u8 id; | |
37 | char *name; | |
38 | } iwm_debug_module[__IWM_DM_NR] = { | |
39 | {IWM_DM_BOOT, "boot"}, | |
40 | {IWM_DM_FW, "fw"}, | |
41 | {IWM_DM_SDIO, "sdio"}, | |
42 | {IWM_DM_NTF, "ntf"}, | |
43 | {IWM_DM_RX, "rx"}, | |
44 | {IWM_DM_TX, "tx"}, | |
45 | {IWM_DM_MLME, "mlme"}, | |
46 | {IWM_DM_CMD, "cmd"}, | |
47 | {IWM_DM_WEXT, "wext"}, | |
48 | }; | |
49 | ||
50 | #define add_dbg_module(dbg, name, id, initlevel) \ | |
51 | do { \ | |
bb9f8692 | 52 | dbg.dbg_module[id] = (initlevel); \ |
1f55c12c JL |
53 | dbg.dbg_module_dentries[id] = \ |
54 | debugfs_create_x8(name, 0600, \ | |
55 | dbg.dbgdir, \ | |
56 | &(dbg.dbg_module[id])); \ | |
bb9f8692 ZY |
57 | } while (0) |
58 | ||
59 | static int iwm_debugfs_u32_read(void *data, u64 *val) | |
60 | { | |
61 | struct iwm_priv *iwm = data; | |
62 | ||
63 | *val = iwm->dbg.dbg_level; | |
64 | return 0; | |
65 | } | |
66 | ||
67 | static int iwm_debugfs_dbg_level_write(void *data, u64 val) | |
68 | { | |
69 | struct iwm_priv *iwm = data; | |
70 | int i; | |
71 | ||
72 | iwm->dbg.dbg_level = val; | |
73 | ||
74 | for (i = 0; i < __IWM_DM_NR; i++) | |
75 | iwm->dbg.dbg_module[i] = val; | |
76 | ||
77 | return 0; | |
78 | } | |
79 | DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_level, | |
80 | iwm_debugfs_u32_read, iwm_debugfs_dbg_level_write, | |
81 | "%llu\n"); | |
82 | ||
83 | static int iwm_debugfs_dbg_modules_write(void *data, u64 val) | |
84 | { | |
85 | struct iwm_priv *iwm = data; | |
86 | int i, bit; | |
87 | ||
88 | iwm->dbg.dbg_modules = val; | |
89 | ||
90 | for (i = 0; i < __IWM_DM_NR; i++) | |
91 | iwm->dbg.dbg_module[i] = 0; | |
92 | ||
984b3f57 | 93 | for_each_set_bit(bit, &iwm->dbg.dbg_modules, __IWM_DM_NR) |
bb9f8692 ZY |
94 | iwm->dbg.dbg_module[bit] = iwm->dbg.dbg_level; |
95 | ||
96 | return 0; | |
97 | } | |
98 | DEFINE_SIMPLE_ATTRIBUTE(fops_iwm_dbg_modules, | |
99 | iwm_debugfs_u32_read, iwm_debugfs_dbg_modules_write, | |
100 | "%llu\n"); | |
101 | ||
bb9f8692 ZY |
102 | |
103 | static ssize_t iwm_debugfs_txq_read(struct file *filp, char __user *buffer, | |
104 | size_t count, loff_t *ppos) | |
105 | { | |
106 | struct iwm_priv *iwm = filp->private_data; | |
107 | char *buf; | |
108 | int i, buf_len = 4096; | |
109 | size_t len = 0; | |
110 | ssize_t ret; | |
111 | ||
112 | if (*ppos != 0) | |
113 | return 0; | |
114 | if (count < sizeof(buf)) | |
115 | return -ENOSPC; | |
116 | ||
117 | buf = kzalloc(buf_len, GFP_KERNEL); | |
118 | if (!buf) | |
119 | return -ENOMEM; | |
120 | ||
121 | for (i = 0; i < IWM_TX_QUEUES; i++) { | |
122 | struct iwm_tx_queue *txq = &iwm->txq[i]; | |
123 | struct sk_buff *skb; | |
124 | int j; | |
125 | unsigned long flags; | |
126 | ||
127 | spin_lock_irqsave(&txq->queue.lock, flags); | |
128 | ||
129 | skb = (struct sk_buff *)&txq->queue; | |
130 | ||
131 | len += snprintf(buf + len, buf_len - len, "TXQ #%d\n", i); | |
132 | len += snprintf(buf + len, buf_len - len, "\tStopped: %d\n", | |
133 | __netif_subqueue_stopped(iwm_to_ndev(iwm), | |
134 | txq->id)); | |
135 | len += snprintf(buf + len, buf_len - len, "\tConcat count:%d\n", | |
136 | txq->concat_count); | |
137 | len += snprintf(buf + len, buf_len - len, "\tQueue len: %d\n", | |
138 | skb_queue_len(&txq->queue)); | |
139 | for (j = 0; j < skb_queue_len(&txq->queue); j++) { | |
140 | struct iwm_tx_info *tx_info; | |
141 | ||
142 | skb = skb->next; | |
143 | tx_info = skb_to_tx_info(skb); | |
144 | ||
145 | len += snprintf(buf + len, buf_len - len, | |
146 | "\tSKB #%d\n", j); | |
147 | len += snprintf(buf + len, buf_len - len, | |
148 | "\t\tsta: %d\n", tx_info->sta); | |
149 | len += snprintf(buf + len, buf_len - len, | |
150 | "\t\tcolor: %d\n", tx_info->color); | |
151 | len += snprintf(buf + len, buf_len - len, | |
152 | "\t\ttid: %d\n", tx_info->tid); | |
153 | } | |
154 | ||
155 | spin_unlock_irqrestore(&txq->queue.lock, flags); | |
b136b3a2 SO |
156 | |
157 | spin_lock_irqsave(&txq->stopped_queue.lock, flags); | |
158 | ||
159 | len += snprintf(buf + len, buf_len - len, | |
160 | "\tStopped Queue len: %d\n", | |
161 | skb_queue_len(&txq->stopped_queue)); | |
162 | for (j = 0; j < skb_queue_len(&txq->stopped_queue); j++) { | |
163 | struct iwm_tx_info *tx_info; | |
164 | ||
165 | skb = skb->next; | |
166 | tx_info = skb_to_tx_info(skb); | |
167 | ||
168 | len += snprintf(buf + len, buf_len - len, | |
169 | "\tSKB #%d\n", j); | |
170 | len += snprintf(buf + len, buf_len - len, | |
171 | "\t\tsta: %d\n", tx_info->sta); | |
172 | len += snprintf(buf + len, buf_len - len, | |
173 | "\t\tcolor: %d\n", tx_info->color); | |
174 | len += snprintf(buf + len, buf_len - len, | |
175 | "\t\ttid: %d\n", tx_info->tid); | |
176 | } | |
177 | ||
178 | spin_unlock_irqrestore(&txq->stopped_queue.lock, flags); | |
bb9f8692 ZY |
179 | } |
180 | ||
181 | ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len); | |
182 | kfree(buf); | |
183 | ||
184 | return ret; | |
185 | } | |
186 | ||
187 | static ssize_t iwm_debugfs_tx_credit_read(struct file *filp, | |
188 | char __user *buffer, | |
189 | size_t count, loff_t *ppos) | |
190 | { | |
191 | struct iwm_priv *iwm = filp->private_data; | |
192 | struct iwm_tx_credit *credit = &iwm->tx_credit; | |
193 | char *buf; | |
194 | int i, buf_len = 4096; | |
195 | size_t len = 0; | |
196 | ssize_t ret; | |
197 | ||
198 | if (*ppos != 0) | |
199 | return 0; | |
200 | if (count < sizeof(buf)) | |
201 | return -ENOSPC; | |
202 | ||
203 | buf = kzalloc(buf_len, GFP_KERNEL); | |
204 | if (!buf) | |
205 | return -ENOMEM; | |
206 | ||
207 | len += snprintf(buf + len, buf_len - len, | |
208 | "NR pools: %d\n", credit->pool_nr); | |
209 | len += snprintf(buf + len, buf_len - len, | |
210 | "pools map: 0x%lx\n", credit->full_pools_map); | |
211 | ||
212 | len += snprintf(buf + len, buf_len - len, "\n### POOLS ###\n"); | |
213 | for (i = 0; i < IWM_MACS_OUT_GROUPS; i++) { | |
214 | len += snprintf(buf + len, buf_len - len, | |
215 | "pools entry #%d\n", i); | |
216 | len += snprintf(buf + len, buf_len - len, | |
217 | "\tid: %d\n", | |
218 | credit->pools[i].id); | |
219 | len += snprintf(buf + len, buf_len - len, | |
220 | "\tsid: %d\n", | |
221 | credit->pools[i].sid); | |
222 | len += snprintf(buf + len, buf_len - len, | |
223 | "\tmin_pages: %d\n", | |
224 | credit->pools[i].min_pages); | |
225 | len += snprintf(buf + len, buf_len - len, | |
226 | "\tmax_pages: %d\n", | |
227 | credit->pools[i].max_pages); | |
228 | len += snprintf(buf + len, buf_len - len, | |
229 | "\talloc_pages: %d\n", | |
230 | credit->pools[i].alloc_pages); | |
231 | len += snprintf(buf + len, buf_len - len, | |
232 | "\tfreed_pages: %d\n", | |
233 | credit->pools[i].total_freed_pages); | |
234 | } | |
235 | ||
236 | len += snprintf(buf + len, buf_len - len, "\n### SPOOLS ###\n"); | |
237 | for (i = 0; i < IWM_MACS_OUT_SGROUPS; i++) { | |
238 | len += snprintf(buf + len, buf_len - len, | |
239 | "spools entry #%d\n", i); | |
240 | len += snprintf(buf + len, buf_len - len, | |
241 | "\tid: %d\n", | |
242 | credit->spools[i].id); | |
243 | len += snprintf(buf + len, buf_len - len, | |
244 | "\tmax_pages: %d\n", | |
245 | credit->spools[i].max_pages); | |
246 | len += snprintf(buf + len, buf_len - len, | |
247 | "\talloc_pages: %d\n", | |
248 | credit->spools[i].alloc_pages); | |
249 | ||
250 | } | |
251 | ||
252 | ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len); | |
253 | kfree(buf); | |
254 | ||
255 | return ret; | |
256 | } | |
257 | ||
258 | static ssize_t iwm_debugfs_rx_ticket_read(struct file *filp, | |
259 | char __user *buffer, | |
260 | size_t count, loff_t *ppos) | |
261 | { | |
262 | struct iwm_priv *iwm = filp->private_data; | |
04d1c227 | 263 | struct iwm_rx_ticket_node *ticket; |
bb9f8692 ZY |
264 | char *buf; |
265 | int buf_len = 4096, i; | |
266 | size_t len = 0; | |
267 | ssize_t ret; | |
268 | ||
269 | if (*ppos != 0) | |
270 | return 0; | |
271 | if (count < sizeof(buf)) | |
272 | return -ENOSPC; | |
273 | ||
274 | buf = kzalloc(buf_len, GFP_KERNEL); | |
275 | if (!buf) | |
276 | return -ENOMEM; | |
277 | ||
c03c6aef | 278 | spin_lock(&iwm->ticket_lock); |
04d1c227 | 279 | list_for_each_entry(ticket, &iwm->rx_tickets, node) { |
bb9f8692 ZY |
280 | len += snprintf(buf + len, buf_len - len, "Ticket #%d\n", |
281 | ticket->ticket->id); | |
282 | len += snprintf(buf + len, buf_len - len, "\taction: 0x%x\n", | |
283 | ticket->ticket->action); | |
284 | len += snprintf(buf + len, buf_len - len, "\tflags: 0x%x\n", | |
285 | ticket->ticket->flags); | |
286 | } | |
c03c6aef | 287 | spin_unlock(&iwm->ticket_lock); |
bb9f8692 ZY |
288 | |
289 | for (i = 0; i < IWM_RX_ID_HASH; i++) { | |
04d1c227 | 290 | struct iwm_rx_packet *packet; |
bb9f8692 | 291 | struct list_head *pkt_list = &iwm->rx_packets[i]; |
04d1c227 | 292 | |
bb9f8692 ZY |
293 | if (!list_empty(pkt_list)) { |
294 | len += snprintf(buf + len, buf_len - len, | |
295 | "Packet hash #%d\n", i); | |
c03c6aef | 296 | spin_lock(&iwm->packet_lock[i]); |
04d1c227 | 297 | list_for_each_entry(packet, pkt_list, node) { |
bb9f8692 ZY |
298 | len += snprintf(buf + len, buf_len - len, |
299 | "\tPacket id: %d\n", | |
300 | packet->id); | |
301 | len += snprintf(buf + len, buf_len - len, | |
302 | "\tPacket length: %lu\n", | |
303 | packet->pkt_size); | |
304 | } | |
c03c6aef | 305 | spin_unlock(&iwm->packet_lock[i]); |
bb9f8692 ZY |
306 | } |
307 | } | |
308 | ||
309 | ret = simple_read_from_buffer(buffer, len, ppos, buf, buf_len); | |
310 | kfree(buf); | |
311 | ||
312 | return ret; | |
313 | } | |
314 | ||
04e715cd SO |
315 | static ssize_t iwm_debugfs_fw_err_read(struct file *filp, |
316 | char __user *buffer, | |
317 | size_t count, loff_t *ppos) | |
318 | { | |
319 | ||
320 | struct iwm_priv *iwm = filp->private_data; | |
321 | char buf[512]; | |
322 | int buf_len = 512; | |
323 | size_t len = 0; | |
324 | ||
325 | if (*ppos != 0) | |
326 | return 0; | |
327 | if (count < sizeof(buf)) | |
328 | return -ENOSPC; | |
329 | ||
330 | if (!iwm->last_fw_err) | |
331 | return -ENOMEM; | |
332 | ||
333 | if (iwm->last_fw_err->line_num == 0) | |
334 | goto out; | |
335 | ||
336 | len += snprintf(buf + len, buf_len - len, "%cMAC FW ERROR:\n", | |
337 | (le32_to_cpu(iwm->last_fw_err->category) == UMAC_SYS_ERR_CAT_LMAC) | |
338 | ? 'L' : 'U'); | |
339 | len += snprintf(buf + len, buf_len - len, | |
340 | "\tCategory: %d\n", | |
341 | le32_to_cpu(iwm->last_fw_err->category)); | |
342 | ||
343 | len += snprintf(buf + len, buf_len - len, | |
344 | "\tStatus: 0x%x\n", | |
345 | le32_to_cpu(iwm->last_fw_err->status)); | |
346 | ||
347 | len += snprintf(buf + len, buf_len - len, | |
348 | "\tPC: 0x%x\n", | |
349 | le32_to_cpu(iwm->last_fw_err->pc)); | |
350 | ||
351 | len += snprintf(buf + len, buf_len - len, | |
352 | "\tblink1: %d\n", | |
353 | le32_to_cpu(iwm->last_fw_err->blink1)); | |
354 | ||
355 | len += snprintf(buf + len, buf_len - len, | |
356 | "\tblink2: %d\n", | |
357 | le32_to_cpu(iwm->last_fw_err->blink2)); | |
358 | ||
359 | len += snprintf(buf + len, buf_len - len, | |
360 | "\tilink1: %d\n", | |
361 | le32_to_cpu(iwm->last_fw_err->ilink1)); | |
362 | ||
363 | len += snprintf(buf + len, buf_len - len, | |
364 | "\tilink2: %d\n", | |
365 | le32_to_cpu(iwm->last_fw_err->ilink2)); | |
366 | ||
367 | len += snprintf(buf + len, buf_len - len, | |
368 | "\tData1: 0x%x\n", | |
369 | le32_to_cpu(iwm->last_fw_err->data1)); | |
370 | ||
371 | len += snprintf(buf + len, buf_len - len, | |
372 | "\tData2: 0x%x\n", | |
373 | le32_to_cpu(iwm->last_fw_err->data2)); | |
374 | ||
375 | len += snprintf(buf + len, buf_len - len, | |
376 | "\tLine number: %d\n", | |
377 | le32_to_cpu(iwm->last_fw_err->line_num)); | |
378 | ||
379 | len += snprintf(buf + len, buf_len - len, | |
380 | "\tUMAC status: 0x%x\n", | |
381 | le32_to_cpu(iwm->last_fw_err->umac_status)); | |
382 | ||
383 | len += snprintf(buf + len, buf_len - len, | |
384 | "\tLMAC status: 0x%x\n", | |
385 | le32_to_cpu(iwm->last_fw_err->lmac_status)); | |
386 | ||
387 | len += snprintf(buf + len, buf_len - len, | |
388 | "\tSDIO status: 0x%x\n", | |
389 | le32_to_cpu(iwm->last_fw_err->sdio_status)); | |
390 | ||
391 | out: | |
392 | ||
393 | return simple_read_from_buffer(buffer, len, ppos, buf, buf_len); | |
394 | } | |
bb9f8692 ZY |
395 | |
396 | static const struct file_operations iwm_debugfs_txq_fops = { | |
397 | .owner = THIS_MODULE, | |
234e3405 | 398 | .open = simple_open, |
bb9f8692 | 399 | .read = iwm_debugfs_txq_read, |
6038f373 | 400 | .llseek = default_llseek, |
bb9f8692 ZY |
401 | }; |
402 | ||
403 | static const struct file_operations iwm_debugfs_tx_credit_fops = { | |
404 | .owner = THIS_MODULE, | |
234e3405 | 405 | .open = simple_open, |
bb9f8692 | 406 | .read = iwm_debugfs_tx_credit_read, |
6038f373 | 407 | .llseek = default_llseek, |
bb9f8692 ZY |
408 | }; |
409 | ||
410 | static const struct file_operations iwm_debugfs_rx_ticket_fops = { | |
411 | .owner = THIS_MODULE, | |
234e3405 | 412 | .open = simple_open, |
bb9f8692 | 413 | .read = iwm_debugfs_rx_ticket_read, |
6038f373 | 414 | .llseek = default_llseek, |
bb9f8692 ZY |
415 | }; |
416 | ||
04e715cd SO |
417 | static const struct file_operations iwm_debugfs_fw_err_fops = { |
418 | .owner = THIS_MODULE, | |
234e3405 | 419 | .open = simple_open, |
04e715cd | 420 | .read = iwm_debugfs_fw_err_read, |
6038f373 | 421 | .llseek = default_llseek, |
04e715cd SO |
422 | }; |
423 | ||
1f55c12c | 424 | void iwm_debugfs_init(struct iwm_priv *iwm) |
bb9f8692 | 425 | { |
1f55c12c | 426 | int i; |
bb9f8692 ZY |
427 | |
428 | iwm->dbg.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL); | |
1f55c12c JL |
429 | iwm->dbg.devdir = debugfs_create_dir(wiphy_name(iwm_to_wiphy(iwm)), |
430 | iwm->dbg.rootdir); | |
bb9f8692 | 431 | iwm->dbg.dbgdir = debugfs_create_dir("debug", iwm->dbg.devdir); |
bb9f8692 | 432 | iwm->dbg.rxdir = debugfs_create_dir("rx", iwm->dbg.devdir); |
bb9f8692 | 433 | iwm->dbg.txdir = debugfs_create_dir("tx", iwm->dbg.devdir); |
bb9f8692 | 434 | iwm->dbg.busdir = debugfs_create_dir("bus", iwm->dbg.devdir); |
1f55c12c JL |
435 | if (iwm->bus_ops->debugfs_init) |
436 | iwm->bus_ops->debugfs_init(iwm, iwm->dbg.busdir); | |
bb9f8692 ZY |
437 | |
438 | 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); | |
bb9f8692 ZY |
442 | |
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); | |
bb9f8692 ZY |
447 | |
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); | |
bb9f8692 ZY |
455 | iwm->dbg.tx_credit_dentry = debugfs_create_file("credits", 0200, |
456 | iwm->dbg.txdir, iwm, | |
457 | &iwm_debugfs_tx_credit_fops); | |
bb9f8692 ZY |
458 | iwm->dbg.rx_ticket_dentry = debugfs_create_file("tickets", 0200, |
459 | iwm->dbg.rxdir, iwm, | |
460 | &iwm_debugfs_rx_ticket_fops); | |
04e715cd SO |
461 | iwm->dbg.fw_err_dentry = debugfs_create_file("last_fw_err", 0200, |
462 | iwm->dbg.dbgdir, iwm, | |
463 | &iwm_debugfs_fw_err_fops); | |
bb9f8692 ZY |
464 | } |
465 | ||
466 | void 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); | |
04e715cd | 478 | debugfs_remove(iwm->dbg.fw_err_dentry); |
bb9f8692 ZY |
479 | 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 | } |