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>
40 /* The root directory. */
41 static struct dentry
*rootdir
;
43 struct b43_debugfs_fops
{
44 ssize_t (*read
)(struct b43_wldev
*dev
, char *buf
, size_t bufsize
);
45 int (*write
)(struct b43_wldev
*dev
, const char *buf
, size_t count
);
46 struct file_operations fops
;
47 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
48 size_t file_struct_offset
;
49 /* Take wl->irq_lock before calling read/write? */
54 struct b43_dfs_file
* fops_to_dfs_file(struct b43_wldev
*dev
,
55 const struct b43_debugfs_fops
*dfops
)
60 p
+= dfops
->file_struct_offset
;
66 #define fappend(fmt, x...) \
68 if (bufsize - count) \
69 count += snprintf(buf + count, \
73 printk(KERN_ERR "b43: fappend overflow\n"); \
77 /* wl->irq_lock is locked */
78 static ssize_t
tsf_read_file(struct b43_wldev
*dev
,
79 char *buf
, size_t bufsize
)
84 b43_tsf_read(dev
, &tsf
);
85 fappend("0x%08x%08x\n",
86 (unsigned int)((tsf
& 0xFFFFFFFF00000000ULL
) >> 32),
87 (unsigned int)(tsf
& 0xFFFFFFFFULL
));
92 /* wl->irq_lock is locked */
93 static int tsf_write_file(struct b43_wldev
*dev
,
94 const char *buf
, size_t count
)
98 if (sscanf(buf
, "%llu", (unsigned long long *)(&tsf
)) != 1)
100 b43_tsf_write(dev
, tsf
);
105 /* wl->irq_lock is locked */
106 static ssize_t
ucode_regs_read_file(struct b43_wldev
*dev
,
107 char *buf
, size_t bufsize
)
112 for (i
= 0; i
< 64; i
++) {
113 fappend("r%d = 0x%04x\n", i
,
114 b43_shm_read16(dev
, B43_SHM_SCRATCH
, i
));
120 /* wl->irq_lock is locked */
121 static ssize_t
shm_read_file(struct b43_wldev
*dev
,
122 char *buf
, size_t bufsize
)
127 __le16
*le16buf
= (__le16
*)buf
;
129 for (i
= 0; i
< 0x1000; i
++) {
130 if (bufsize
< sizeof(tmp
))
132 tmp
= b43_shm_read16(dev
, B43_SHM_SHARED
, 2 * i
);
133 le16buf
[i
] = cpu_to_le16(tmp
);
134 count
+= sizeof(tmp
);
135 bufsize
-= sizeof(tmp
);
141 static ssize_t
txstat_read_file(struct b43_wldev
*dev
,
142 char *buf
, size_t bufsize
)
144 struct b43_txstatus_log
*log
= &dev
->dfsentry
->txstatlog
;
148 struct b43_txstatus
*stat
;
150 spin_lock_irqsave(&log
->lock
, flags
);
152 fappend("Nothing transmitted, yet\n");
155 fappend("b43 TX status reports:\n\n"
156 "index | cookie | seq | phy_stat | frame_count | "
157 "rts_count | supp_reason | pm_indicated | "
158 "intermediate | for_ampdu | acked\n" "---\n");
162 if (i
== B43_NR_LOGGED_TXSTATUS
)
164 stat
= &(log
->log
[i
]);
167 "0x%04X | 0x%04X | 0x%02X | "
172 stat
->cookie
, stat
->seq
, stat
->phy_stat
,
173 stat
->frame_count
, stat
->rts_count
,
174 stat
->supp_reason
, stat
->pm_indicated
,
175 stat
->intermediate
, stat
->for_ampdu
,
184 spin_unlock_irqrestore(&log
->lock
, flags
);
189 static ssize_t
txpower_g_read_file(struct b43_wldev
*dev
,
190 char *buf
, size_t bufsize
)
194 if (dev
->phy
.type
!= B43_PHYTYPE_G
) {
195 fappend("Device is not a G-PHY\n");
198 fappend("Control: %s\n", dev
->phy
.manual_txpower_control
?
199 "MANUAL" : "AUTOMATIC");
200 fappend("Baseband attenuation: %u\n", dev
->phy
.bbatt
.att
);
201 fappend("Radio attenuation: %u\n", dev
->phy
.rfatt
.att
);
202 fappend("TX Mixer Gain: %s\n",
203 (dev
->phy
.tx_control
& B43_TXCTL_TXMIX
) ? "ON" : "OFF");
204 fappend("PA Gain 2dB: %s\n",
205 (dev
->phy
.tx_control
& B43_TXCTL_PA2DB
) ? "ON" : "OFF");
206 fappend("PA Gain 3dB: %s\n",
207 (dev
->phy
.tx_control
& B43_TXCTL_PA3DB
) ? "ON" : "OFF");
209 fappend("You can write to this file:\n");
210 fappend("Writing \"auto\" enables automatic txpower control.\n");
212 ("Writing the attenuation values as \"bbatt rfatt txmix pa2db pa3db\" "
213 "enables manual txpower control.\n");
214 fappend("Example: 5 4 0 0 1\n");
215 fappend("Enables manual control with Baseband attenuation 5, "
216 "Radio attenuation 4, No TX Mixer Gain, "
217 "No PA Gain 2dB, With PA Gain 3dB.\n");
222 static int txpower_g_write_file(struct b43_wldev
*dev
,
223 const char *buf
, size_t count
)
225 if (dev
->phy
.type
!= B43_PHYTYPE_G
)
227 if ((count
>= 4) && (memcmp(buf
, "auto", 4) == 0)) {
228 /* Automatic control */
229 dev
->phy
.manual_txpower_control
= 0;
230 b43_phy_xmitpower(dev
);
232 int bbatt
= 0, rfatt
= 0, txmix
= 0, pa2db
= 0, pa3db
= 0;
234 if (sscanf(buf
, "%d %d %d %d %d", &bbatt
, &rfatt
,
235 &txmix
, &pa2db
, &pa3db
) != 5)
237 b43_put_attenuation_into_ranges(dev
, &bbatt
, &rfatt
);
238 dev
->phy
.manual_txpower_control
= 1;
239 dev
->phy
.bbatt
.att
= bbatt
;
240 dev
->phy
.rfatt
.att
= rfatt
;
241 dev
->phy
.tx_control
= 0;
243 dev
->phy
.tx_control
|= B43_TXCTL_TXMIX
;
245 dev
->phy
.tx_control
|= B43_TXCTL_PA2DB
;
247 dev
->phy
.tx_control
|= B43_TXCTL_PA3DB
;
250 b43_set_txpower_g(dev
, &dev
->phy
.bbatt
,
251 &dev
->phy
.rfatt
, dev
->phy
.tx_control
);
252 b43_radio_unlock(dev
);
259 /* wl->irq_lock is locked */
260 static int restart_write_file(struct b43_wldev
*dev
,
261 const char *buf
, size_t count
)
265 if (count
> 0 && buf
[0] == '1') {
266 b43_controller_restart(dev
, "manually restarted");
273 static unsigned long calc_expire_secs(unsigned long now
,
275 unsigned long expire
)
277 expire
= time
+ expire
;
279 if (time_after(now
, expire
))
280 return 0; /* expired */
282 /* jiffies wrapped */
283 expire
-= MAX_JIFFY_OFFSET
;
284 now
-= MAX_JIFFY_OFFSET
;
286 B43_WARN_ON(expire
< now
);
288 return (expire
- now
) / HZ
;
291 static ssize_t
loctls_read_file(struct b43_wldev
*dev
,
292 char *buf
, size_t bufsize
)
295 struct b43_txpower_lo_control
*lo
;
297 struct b43_lo_calib
*cal
;
298 unsigned long now
= jiffies
;
299 struct b43_phy
*phy
= &dev
->phy
;
301 if (phy
->type
!= B43_PHYTYPE_G
) {
302 fappend("Device is not a G-PHY\n");
306 lo
= phy
->lo_control
;
307 fappend("-- Local Oscillator calibration data --\n\n");
308 fappend("HW-power-control enabled: %d\n",
309 dev
->phy
.hardware_power_control
);
310 fappend("TX Bias: 0x%02X, TX Magn: 0x%02X (expire in %lu sec)\n",
311 lo
->tx_bias
, lo
->tx_magn
,
312 calc_expire_secs(now
, lo
->txctl_measured_time
,
313 B43_LO_TXCTL_EXPIRE
));
314 fappend("Power Vector: 0x%08X%08X (expires in %lu sec)\n",
315 (unsigned int)((lo
->power_vector
& 0xFFFFFFFF00000000ULL
) >> 32),
316 (unsigned int)(lo
->power_vector
& 0x00000000FFFFFFFFULL
),
317 calc_expire_secs(now
, lo
->pwr_vec_read_time
,
318 B43_LO_PWRVEC_EXPIRE
));
320 fappend("\nCalibrated settings:\n");
321 list_for_each_entry(cal
, &lo
->calib_list
, list
) {
324 active
= (b43_compare_bbatt(&cal
->bbatt
, &phy
->bbatt
) &&
325 b43_compare_rfatt(&cal
->rfatt
, &phy
->rfatt
));
326 fappend("BB(%d), RF(%d,%d) -> I=%d, Q=%d "
327 "(expires in %lu sec)%s\n",
329 cal
->rfatt
.att
, cal
->rfatt
.with_padmix
,
330 cal
->ctl
.i
, cal
->ctl
.q
,
331 calc_expire_secs(now
, cal
->calib_time
,
332 B43_LO_CALIB_EXPIRE
),
333 active
? " ACTIVE" : "");
336 fappend("\nUsed RF attenuation values: Value(WithPadmix flag)\n");
337 for (i
= 0; i
< lo
->rfatt_list
.len
; i
++) {
339 lo
->rfatt_list
.list
[i
].att
,
340 lo
->rfatt_list
.list
[i
].with_padmix
);
343 fappend("\nUsed Baseband attenuation values:\n");
344 for (i
= 0; i
< lo
->bbatt_list
.len
; i
++) {
346 lo
->bbatt_list
.list
[i
].att
);
351 return err
? err
: count
;
356 static int b43_debugfs_open(struct inode
*inode
, struct file
*file
)
358 file
->private_data
= inode
->i_private
;
362 static ssize_t
b43_debugfs_read(struct file
*file
, char __user
*userbuf
,
363 size_t count
, loff_t
*ppos
)
365 struct b43_wldev
*dev
;
366 struct b43_debugfs_fops
*dfops
;
367 struct b43_dfs_file
*dfile
;
368 ssize_t
uninitialized_var(ret
);
370 const size_t bufsize
= 1024 * 16; /* 16 kiB buffer */
371 const size_t buforder
= get_order(bufsize
);
376 dev
= file
->private_data
;
380 mutex_lock(&dev
->wl
->mutex
);
381 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
386 dfops
= container_of(file
->f_op
, struct b43_debugfs_fops
, fops
);
391 dfile
= fops_to_dfs_file(dev
, dfops
);
393 if (!dfile
->buffer
) {
394 buf
= (char *)__get_free_pages(GFP_KERNEL
, buforder
);
399 memset(buf
, 0, bufsize
);
400 if (dfops
->take_irqlock
) {
401 spin_lock_irq(&dev
->wl
->irq_lock
);
402 ret
= dfops
->read(dev
, buf
, bufsize
);
403 spin_unlock_irq(&dev
->wl
->irq_lock
);
405 ret
= dfops
->read(dev
, buf
, bufsize
);
407 free_pages((unsigned long)buf
, buforder
);
411 dfile
->data_len
= ret
;
415 ret
= simple_read_from_buffer(userbuf
, count
, ppos
,
418 if (*ppos
>= dfile
->data_len
) {
419 free_pages((unsigned long)dfile
->buffer
, buforder
);
420 dfile
->buffer
= NULL
;
424 mutex_unlock(&dev
->wl
->mutex
);
426 return err
? err
: ret
;
429 static ssize_t
b43_debugfs_write(struct file
*file
,
430 const char __user
*userbuf
,
431 size_t count
, loff_t
*ppos
)
433 struct b43_wldev
*dev
;
434 struct b43_debugfs_fops
*dfops
;
440 if (count
> PAGE_SIZE
)
442 dev
= file
->private_data
;
446 mutex_lock(&dev
->wl
->mutex
);
447 if (b43_status(dev
) < B43_STAT_INITIALIZED
) {
452 dfops
= container_of(file
->f_op
, struct b43_debugfs_fops
, fops
);
458 buf
= (char *)get_zeroed_page(GFP_KERNEL
);
463 if (copy_from_user(buf
, userbuf
, count
)) {
467 if (dfops
->take_irqlock
) {
468 spin_lock_irq(&dev
->wl
->irq_lock
);
469 err
= dfops
->write(dev
, buf
, count
);
470 spin_unlock_irq(&dev
->wl
->irq_lock
);
472 err
= dfops
->write(dev
, buf
, count
);
477 free_page((unsigned long)buf
);
479 mutex_unlock(&dev
->wl
->mutex
);
481 return err
? err
: count
;
485 #define B43_DEBUGFS_FOPS(name, _read, _write, _take_irqlock) \
486 static struct b43_debugfs_fops fops_##name = { \
490 .open = b43_debugfs_open, \
491 .read = b43_debugfs_read, \
492 .write = b43_debugfs_write, \
494 .file_struct_offset = offsetof(struct b43_dfsentry, \
496 .take_irqlock = _take_irqlock, \
499 B43_DEBUGFS_FOPS(tsf
, tsf_read_file
, tsf_write_file
, 1);
500 B43_DEBUGFS_FOPS(ucode_regs
, ucode_regs_read_file
, NULL
, 1);
501 B43_DEBUGFS_FOPS(shm
, shm_read_file
, NULL
, 1);
502 B43_DEBUGFS_FOPS(txstat
, txstat_read_file
, NULL
, 0);
503 B43_DEBUGFS_FOPS(txpower_g
, txpower_g_read_file
, txpower_g_write_file
, 0);
504 B43_DEBUGFS_FOPS(restart
, NULL
, restart_write_file
, 1);
505 B43_DEBUGFS_FOPS(loctls
, loctls_read_file
, NULL
, 0);
508 int b43_debug(struct b43_wldev
*dev
, enum b43_dyndbg feature
)
510 return !!(dev
->dfsentry
&& dev
->dfsentry
->dyn_debug
[feature
]);
513 static void b43_remove_dynamic_debug(struct b43_wldev
*dev
)
515 struct b43_dfsentry
*e
= dev
->dfsentry
;
518 for (i
= 0; i
< __B43_NR_DYNDBG
; i
++)
519 debugfs_remove(e
->dyn_debug_dentries
[i
]);
522 static void b43_add_dynamic_debug(struct b43_wldev
*dev
)
524 struct b43_dfsentry
*e
= dev
->dfsentry
;
527 #define add_dyn_dbg(name, id, initstate) do { \
528 e->dyn_debug[id] = (initstate); \
529 d = debugfs_create_bool(name, 0600, e->subdir, \
530 &(e->dyn_debug[id])); \
532 e->dyn_debug_dentries[id] = d; \
535 add_dyn_dbg("debug_xmitpower", B43_DBG_XMITPOWER
, 0);
536 add_dyn_dbg("debug_dmaoverflow", B43_DBG_DMAOVERFLOW
, 0);
537 add_dyn_dbg("debug_dmaverbose", B43_DBG_DMAVERBOSE
, 0);
538 add_dyn_dbg("debug_pwork_fast", B43_DBG_PWORK_FAST
, 0);
539 add_dyn_dbg("debug_pwork_stop", B43_DBG_PWORK_STOP
, 0);
540 add_dyn_dbg("debug_lo", B43_DBG_LO
, 0);
545 void b43_debugfs_add_device(struct b43_wldev
*dev
)
547 struct b43_dfsentry
*e
;
548 struct b43_txstatus_log
*log
;
552 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
554 b43err(dev
->wl
, "debugfs: add device OOM\n");
559 log
->log
= kcalloc(B43_NR_LOGGED_TXSTATUS
,
560 sizeof(struct b43_txstatus
), GFP_KERNEL
);
562 b43err(dev
->wl
, "debugfs: add device txstatus OOM\n");
567 spin_lock_init(&log
->lock
);
571 snprintf(devdir
, sizeof(devdir
), "%s", wiphy_name(dev
->wl
->hw
->wiphy
));
572 e
->subdir
= debugfs_create_dir(devdir
, rootdir
);
573 if (!e
->subdir
|| IS_ERR(e
->subdir
)) {
574 if (e
->subdir
== ERR_PTR(-ENODEV
)) {
575 b43dbg(dev
->wl
, "DebugFS (CONFIG_DEBUG_FS) not "
576 "enabled in kernel config\n");
578 b43err(dev
->wl
, "debugfs: cannot create %s directory\n",
581 dev
->dfsentry
= NULL
;
587 #define ADD_FILE(name, mode) \
590 d = debugfs_create_file(__stringify(name), \
591 mode, e->subdir, dev, \
592 &fops_##name.fops); \
593 e->file_##name.dentry = NULL; \
595 e->file_##name.dentry = d; \
600 ADD_FILE(ucode_regs
, 0400);
602 ADD_FILE(txstat
, 0400);
603 ADD_FILE(txpower_g
, 0600);
604 ADD_FILE(restart
, 0200);
605 ADD_FILE(loctls
, 0400);
609 b43_add_dynamic_debug(dev
);
612 void b43_debugfs_remove_device(struct b43_wldev
*dev
)
614 struct b43_dfsentry
*e
;
621 b43_remove_dynamic_debug(dev
);
623 debugfs_remove(e
->file_tsf
.dentry
);
624 debugfs_remove(e
->file_ucode_regs
.dentry
);
625 debugfs_remove(e
->file_shm
.dentry
);
626 debugfs_remove(e
->file_txstat
.dentry
);
627 debugfs_remove(e
->file_txpower_g
.dentry
);
628 debugfs_remove(e
->file_restart
.dentry
);
629 debugfs_remove(e
->file_loctls
.dentry
);
631 debugfs_remove(e
->subdir
);
632 kfree(e
->txstatlog
.log
);
636 /* Called with IRQs disabled. */
637 void b43_debugfs_log_txstat(struct b43_wldev
*dev
,
638 const struct b43_txstatus
*status
)
640 struct b43_dfsentry
*e
= dev
->dfsentry
;
641 struct b43_txstatus_log
*log
;
642 struct b43_txstatus
*cur
;
648 spin_lock(&log
->lock
); /* IRQs are already disabled. */
650 if (i
== B43_NR_LOGGED_TXSTATUS
)
653 cur
= &(log
->log
[i
]);
654 memcpy(cur
, status
, sizeof(*cur
));
655 spin_unlock(&log
->lock
);
658 void b43_debugfs_init(void)
660 rootdir
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
665 void b43_debugfs_exit(void)
667 debugfs_remove(rootdir
);
This page took 0.083834 seconds and 5 git commands to generate.