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
);
257 static ssize_t
txpower_g_read_file(struct file
*file
, char __user
*userbuf
,
258 size_t count
, loff_t
*ppos
)
260 struct bcm43xx_wldev
*dev
= file
->private_data
;
261 const size_t len
= ARRAY_SIZE(big_buffer
);
262 char *buf
= big_buffer
;
267 mutex_lock(&big_buffer_mutex
);
268 mutex_lock(&dev
->wl
->mutex
);
269 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
270 if ((bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) ||
272 fappend("Not initialized\n");
275 if (dev
->phy
.type
!= BCM43xx_PHYTYPE_G
) {
276 fappend("Device is not a G-PHY\n");
279 fappend("Control: %s\n", dev
->phy
.manual_txpower_control
?
280 "MANUAL" : "AUTOMATIC");
281 fappend("Baseband attenuation: %u\n", dev
->phy
.bbatt
.att
);
282 fappend("Radio attenuation: %u\n", dev
->phy
.rfatt
.att
);
283 fappend("TX Mixer Gain: %s\n", (dev
->phy
.tx_control
& BCM43xx_TXCTL_TXMIX
) ?
285 fappend("PA Gain 2dB: %s\n", (dev
->phy
.tx_control
& BCM43xx_TXCTL_PA2DB
) ?
287 fappend("PA Gain 3dB: %s\n", (dev
->phy
.tx_control
& BCM43xx_TXCTL_PA3DB
) ?
290 fappend("You can write to this file:\n");
291 fappend("Writing \"auto\" enables automatic txpower control.\n");
292 fappend("Writing the attenuation values as \"bbatt rfatt txmix pa2db pa3db\" "
293 "enables manual txpower control.\n");
294 fappend("Example: 5 4 0 0 1\n");
295 fappend("Enables manual control with Baseband attenuation 5, "
296 "Radio attenuation 4, No TX Mixer Gain, "
297 "No PA Gain 2dB, With PA Gain 3dB.\n");
300 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
301 mutex_unlock(&dev
->wl
->mutex
);
302 res
= simple_read_from_buffer(userbuf
, count
, ppos
, buf
, pos
);
303 mutex_unlock(&big_buffer_mutex
);
308 static ssize_t
txpower_g_write_file(struct file
*file
, const char __user
*user_buf
,
309 size_t count
, loff_t
*ppos
)
311 struct bcm43xx_wldev
*dev
= file
->private_data
;
312 char *buf
= big_buffer
;
315 unsigned long flags
, phy_flags
;
317 mutex_lock(&big_buffer_mutex
);
318 buf_size
= min(count
, ARRAY_SIZE(big_buffer
) - 1);
319 if (copy_from_user(buf
, user_buf
, buf_size
)) {
323 mutex_lock(&dev
->wl
->mutex
);
324 spin_lock_irqsave(&dev
->wl
->irq_lock
, flags
);
325 if ((bcm43xx_status(dev
) != BCM43xx_STAT_INITIALIZED
) ||
327 printk(KERN_INFO PFX
"debugfs: Board not initialized.\n");
331 if (dev
->phy
.type
!= BCM43xx_PHYTYPE_G
) {
332 printk(KERN_ERR PFX
"debugfs: Device is not a G-PHY\n");
336 if ((buf_size
>= 4) && (memcmp(buf
, "auto", 4) == 0)) {
337 /* Automatic control */
338 dev
->phy
.manual_txpower_control
= 0;
339 bcm43xx_phy_xmitpower(dev
);
341 int bbatt
= 0, rfatt
= 0, txmix
= 0, pa2db
= 0, pa3db
= 0;
343 if (sscanf(buf
, "%d %d %d %d %d", &bbatt
, &rfatt
,
344 &txmix
, &pa2db
, &pa3db
) != 5) {
345 printk(KERN_INFO PFX
"debugfs: invalid value for \"tx_power_g\"\n");
349 bcm43xx_put_attenuation_into_ranges(dev
, &bbatt
, &rfatt
);
350 dev
->phy
.manual_txpower_control
= 1;
351 dev
->phy
.bbatt
.att
= bbatt
;
352 dev
->phy
.rfatt
.att
= rfatt
;
353 dev
->phy
.tx_control
= 0;
355 dev
->phy
.tx_control
|= BCM43xx_TXCTL_TXMIX
;
357 dev
->phy
.tx_control
|= BCM43xx_TXCTL_PA2DB
;
359 dev
->phy
.tx_control
|= BCM43xx_TXCTL_PA3DB
;
360 bcm43xx_phy_lock(dev
, phy_flags
);
361 bcm43xx_radio_lock(dev
);
362 bcm43xx_set_txpower_g(dev
, &dev
->phy
.bbatt
,
363 &dev
->phy
.rfatt
, dev
->phy
.tx_control
);
364 bcm43xx_radio_unlock(dev
);
365 bcm43xx_phy_unlock(dev
, phy_flags
);
369 spin_unlock_irqrestore(&dev
->wl
->irq_lock
, flags
);
370 mutex_unlock(&dev
->wl
->mutex
);
372 mutex_unlock(&big_buffer_mutex
);
381 static struct file_operations drvinfo_fops
= {
382 .read
= drvinfo_read_file
,
383 .write
= write_file_dummy
,
384 .open
= open_file_generic
,
387 static struct file_operations tsf_fops
= {
388 .read
= tsf_read_file
,
389 .write
= tsf_write_file
,
390 .open
= open_file_generic
,
393 static struct file_operations txstat_fops
= {
394 .read
= txstat_read_file
,
395 .write
= write_file_dummy
,
396 .open
= open_file_generic
,
399 static struct file_operations txpower_g_fops
= {
400 .read
= txpower_g_read_file
,
401 .write
= txpower_g_write_file
,
402 .open
= open_file_generic
,
405 static struct file_operations restart_fops
= {
406 .write
= restart_write_file
,
407 .open
= open_file_generic
,
411 int bcm43xx_debug(struct bcm43xx_wldev
*dev
, enum bcm43xx_dyndbg feature
)
413 return !!(dev
->dfsentry
->dyn_debug
[feature
]);
416 static void bcm43xx_remove_dynamic_debug(struct bcm43xx_wldev
*dev
)
418 struct bcm43xx_dfsentry
*e
= dev
->dfsentry
;
421 for (i
= 0; i
< __BCM43xx_NR_DYNDBG
; i
++)
422 debugfs_remove(e
->dyn_debug_dentries
[i
]);
425 static void bcm43xx_add_dynamic_debug(struct bcm43xx_wldev
*dev
)
427 struct bcm43xx_dfsentry
*e
= dev
->dfsentry
;
430 #define add_dyn_dbg(name, id, initstate) do { \
431 e->dyn_debug[id] = (initstate); \
432 d = debugfs_create_bool(name, 0600, e->subdir, \
433 &(e->dyn_debug[id])); \
435 e->dyn_debug_dentries[id] = d; \
438 add_dyn_dbg("debug_xmitpower", BCM43xx_DBG_XMITPOWER
, 0);
439 add_dyn_dbg("debug_dmaoverflow", BCM43xx_DBG_DMAOVERFLOW
, 0);
440 add_dyn_dbg("debug_dmaverbose", BCM43xx_DBG_DMAVERBOSE
, 0);
441 add_dyn_dbg("debug_pwork_fast", BCM43xx_DBG_PWORK_FAST
, 0);
442 add_dyn_dbg("debug_pwork_stop", BCM43xx_DBG_PWORK_STOP
, 0);
447 void bcm43xx_debugfs_add_device(struct bcm43xx_wldev
*dev
)
449 struct bcm43xx_dfsentry
*e
;
450 struct bcm43xx_txstatus_log
*log
;
454 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
456 printk(KERN_ERR PFX
"debugfs: add device OOM\n");
461 log
->log
= kcalloc(BCM43xx_NR_LOGGED_TXSTATUS
,
462 sizeof(struct bcm43xx_txstatus
),
465 printk(KERN_ERR PFX
"debugfs: add device txstatus OOM\n");
470 spin_lock_init(&log
->lock
);
474 snprintf(devdir
, sizeof(devdir
), "%s", wiphy_name(dev
->wl
->hw
->wiphy
));
475 e
->subdir
= debugfs_create_dir(devdir
, fs
.root
);
476 if (!e
->subdir
|| IS_ERR(e
->subdir
)) {
483 e
->dentry_tsf
= debugfs_create_file("tsf", 0600, e
->subdir
,
485 if (IS_ERR(e
->dentry_tsf
))
486 e
->dentry_tsf
= NULL
;
487 e
->dentry_txstat
= debugfs_create_file("tx_status", 0400, e
->subdir
,
489 if (IS_ERR(e
->dentry_txstat
))
490 e
->dentry_txstat
= NULL
;
491 e
->dentry_txpower_g
= debugfs_create_file("tx_power_g", 0600, e
->subdir
,
492 dev
, &txpower_g_fops
);
493 if (IS_ERR(e
->dentry_txpower_g
))
494 e
->dentry_txpower_g
= NULL
;
495 e
->dentry_restart
= debugfs_create_file("restart", 0200, e
->subdir
,
497 if (IS_ERR(e
->dentry_restart
))
498 e
->dentry_restart
= NULL
;
500 bcm43xx_add_dynamic_debug(dev
);
503 void bcm43xx_debugfs_remove_device(struct bcm43xx_wldev
*dev
)
505 struct bcm43xx_dfsentry
*e
;
512 bcm43xx_remove_dynamic_debug(dev
);
513 debugfs_remove(e
->dentry_tsf
);
514 debugfs_remove(e
->dentry_txstat
);
515 debugfs_remove(e
->dentry_restart
);
516 debugfs_remove(e
->dentry_txpower_g
);
517 debugfs_remove(e
->subdir
);
518 kfree(e
->txstatlog
.log
);
522 void bcm43xx_debugfs_log_txstat(struct bcm43xx_wldev
*dev
,
523 const struct bcm43xx_txstatus
*status
)
525 struct bcm43xx_dfsentry
*e
= dev
->dfsentry
;
526 struct bcm43xx_txstatus_log
*log
;
527 struct bcm43xx_txstatus
*cur
;
531 assert(irqs_disabled());
532 spin_lock(&log
->lock
);
534 if (i
== BCM43xx_NR_LOGGED_TXSTATUS
)
537 cur
= &(log
->log
[i
]);
538 memcpy(cur
, status
, sizeof(*cur
));
539 spin_unlock(&log
->lock
);
542 void bcm43xx_debugfs_init(void)
544 memset(&fs
, 0, sizeof(fs
));
545 fs
.root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
546 if (!fs
.root
|| IS_ERR(fs
.root
)) {
550 fs
.dentry_driverinfo
= debugfs_create_file("driver", 0444, fs
.root
,
551 NULL
, &drvinfo_fops
);
552 if (IS_ERR(fs
.dentry_driverinfo
))
553 fs
.dentry_driverinfo
= NULL
;
556 void bcm43xx_debugfs_exit(void)
558 debugfs_remove(fs
.dentry_driverinfo
);
559 debugfs_remove(fs
.root
);
562 void bcm43xx_printk_dump(const char *data
,
564 const char *description
)
569 printk(KERN_INFO PFX
"Data dump (%s, %lu bytes):",
570 description
, (unsigned long)size
);
571 for (i
= 0; i
< size
; i
++) {
574 printk("\n" KERN_INFO PFX
"0x%08x: 0x%02x, ", i
, c
& 0xff);
576 printk("0x%02x, ", c
& 0xff);
581 void bcm43xx_printk_bitdump(const unsigned char *data
,
582 size_t bytes
, int msb_to_lsb
,
583 const char *description
)
587 const unsigned char *d
;
589 printk(KERN_INFO PFX
"*** Bitdump (%s, %lu bytes, %s) ***",
590 description
, (unsigned long)bytes
,
591 msb_to_lsb
? "MSB to LSB" : "LSB to MSB");
592 for (i
= 0; i
< bytes
; i
++) {
595 printk("\n" KERN_INFO PFX
"0x%08x: ", i
);
597 for (j
= 7; j
>= 0; j
--) {
604 for (j
= 0; j
< 8; j
++) {