3 Broadcom B43 wireless driver
5 debugfs driver debugging code
7 Copyright (c) 2005-2007 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.
27 #include <linux/debugfs.h>
28 #include <linux/slab.h>
29 #include <linux/netdevice.h>
30 #include <linux/pci.h>
31 #include <linux/mutex.h>
41 /* The root directory. */
42 static struct dentry
*rootdir
;
44 struct b43_debugfs_fops
{
45 ssize_t (*read
)(struct b43_wldev
*dev
, char *buf
, size_t bufsize
);
46 int (*write
)(struct b43_wldev
*dev
, const char *buf
, size_t count
);
47 struct file_operations fops
;
48 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
49 size_t file_struct_offset
;
50 /* Take wl->irq_lock before calling read/write? */
55 struct b43_dfs_file
* fops_to_dfs_file(struct b43_wldev
*dev
,
56 const struct b43_debugfs_fops
*dfops
)
61 p
+= dfops
->file_struct_offset
;
67 #define fappend(fmt, x...) \
69 if (bufsize - count) \
70 count += snprintf(buf + count, \
74 printk(KERN_ERR "b43: fappend overflow\n"); \
78 /* wl->irq_lock is locked */
79 static ssize_t
tsf_read_file(struct b43_wldev
*dev
,
80 char *buf
, size_t bufsize
)
85 b43_tsf_read(dev
, &tsf
);
86 fappend("0x%08x%08x\n",
87 (unsigned int)((tsf
& 0xFFFFFFFF00000000ULL
) >> 32),
88 (unsigned int)(tsf
& 0xFFFFFFFFULL
));
93 /* wl->irq_lock is locked */
94 static int tsf_write_file(struct b43_wldev
*dev
,
95 const char *buf
, size_t count
)
99 if (sscanf(buf
, "%llu", (unsigned long long *)(&tsf
)) != 1)
101 b43_tsf_write(dev
, tsf
);
106 /* wl->irq_lock is locked */
107 static ssize_t
ucode_regs_read_file(struct b43_wldev
*dev
,
108 char *buf
, size_t bufsize
)
113 for (i
= 0; i
< 64; i
++) {
114 fappend("r%d = 0x%04x\n", i
,
115 b43_shm_read16(dev
, B43_SHM_SCRATCH
, i
));
121 /* wl->irq_lock is locked */
122 static ssize_t
shm_read_file(struct b43_wldev
*dev
,
123 char *buf
, size_t bufsize
)
128 __le16
*le16buf
= (__le16
*)buf
;
130 for (i
= 0; i
< 0x1000; i
++) {
133 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, 2 * i
);
134 le16buf
[i
] = cpu_to_le16(tmp
);
135 count
+= sizeof(tmp
);
136 bufsize
-= sizeof(tmp
);
142 static ssize_t
txstat_read_file(struct b43_wldev
*dev
,
143 char *buf
, size_t bufsize
)
145 struct b43_txstatus_log
*log
= &dev
->dfsentry
->txstatlog
;
149 struct b43_txstatus
*stat
;
151 spin_lock_irqsave(&log
->lock
, flags
);
153 fappend("Nothing transmitted, yet\n");
156 fappend("b43 TX status reports:\n\n"
157 "index | cookie | seq | phy_stat | frame_count | "
158 "rts_count | supp_reason | pm_indicated | "
159 "intermediate | for_ampdu | acked\n" "---\n");
163 if (i
== B43_NR_LOGGED_TXSTATUS
)
165 stat
= &(log
->log
[i
]);
168 "0x%04X | 0x%04X | 0x%02X | "
173 stat
->cookie
, stat
->seq
, stat
->phy_stat
,
174 stat
->frame_count
, stat
->rts_count
,
175 stat
->supp_reason
, stat
->pm_indicated
,
176 stat
->intermediate
, stat
->for_ampdu
,
185 spin_unlock_irqrestore(&log
->lock
, flags
);
190 static ssize_t
txpower_g_read_file(struct b43_wldev
*dev
,
191 char *buf
, size_t bufsize
)
195 if (dev
->phy
.type
!= B43_PHYTYPE_G
) {
196 fappend("Device is not a G-PHY\n");
199 fappend("Control: %s\n", dev
->phy
.manual_txpower_control
?
200 "MANUAL" : "AUTOMATIC");
201 fappend("Baseband attenuation: %u\n", dev
->phy
.bbatt
.att
);
202 fappend("Radio attenuation: %u\n", dev
->phy
.rfatt
.att
);
203 fappend("TX Mixer Gain: %s\n",
204 (dev
->phy
.tx_control
& B43_TXCTL_TXMIX
) ? "ON" : "OFF");
205 fappend("PA Gain 2dB: %s\n",
206 (dev
->phy
.tx_control
& B43_TXCTL_PA2DB
) ? "ON" : "OFF");
207 fappend("PA Gain 3dB: %s\n",
208 (dev
->phy
.tx_control
& B43_TXCTL_PA3DB
) ? "ON" : "OFF");
210 fappend("You can write to this file:\n");
211 fappend("Writing \"auto\" enables automatic txpower control.\n");
213 ("Writing the attenuation values as \"bbatt rfatt txmix pa2db pa3db\" "
214 "enables manual txpower control.\n");
215 fappend("Example: 5 4 0 0 1\n");
216 fappend("Enables manual control with Baseband attenuation 5, "
217 "Radio attenuation 4, No TX Mixer Gain, "
218 "No PA Gain 2dB, With PA Gain 3dB.\n");
223 static int txpower_g_write_file(struct b43_wldev
*dev
,
224 const char *buf
, size_t count
)
226 unsigned long phy_flags
;
228 if (dev
->phy
.type
!= B43_PHYTYPE_G
)
230 if ((count
>= 4) && (memcmp(buf
, "auto", 4) == 0)) {
231 /* Automatic control */
232 dev
->phy
.manual_txpower_control
= 0;
233 b43_phy_xmitpower(dev
);
235 int bbatt
= 0, rfatt
= 0, txmix
= 0, pa2db
= 0, pa3db
= 0;
237 if (sscanf(buf
, "%d %d %d %d %d", &bbatt
, &rfatt
,
238 &txmix
, &pa2db
, &pa3db
) != 5)
240 b43_put_attenuation_into_ranges(dev
, &bbatt
, &rfatt
);
241 dev
->phy
.manual_txpower_control
= 1;
242 dev
->phy
.bbatt
.att
= bbatt
;
243 dev
->phy
.rfatt
.att
= rfatt
;
244 dev
->phy
.tx_control
= 0;
246 dev
->phy
.tx_control
|= B43_TXCTL_TXMIX
;
248 dev
->phy
.tx_control
|= B43_TXCTL_PA2DB
;
250 dev
->phy
.tx_control
|= B43_TXCTL_PA3DB
;
251 b43_phy_lock(dev
, phy_flags
);
253 b43_set_txpower_g(dev
, &dev
->phy
.bbatt
,
254 &dev
->phy
.rfatt
, dev
->phy
.tx_control
);
255 b43_radio_unlock(dev
);
256 b43_phy_unlock(dev
, phy_flags
);
262 /* wl->irq_lock is locked */
263 static int restart_write_file(struct b43_wldev
*dev
,
264 const char *buf
, size_t count
)
268 if (count
> 0 && buf
[0] == '1') {
269 b43_controller_restart(dev
, "manually restarted");
276 static ssize_t
append_lo_table(ssize_t count
, char *buf
, const size_t bufsize
,
277 struct b43_loctl table
[B43_NR_BB
][B43_NR_RF
])
280 struct b43_loctl
*ctl
;
282 for (i
= 0; i
< B43_NR_BB
; i
++) {
283 for (j
= 0; j
< B43_NR_RF
; j
++) {
284 ctl
= &(table
[i
][j
]);
285 fappend("(bbatt %2u, rfatt %2u) -> "
286 "(I %+3d, Q %+3d, Used: %d, Calibrated: %d)\n",
287 i
, j
, ctl
->i
, ctl
->q
,
289 b43_loctl_is_calibrated(ctl
));
296 static ssize_t
loctls_read_file(struct b43_wldev
*dev
,
297 char *buf
, size_t bufsize
)
300 struct b43_txpower_lo_control
*lo
;
303 if (dev
->phy
.type
!= B43_PHYTYPE_G
) {
304 fappend("Device is not a G-PHY\n");
308 lo
= dev
->phy
.lo_control
;
309 fappend("-- Local Oscillator calibration data --\n\n");
310 fappend("Measured: %d, Rebuild: %d, HW-power-control: %d\n",
313 dev
->phy
.hardware_power_control
);
314 fappend("TX Bias: 0x%02X, TX Magn: 0x%02X\n",
315 lo
->tx_bias
, lo
->tx_magn
);
316 fappend("Power Vector: 0x%08X%08X\n",
317 (unsigned int)((lo
->power_vector
& 0xFFFFFFFF00000000ULL
) >> 32),
318 (unsigned int)(lo
->power_vector
& 0x00000000FFFFFFFFULL
));
319 fappend("\nControl table WITH PADMIX:\n");
320 count
= append_lo_table(count
, buf
, bufsize
, lo
->with_padmix
);
321 fappend("\nControl table WITHOUT PADMIX:\n");
322 count
= append_lo_table(count
, buf
, bufsize
, lo
->no_padmix
);
323 fappend("\nUsed RF attenuation values: Value(WithPadmix flag)\n");
324 for (i
= 0; i
< lo
->rfatt_list
.len
; i
++) {
326 lo
->rfatt_list
.list
[i
].att
,
327 lo
->rfatt_list
.list
[i
].with_padmix
);
330 fappend("\nUsed Baseband attenuation values:\n");
331 for (i
= 0; i
< lo
->bbatt_list
.len
; i
++) {
333 lo
->bbatt_list
.list
[i
].att
);
338 return err
? err
: count
;
343 static int b43_debugfs_open(struct inode
*inode
, struct file
*file
)
345 file
->private_data
= inode
->i_private
;
349 static ssize_t
b43_debugfs_read(struct file
*file
, char __user
*userbuf
,
350 size_t count
, loff_t
*ppos
)
352 struct b43_wldev
*dev
;
353 struct b43_debugfs_fops
*dfops
;
354 struct b43_dfs_file
*dfile
;
357 const size_t bufsize
= 1024 * 128;
358 const size_t buforder
= get_order(bufsize
);
363 dev
= file
->private_data
;
367 mutex_lock(&dev
->wl
->mutex
);
368 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
373 dfops
= container_of(file
->f_op
, struct b43_debugfs_fops
, fops
);
378 dfile
= fops_to_dfs_file(dev
, dfops
);
380 if (!dfile
->buffer
) {
381 buf
= (char *)__get_free_pages(GFP_KERNEL
, buforder
);
386 /* Sparse warns about the following memset, because it has a big
387 * size value. That warning is bogus, so I will ignore it. --mb */
388 memset(buf
, 0, bufsize
);
389 if (dfops
->take_irqlock
) {
390 spin_lock_irq(&dev
->wl
->irq_lock
);
391 ret
= dfops
->read(dev
, buf
, bufsize
);
392 spin_unlock_irq(&dev
->wl
->irq_lock
);
394 ret
= dfops
->read(dev
, buf
, bufsize
);
396 free_pages((unsigned long)buf
, buforder
);
400 dfile
->data_len
= ret
;
404 ret
= simple_read_from_buffer(userbuf
, count
, ppos
,
407 if (*ppos
>= dfile
->data_len
) {
408 free_pages((unsigned long)dfile
->buffer
, buforder
);
409 dfile
->buffer
= NULL
;
413 mutex_unlock(&dev
->wl
->mutex
);
415 return err
? err
: ret
;
418 static ssize_t
b43_debugfs_write(struct file
*file
,
419 const char __user
*userbuf
,
420 size_t count
, loff_t
*ppos
)
422 struct b43_wldev
*dev
;
423 struct b43_debugfs_fops
*dfops
;
429 if (count
> PAGE_SIZE
)
431 dev
= file
->private_data
;
435 mutex_lock(&dev
->wl
->mutex
);
436 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
441 dfops
= container_of(file
->f_op
, struct b43_debugfs_fops
, fops
);
447 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
452 if (copy_from_user(buf
, userbuf
, count
)) {
456 if (dfops
->take_irqlock
) {
457 spin_lock_irq(&dev
->wl
->irq_lock
);
458 err
= dfops
->write(dev
, buf
, count
);
459 spin_unlock_irq(&dev
->wl
->irq_lock
);
461 err
= dfops
->write(dev
, buf
, count
);
466 free_page((unsigned long)buf
);
468 mutex_unlock(&dev
->wl
->mutex
);
470 return err
? err
: count
;
474 #define B43_DEBUGFS_FOPS(name, _read, _write, _take_irqlock) \
475 static struct b43_debugfs_fops fops_##name = { \
479 .open = b43_debugfs_open, \
480 .read = b43_debugfs_read, \
481 .write = b43_debugfs_write, \
483 .file_struct_offset = offsetof(struct b43_dfsentry, \
485 .take_irqlock = _take_irqlock, \
488 B43_DEBUGFS_FOPS(tsf
, tsf_read_file
, tsf_write_file
, 1);
489 B43_DEBUGFS_FOPS(ucode_regs
, ucode_regs_read_file
, NULL
, 1);
490 B43_DEBUGFS_FOPS(shm
, shm_read_file
, NULL
, 1);
491 B43_DEBUGFS_FOPS(txstat
, txstat_read_file
, NULL
, 0);
492 B43_DEBUGFS_FOPS(txpower_g
, txpower_g_read_file
, txpower_g_write_file
, 0);
493 B43_DEBUGFS_FOPS(restart
, NULL
, restart_write_file
, 1);
494 B43_DEBUGFS_FOPS(loctls
, loctls_read_file
, NULL
, 0);
497 int b43_debug(struct b43_wldev
*dev
, enum b43_dyndbg feature
)
499 return !!(dev
->dfsentry
&& dev
->dfsentry
->dyn_debug
[feature
]);
502 static void b43_remove_dynamic_debug(struct b43_wldev
*dev
)
504 struct b43_dfsentry
*e
= dev
->dfsentry
;
507 for (i
= 0; i
< __B43_NR_DYNDBG
; i
++)
508 debugfs_remove(e
->dyn_debug_dentries
[i
]);
511 static void b43_add_dynamic_debug(struct b43_wldev
*dev
)
513 struct b43_dfsentry
*e
= dev
->dfsentry
;
516 #define add_dyn_dbg(name, id, initstate) do { \
517 e->dyn_debug[id] = (initstate); \
518 d = debugfs_create_bool(name, 0600, e->subdir, \
519 &(e->dyn_debug[id])); \
521 e->dyn_debug_dentries[id] = d; \
524 add_dyn_dbg("debug_xmitpower", B43_DBG_XMITPOWER
, 0);
525 add_dyn_dbg("debug_dmaoverflow", B43_DBG_DMAOVERFLOW
, 0);
526 add_dyn_dbg("debug_dmaverbose", B43_DBG_DMAVERBOSE
, 0);
527 add_dyn_dbg("debug_pwork_fast", B43_DBG_PWORK_FAST
, 0);
528 add_dyn_dbg("debug_pwork_stop", B43_DBG_PWORK_STOP
, 0);
533 void b43_debugfs_add_device(struct b43_wldev
*dev
)
535 struct b43_dfsentry
*e
;
536 struct b43_txstatus_log
*log
;
540 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
542 b43err(dev
->wl
, "debugfs: add device OOM\n");
547 log
->log
= kcalloc(B43_NR_LOGGED_TXSTATUS
,
548 sizeof(struct b43_txstatus
), GFP_KERNEL
);
550 b43err(dev
->wl
, "debugfs: add device txstatus OOM\n");
555 spin_lock_init(&log
->lock
);
559 snprintf(devdir
, sizeof(devdir
), "%s", wiphy_name(dev
->wl
->hw
->wiphy
));
560 e
->subdir
= debugfs_create_dir(devdir
, rootdir
);
561 if (!e
->subdir
|| IS_ERR(e
->subdir
)) {
562 if (e
->subdir
== ERR_PTR(-ENODEV
)) {
563 b43dbg(dev
->wl
, "DebugFS (CONFIG_DEBUG_FS) not "
564 "enabled in kernel config\n");
566 b43err(dev
->wl
, "debugfs: cannot create %s directory\n",
569 dev
->dfsentry
= NULL
;
575 #define ADD_FILE(name, mode) \
578 d = debugfs_create_file(__stringify(name), \
579 mode, e->subdir, dev, \
580 &fops_##name.fops); \
581 e->file_##name.dentry = NULL; \
583 e->file_##name.dentry = d; \
588 ADD_FILE(ucode_regs
, 0400);
590 ADD_FILE(txstat
, 0400);
591 ADD_FILE(txpower_g
, 0600);
592 ADD_FILE(restart
, 0200);
593 ADD_FILE(loctls
, 0400);
597 b43_add_dynamic_debug(dev
);
600 void b43_debugfs_remove_device(struct b43_wldev
*dev
)
602 struct b43_dfsentry
*e
;
609 b43_remove_dynamic_debug(dev
);
611 debugfs_remove(e
->file_tsf
.dentry
);
612 debugfs_remove(e
->file_ucode_regs
.dentry
);
613 debugfs_remove(e
->file_shm
.dentry
);
614 debugfs_remove(e
->file_txstat
.dentry
);
615 debugfs_remove(e
->file_txpower_g
.dentry
);
616 debugfs_remove(e
->file_restart
.dentry
);
617 debugfs_remove(e
->file_loctls
.dentry
);
619 debugfs_remove(e
->subdir
);
620 kfree(e
->txstatlog
.log
);
624 void b43_debugfs_log_txstat(struct b43_wldev
*dev
,
625 const struct b43_txstatus
*status
)
627 struct b43_dfsentry
*e
= dev
->dfsentry
;
628 struct b43_txstatus_log
*log
;
629 struct b43_txstatus
*cur
;
635 B43_WARN_ON(!irqs_disabled());
636 spin_lock(&log
->lock
);
638 if (i
== B43_NR_LOGGED_TXSTATUS
)
641 cur
= &(log
->log
[i
]);
642 memcpy(cur
, status
, sizeof(*cur
));
643 spin_unlock(&log
->lock
);
646 void b43_debugfs_init(void)
648 rootdir
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
653 void b43_debugfs_exit(void)
655 debugfs_remove(rootdir
);
This page took 0.080653 seconds and 5 git commands to generate.