3 Broadcom BCM43xx wireless driver
5 debugfs driver debugging code
7 Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
29 #include <linux/debugfs.h>
30 #include <linux/slab.h>
31 #include <linux/netdevice.h>
32 #include <linux/pci.h>
36 #include "bcm43xx_main.h"
37 #include "bcm43xx_debugfs.h"
38 #include "bcm43xx_dma.h"
39 #include "bcm43xx_pio.h"
41 #define REALLY_BIG_BUFFER_SIZE (1024*256)
43 static struct bcm43xx_debugfs fs
;
44 static char really_big_buffer
[REALLY_BIG_BUFFER_SIZE
];
45 static DECLARE_MUTEX(big_buffer_sem
);
48 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
49 size_t count
, loff_t
*ppos
)
54 static int open_file_generic(struct inode
*inode
, struct file
*file
)
56 file
->private_data
= inode
->u
.generic_ip
;
60 #define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
62 static ssize_t
devinfo_read_file(struct file
*file
, char __user
*userbuf
,
63 size_t count
, loff_t
*ppos
)
65 const size_t len
= REALLY_BIG_BUFFER_SIZE
;
67 struct bcm43xx_private
*bcm
= file
->private_data
;
68 char *buf
= really_big_buffer
;
71 struct net_device
*net_dev
;
72 struct pci_dev
*pci_dev
;
77 down(&big_buffer_sem
);
79 spin_lock_irqsave(&bcm
->lock
, flags
);
80 if (!bcm
->initialized
) {
81 fappend("Board not initialized.\n");
84 net_dev
= bcm
->net_dev
;
85 pci_dev
= bcm
->pci_dev
;
87 /* This is where the information is written to the "devinfo" file */
88 fappend("*** %s devinfo ***\n", net_dev
->name
);
89 fappend("vendor: 0x%04x device: 0x%04x\n",
90 pci_dev
->vendor
, pci_dev
->device
);
91 fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
92 pci_dev
->subsystem_vendor
, pci_dev
->subsystem_device
);
93 fappend("IRQ: %d\n", bcm
->irq
);
94 fappend("mmio_addr: 0x%p mmio_len: %u\n", bcm
->mmio_addr
, bcm
->mmio_len
);
95 fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm
->chip_id
, bcm
->chip_rev
);
96 if ((bcm
->core_80211
[0].rev
>= 3) && (bcm43xx_read32(bcm
, 0x0158) & (1 << 16)))
97 fappend("Radio disabled by hardware!\n");
98 if ((bcm
->core_80211
[0].rev
< 3) && !(bcm43xx_read16(bcm
, 0x049A) & (1 << 4)))
99 fappend("Radio disabled by hardware!\n");
100 fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm
->board_vendor
,
103 fappend("\nCores:\n");
104 #define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
105 "rev: 0x%02x, index: 0x%02x\n", \
106 (info).flags & BCM43xx_COREFLAG_AVAILABLE \
107 ? "available" : "nonavailable", \
108 (info).flags & BCM43xx_COREFLAG_ENABLED \
109 ? "enabled" : "disabled", \
110 (info).id, (info).rev, (info).index)
111 fappend_core("CHIPCOMMON", bcm
->core_chipcommon
);
112 fappend_core("PCI", bcm
->core_pci
);
113 fappend_core("V90", bcm
->core_v90
);
114 fappend_core("PCMCIA", bcm
->core_pcmcia
);
115 fappend_core("ETHERNET", bcm
->core_ethernet
);
116 fappend_core("first 80211", bcm
->core_80211
[0]);
117 fappend_core("second 80211", bcm
->core_80211
[1]);
119 tmp16
= bcm43xx_read16(bcm
, BCM43xx_MMIO_GPIO_CONTROL
);
121 for (i
= 0; i
< BCM43xx_NR_LEDS
; i
++)
122 fappend("%d ", !!(tmp16
& (1 << i
)));
126 spin_unlock_irqrestore(&bcm
->lock
, flags
);
127 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
132 static ssize_t
drvinfo_read_file(struct file
*file
, char __user
*userbuf
,
133 size_t count
, loff_t
*ppos
)
135 const size_t len
= REALLY_BIG_BUFFER_SIZE
;
137 char *buf
= really_big_buffer
;
141 down(&big_buffer_sem
);
143 /* This is where the information is written to the "driver" file */
144 fappend(BCM43xx_DRIVER_NAME
"\n");
145 fappend("Compiled at: %s %s\n", __DATE__
, __TIME__
);
147 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
152 static ssize_t
spromdump_read_file(struct file
*file
, char __user
*userbuf
,
153 size_t count
, loff_t
*ppos
)
155 const size_t len
= REALLY_BIG_BUFFER_SIZE
;
157 struct bcm43xx_private
*bcm
= file
->private_data
;
158 char *buf
= really_big_buffer
;
163 down(&big_buffer_sem
);
164 spin_lock_irqsave(&bcm
->lock
, flags
);
165 if (!bcm
->initialized
) {
166 fappend("Board not initialized.\n");
170 /* This is where the information is written to the "sprom_dump" file */
171 fappend("boardflags: 0x%04x\n", bcm
->sprom
.boardflags
);
174 spin_unlock_irqrestore(&bcm
->lock
, flags
);
175 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
180 static ssize_t
tsf_read_file(struct file
*file
, char __user
*userbuf
,
181 size_t count
, loff_t
*ppos
)
183 const size_t len
= REALLY_BIG_BUFFER_SIZE
;
185 struct bcm43xx_private
*bcm
= file
->private_data
;
186 char *buf
= really_big_buffer
;
192 down(&big_buffer_sem
);
193 spin_lock_irqsave(&bcm
->lock
, flags
);
194 if (!bcm
->initialized
) {
195 fappend("Board not initialized.\n");
198 bcm43xx_tsf_read(bcm
, &tsf
);
199 fappend("0x%08x%08x\n",
200 (unsigned int)((tsf
& 0xFFFFFFFF00000000ULL
) >> 32),
201 (unsigned int)(tsf
& 0xFFFFFFFFULL
));
204 spin_unlock_irqrestore(&bcm
->lock
, flags
);
205 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
210 static ssize_t
tsf_write_file(struct file
*file
, const char __user
*user_buf
,
211 size_t count
, loff_t
*ppos
)
213 struct bcm43xx_private
*bcm
= file
->private_data
;
214 char *buf
= really_big_buffer
;
220 buf_size
= min(count
, sizeof (really_big_buffer
) - 1);
221 down(&big_buffer_sem
);
222 if (copy_from_user(buf
, user_buf
, buf_size
)) {
226 spin_lock_irqsave(&bcm
->lock
, flags
);
227 if (!bcm
->initialized
) {
228 printk(KERN_INFO PFX
"debugfs: Board not initialized.\n");
232 if (sscanf(buf
, "%lli", &tsf
) != 1) {
233 printk(KERN_INFO PFX
"debugfs: invalid values for \"tsf\"\n");
237 bcm43xx_tsf_write(bcm
, tsf
);
241 spin_unlock_irqrestore(&bcm
->lock
, flags
);
247 static ssize_t
txstat_read_file(struct file
*file
, char __user
*userbuf
,
248 size_t count
, loff_t
*ppos
)
250 const size_t len
= REALLY_BIG_BUFFER_SIZE
;
252 struct bcm43xx_private
*bcm
= file
->private_data
;
253 char *buf
= really_big_buffer
;
257 struct bcm43xx_dfsentry
*e
;
258 struct bcm43xx_xmitstatus
*status
;
261 down(&big_buffer_sem
);
262 spin_lock_irqsave(&bcm
->lock
, flags
);
264 fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
265 BCM43xx_NR_LOGGED_XMITSTATUS
);
267 if (e
->xmitstatus_printing
== 0) {
268 /* At the beginning, make a copy of all data to avoid
269 * concurrency, as this function is called multiple
270 * times for big logs. Without copying, the data might
271 * change between reads. This would result in total trash.
273 e
->xmitstatus_printing
= 1;
274 e
->saved_xmitstatus_ptr
= e
->xmitstatus_ptr
;
275 e
->saved_xmitstatus_cnt
= e
->xmitstatus_cnt
;
276 memcpy(e
->xmitstatus_print_buffer
, e
->xmitstatus_buffer
,
277 BCM43xx_NR_LOGGED_XMITSTATUS
* sizeof(*(e
->xmitstatus_buffer
)));
279 i
= e
->saved_xmitstatus_ptr
- 1;
281 i
= BCM43xx_NR_LOGGED_XMITSTATUS
- 1;
282 cnt
= e
->saved_xmitstatus_cnt
;
284 status
= e
->xmitstatus_print_buffer
+ i
;
285 fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
286 "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
288 status
->cookie
, status
->flags
,
289 status
->cnt1
, status
->cnt2
, status
->seq
,
295 i
= BCM43xx_NR_LOGGED_XMITSTATUS
- 1;
298 spin_unlock_irqrestore(&bcm
->lock
, flags
);
299 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
300 spin_lock_irqsave(&bcm
->lock
, flags
);
302 /* Done. Drop the copied data. */
303 e
->xmitstatus_printing
= 0;
305 spin_unlock_irqrestore(&bcm
->lock
, flags
);
313 static struct file_operations devinfo_fops
= {
314 .read
= devinfo_read_file
,
315 .write
= write_file_dummy
,
316 .open
= open_file_generic
,
319 static struct file_operations spromdump_fops
= {
320 .read
= spromdump_read_file
,
321 .write
= write_file_dummy
,
322 .open
= open_file_generic
,
325 static struct file_operations drvinfo_fops
= {
326 .read
= drvinfo_read_file
,
327 .write
= write_file_dummy
,
328 .open
= open_file_generic
,
331 static struct file_operations tsf_fops
= {
332 .read
= tsf_read_file
,
333 .write
= tsf_write_file
,
334 .open
= open_file_generic
,
337 static struct file_operations txstat_fops
= {
338 .read
= txstat_read_file
,
339 .write
= write_file_dummy
,
340 .open
= open_file_generic
,
344 void bcm43xx_debugfs_add_device(struct bcm43xx_private
*bcm
)
346 struct bcm43xx_dfsentry
*e
;
347 char devdir
[IFNAMSIZ
];
350 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
352 printk(KERN_ERR PFX
"out of memory\n");
356 e
->xmitstatus_buffer
= kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
357 * sizeof(*(e
->xmitstatus_buffer
)),
359 if (!e
->xmitstatus_buffer
) {
360 printk(KERN_ERR PFX
"out of memory\n");
364 e
->xmitstatus_print_buffer
= kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
365 * sizeof(*(e
->xmitstatus_buffer
)),
367 if (!e
->xmitstatus_print_buffer
) {
368 printk(KERN_ERR PFX
"out of memory\n");
376 strncpy(devdir
, bcm
->net_dev
->name
, ARRAY_SIZE(devdir
));
377 e
->subdir
= debugfs_create_dir(devdir
, fs
.root
);
378 e
->dentry_devinfo
= debugfs_create_file("devinfo", 0444, e
->subdir
,
380 if (!e
->dentry_devinfo
)
381 printk(KERN_ERR PFX
"debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir
);
382 e
->dentry_spromdump
= debugfs_create_file("sprom_dump", 0444, e
->subdir
,
383 bcm
, &spromdump_fops
);
384 if (!e
->dentry_spromdump
)
385 printk(KERN_ERR PFX
"debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir
);
386 e
->dentry_tsf
= debugfs_create_file("tsf", 0666, e
->subdir
,
389 printk(KERN_ERR PFX
"debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir
);
390 e
->dentry_txstat
= debugfs_create_file("tx_status", 0444, e
->subdir
,
392 if (!e
->dentry_txstat
)
393 printk(KERN_ERR PFX
"debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir
);
396 void bcm43xx_debugfs_remove_device(struct bcm43xx_private
*bcm
)
398 struct bcm43xx_dfsentry
*e
;
405 debugfs_remove(e
->dentry_spromdump
);
406 debugfs_remove(e
->dentry_devinfo
);
407 debugfs_remove(e
->dentry_tsf
);
408 debugfs_remove(e
->dentry_txstat
);
409 debugfs_remove(e
->subdir
);
410 kfree(e
->xmitstatus_buffer
);
411 kfree(e
->xmitstatus_print_buffer
);
415 void bcm43xx_debugfs_log_txstat(struct bcm43xx_private
*bcm
,
416 struct bcm43xx_xmitstatus
*status
)
418 struct bcm43xx_dfsentry
*e
;
419 struct bcm43xx_xmitstatus
*savedstatus
;
421 /* This is protected by bcm->lock */
424 savedstatus
= e
->xmitstatus_buffer
+ e
->xmitstatus_ptr
;
425 memcpy(savedstatus
, status
, sizeof(*status
));
427 if (e
->xmitstatus_ptr
>= BCM43xx_NR_LOGGED_XMITSTATUS
)
428 e
->xmitstatus_ptr
= 0;
429 if (e
->xmitstatus_cnt
< BCM43xx_NR_LOGGED_XMITSTATUS
)
433 void bcm43xx_debugfs_init(void)
435 memset(&fs
, 0, sizeof(fs
));
436 fs
.root
= debugfs_create_dir(DRV_NAME
, NULL
);
438 printk(KERN_ERR PFX
"debugfs: creating \"" DRV_NAME
"\" subdir failed!\n");
439 fs
.dentry_driverinfo
= debugfs_create_file("driver", 0444, fs
.root
, NULL
, &drvinfo_fops
);
440 if (!fs
.dentry_driverinfo
)
441 printk(KERN_ERR PFX
"debugfs: creating \"" DRV_NAME
"/driver\" failed!\n");
444 void bcm43xx_debugfs_exit(void)
446 debugfs_remove(fs
.dentry_driverinfo
);
447 debugfs_remove(fs
.root
);
450 void bcm43xx_printk_dump(const char *data
,
452 const char *description
)
457 printk(KERN_INFO PFX
"Data dump (%s, %u bytes):",
459 for (i
= 0; i
< size
; i
++) {
462 printk("\n" KERN_INFO PFX
"0x%08x: 0x%02x, ", i
, c
& 0xff);
464 printk("0x%02x, ", c
& 0xff);
469 void bcm43xx_printk_bitdump(const unsigned char *data
,
470 size_t bytes
, int msb_to_lsb
,
471 const char *description
)
475 const unsigned char *d
;
477 printk(KERN_INFO PFX
"*** Bitdump (%s, %u bytes, %s) ***",
478 description
, bytes
, msb_to_lsb
? "MSB to LSB" : "LSB to MSB");
479 for (i
= 0; i
< bytes
; i
++) {
482 printk("\n" KERN_INFO PFX
"0x%08x: ", i
);
484 for (j
= 7; j
>= 0; j
--) {
491 for (j
= 0; j
< 8; j
++) {
503 /* vim: set ts=8 sw=8 sts=8: */