3 Broadcom BCM43xx wireless driver
5 debugfs driver debugging code
7 Copyright (c) 2005 Michael Buesch <mb@bu3sch.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>
33 #include <linux/mutex.h>
36 #include "bcm43xx_main.h"
37 #include "bcm43xx_debugfs.h"
38 #include "bcm43xx_dma.h"
39 #include "bcm43xx_pio.h"
40 #include "bcm43xx_xmit.h"
42 #define REALLY_BIG_BUFFER_SIZE (1024*256)
44 static struct bcm43xx_debugfs fs
;
45 static char big_buffer
[1024*256];
46 static DEFINE_MUTEX(big_buffer_mutex
);
49 static ssize_t
write_file_dummy(struct file
*file
, const char __user
*buf
,
50 size_t count
, loff_t
*ppos
)
55 static int open_file_generic(struct inode
*inode
, struct file
*file
)
57 file
->private_data
= inode
->i_private
;
61 #define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
63 static ssize_t
drvinfo_read_file(struct file
*file
, char __user
*userbuf
,
64 size_t count
, loff_t
*ppos
)
66 const size_t len
= ARRAY_SIZE(big_buffer
);
67 char *buf
= big_buffer
;
71 mutex_lock(&big_buffer_mutex
);
72 /* This is where the information is written to the "driver" file */
73 fappend(KBUILD_MODNAME
" driver\n");
74 fappend("Compiled at: %s %s\n", __DATE__
, __TIME__
);
75 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
76 mutex_unlock(&big_buffer_mutex
);
81 static ssize_t
tsf_read_file(struct file
*file
, char __user
*userbuf
,
82 size_t count
, loff_t
*ppos
)
84 struct bcm43xx_wldev
*dev
= file
->private_data
;
85 const size_t len
= ARRAY_SIZE(big_buffer
);
86 char *buf
= big_buffer
;
92 mutex_lock(&big_buffer_mutex
);
93 mutex_lock(&dev
->wl
->mutex
);
94 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
95 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) {
96 fappend("Board not initialized.\n");
99 bcm43xx_tsf_read(dev
, &tsf
);
100 fappend("0x%08x%08x\n",
101 (unsigned int)((tsf
& 0xFFFFFFFF00000000ULL
) >> 32),
102 (unsigned int)(tsf
& 0xFFFFFFFFULL
));
105 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
106 mutex_unlock(&dev
->wl
->mutex
);
107 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
108 mutex_unlock(&big_buffer_mutex
);
113 static ssize_t
tsf_write_file(struct file
*file
, const char __user
*user_buf
,
114 size_t count
, loff_t
*ppos
)
116 struct bcm43xx_wldev
*dev
= file
->private_data
;
117 char *buf
= big_buffer
;
123 mutex_lock(&big_buffer_mutex
);
124 buf_size
= min(count
, ARRAY_SIZE(big_buffer
) - 1);
125 if (copy_from_user(buf
, user_buf
, buf_size
)) {
129 mutex_lock(&dev
->wl
->mutex
);
130 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
131 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) {
132 printk(KERN_INFO PFX
"debugfs: Board not initialized.\n");
136 if (sscanf(buf
, "%llu", (unsigned long long *)(&tsf
)) != 1) {
137 printk(KERN_INFO PFX
"debugfs: invalid values for \"tsf\"\n");
141 bcm43xx_tsf_write(dev
, tsf
);
146 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
147 mutex_unlock(&dev
->wl
->mutex
);
149 mutex_unlock(&big_buffer_mutex
);
154 static ssize_t
txstat_read_file(struct file
*file
, char __user
*userbuf
,
155 size_t count
, loff_t
*ppos
)
157 struct bcm43xx_wldev
*dev
= file
->private_data
;
158 struct bcm43xx_dfsentry
*e
= dev
->dfsentry
;
159 struct bcm43xx_txstatus_log
*log
= &e
->txstatlog
;
161 char *buf
= log
->printbuf
;
162 const size_t len
= ARRAY_SIZE(log
->printbuf
);
166 struct bcm43xx_txstatus
*stat
;
168 mutex_lock(&big_buffer_mutex
);
169 spin_lock_irqsave(&log
->lock
, flags
);
170 if (!log
->printing
) {
172 fappend("bcm43xx TX status reports:\n\n"
173 "index | cookie | seq | phy_stat | frame_count | "
174 "rts_count | supp_reason | pm_indicated | "
175 "intermediate | for_ampdu | acked\n"
180 if (i
== BCM43xx_NR_LOGGED_TXSTATUS
)
182 stat
= &(log
->log
[i
]);
185 "0x%04X | 0x%04X | 0x%02X | "
190 stat
->cookie
, stat
->seq
, stat
->phy_stat
,
191 stat
->frame_count
, stat
->rts_count
,
192 stat
->supp_reason
, stat
->pm_indicated
,
193 stat
->intermediate
, stat
->for_ampdu
,
201 log
->buf_avail
= pos
;
203 memcpy(big_buffer
, buf
,
204 min(log
->buf_avail
, ARRAY_SIZE(big_buffer
)));
205 spin_unlock_irqrestore(&log
->lock
, flags
);
207 res
= simple_read_from_buffer(userbuf
, count
, ppos
,
210 if (*ppos
== log
->buf_avail
) {
211 spin_lock_irqsave(&log
->lock
, flags
);
213 spin_unlock_irqrestore(&log
->lock
, flags
);
215 mutex_unlock(&big_buffer_mutex
);
220 static ssize_t
restart_write_file(struct file
*file
, const char __user
*user_buf
,
221 size_t count
, loff_t
*ppos
)
223 struct bcm43xx_wldev
*dev
= file
->private_data
;
224 char *buf
= big_buffer
;
229 mutex_lock(&big_buffer_mutex
);
230 buf_size
= min(count
, ARRAY_SIZE(big_buffer
) - 1);
231 if (copy_from_user(buf
, user_buf
, buf_size
)) {
235 mutex_lock(&dev
->wl
->mutex
);
236 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
237 if (bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) {
238 printk(KERN_INFO PFX
"debugfs: Board not initialized.\n");
242 if (count
> 0 && buf
[0] == '1') {
243 bcm43xx_controller_restart(dev
, "manually restarted");
249 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
250 mutex_unlock(&dev
->wl
->mutex
);
252 mutex_unlock(&big_buffer_mutex
);
260 static struct file_operations drvinfo_fops
= {
261 .read
= drvinfo_read_file
,
262 .write
= write_file_dummy
,
263 .open
= open_file_generic
,
266 static struct file_operations tsf_fops
= {
267 .read
= tsf_read_file
,
268 .write
= tsf_write_file
,
269 .open
= open_file_generic
,
272 static struct file_operations txstat_fops
= {
273 .read
= txstat_read_file
,
274 .write
= write_file_dummy
,
275 .open
= open_file_generic
,
278 static struct file_operations restart_fops
= {
279 .write
= restart_write_file
,
280 .open
= open_file_generic
,
284 void bcm43xx_debugfs_add_device(struct bcm43xx_wldev
*dev
)
286 struct bcm43xx_dfsentry
*e
;
287 struct bcm43xx_txstatus_log
*log
;
291 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
293 printk(KERN_ERR PFX
"out of memory\n");
298 log
->log
= kcalloc(BCM43xx_NR_LOGGED_TXSTATUS
,
299 sizeof(struct bcm43xx_txstatus
),
302 printk(KERN_ERR PFX
"debugfs txstatus log OOM\n");
307 spin_lock_init(&log
->lock
);
311 snprintf(devdir
, sizeof(devdir
), "%s", wiphy_name(dev
->wl
->hw
->wiphy
));
312 e
->subdir
= debugfs_create_dir(devdir
, fs
.root
);
313 e
->dentry_tsf
= debugfs_create_file("tsf", 0666, e
->subdir
,
316 printk(KERN_ERR PFX
"debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir
);
317 e
->dentry_txstat
= debugfs_create_file("tx_status", 0444, e
->subdir
,
319 if (!e
->dentry_txstat
)
320 printk(KERN_ERR PFX
"debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir
);
321 e
->dentry_restart
= debugfs_create_file("restart", 0222, e
->subdir
,
323 if (!e
->dentry_restart
)
324 printk(KERN_ERR PFX
"debugfs: creating \"restart\" for \"%s\" failed!\n", devdir
);
327 void bcm43xx_debugfs_remove_device(struct bcm43xx_wldev
*dev
)
329 struct bcm43xx_dfsentry
*e
;
336 debugfs_remove(e
->dentry_tsf
);
337 debugfs_remove(e
->dentry_txstat
);
338 debugfs_remove(e
->dentry_restart
);
339 debugfs_remove(e
->subdir
);
340 kfree(e
->txstatlog
.log
);
344 void bcm43xx_debugfs_log_txstat(struct bcm43xx_wldev
*dev
,
345 const struct bcm43xx_txstatus
*status
)
347 struct bcm43xx_dfsentry
*e
= dev
->dfsentry
;
348 struct bcm43xx_txstatus_log
*log
;
349 struct bcm43xx_txstatus
*cur
;
353 assert(irqs_disabled());
354 spin_lock(&log
->lock
);
356 if (i
== BCM43xx_NR_LOGGED_TXSTATUS
)
359 cur
= &(log
->log
[i
]);
360 memcpy(cur
, status
, sizeof(*cur
));
361 spin_unlock(&log
->lock
);
364 void bcm43xx_debugfs_init(void)
366 memset(&fs
, 0, sizeof(fs
));
367 fs
.root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
369 printk(KERN_ERR PFX
"debugfs: creating \"" KBUILD_MODNAME
"\" subdir failed!\n");
370 fs
.dentry_driverinfo
= debugfs_create_file("driver", 0444, fs
.root
, NULL
, &drvinfo_fops
);
371 if (!fs
.dentry_driverinfo
)
372 printk(KERN_ERR PFX
"debugfs: creating \"" KBUILD_MODNAME
"/driver\" failed!\n");
375 void bcm43xx_debugfs_exit(void)
377 debugfs_remove(fs
.dentry_driverinfo
);
378 debugfs_remove(fs
.root
);
381 void bcm43xx_printk_dump(const char *data
,
383 const char *description
)
388 printk(KERN_INFO PFX
"Data dump (%s, %lu bytes):",
389 description
, (unsigned long)size
);
390 for (i
= 0; i
< size
; i
++) {
393 printk("\n" KERN_INFO PFX
"0x%08x: 0x%02x, ", i
, c
& 0xff);
395 printk("0x%02x, ", c
& 0xff);
400 void bcm43xx_printk_bitdump(const unsigned char *data
,
401 size_t bytes
, int msb_to_lsb
,
402 const char *description
)
406 const unsigned char *d
;
408 printk(KERN_INFO PFX
"*** Bitdump (%s, %lu bytes, %s) ***",
409 description
, (unsigned long)bytes
,
410 msb_to_lsb
? "MSB to LSB" : "LSB to MSB");
411 for (i
= 0; i
< bytes
; i
++) {
414 printk("\n" KERN_INFO PFX
"0x%08x: ", i
);
416 for (j
= 7; j
>= 0; j
--) {
423 for (j
= 0; j
< 8; j
++) {