28 #include <linux/slab.h>
29 #include <linux/netdevice.h>
30 #include <linux/pci.h>
41 static struct dentry *rootdir;
52 struct b43_dfs_file *fops_to_dfs_file(
struct b43_wldev *
dev,
64 #define fappend(fmt, x...) \
66 if (bufsize - count) \
67 count += snprintf(buf + count, \
71 printk(KERN_ERR "b43: fappend overflow\n"); \
76 #define B43_MAX_SHM_ROUTING 4
77 #define B43_MAX_SHM_ADDR 0xFFFF
83 unsigned int routing,
addr;
86 routing = dev->dfsentry->shm16read_routing_next;
87 addr = dev->dfsentry->shm16read_addr_next;
101 unsigned int routing,
addr;
104 res =
sscanf(buf,
"0x%X 0x%X", &routing, &addr);
116 dev->dfsentry->shm16read_routing_next = routing;
117 dev->dfsentry->shm16read_addr_next =
addr;
122 static int shm16write__write_file(
struct b43_wldev *dev,
123 const char *buf,
size_t count)
125 unsigned int routing,
addr,
mask,
set;
129 res =
sscanf(buf,
"0x%X 0x%X 0x%X 0x%X",
130 &routing, &addr, &mask, &
set);
141 if ((mask > 0xFFFF) || (
set > 0xFFFF))
159 unsigned int routing,
addr;
162 routing = dev->dfsentry->shm32read_routing_next;
163 addr = dev->dfsentry->shm32read_addr_next;
174 static int shm32read__write_file(
struct b43_wldev *dev,
175 const char *buf,
size_t count)
177 unsigned int routing,
addr;
180 res =
sscanf(buf,
"0x%X 0x%X", &routing, &addr);
192 dev->dfsentry->shm32read_routing_next = routing;
193 dev->dfsentry->shm32read_addr_next =
addr;
198 static int shm32write__write_file(
struct b43_wldev *dev,
199 const char *buf,
size_t count)
201 unsigned int routing,
addr,
mask,
set;
205 res =
sscanf(buf,
"0x%X 0x%X 0x%X 0x%X",
206 &routing, &addr, &mask, &
set);
217 if ((mask > 0xFFFFFFFF) || (
set > 0xFFFFFFFF))
232 #define B43_MAX_MMIO_ACCESS (0xF00 - 1)
235 char *buf,
size_t bufsize)
241 addr = dev->dfsentry->mmio16read_next;
245 val = b43_read16(dev, addr);
251 static int mmio16read__write_file(
struct b43_wldev *dev,
252 const char *buf,
size_t count)
257 res =
sscanf(buf,
"0x%X", &addr);
265 dev->dfsentry->mmio16read_next =
addr;
270 static int mmio16write__write_file(
struct b43_wldev *dev,
271 const char *buf,
size_t count)
277 res =
sscanf(buf,
"0x%X 0x%X 0x%X", &addr, &mask, &
set);
282 if ((mask > 0xFFFF) || (
set > 0xFFFF))
290 val = b43_read16(dev, addr);
293 b43_write16(dev, addr, val);
299 char *buf,
size_t bufsize)
305 addr = dev->dfsentry->mmio32read_next;
309 val = b43_read32(dev, addr);
315 static int mmio32read__write_file(
struct b43_wldev *dev,
316 const char *buf,
size_t count)
321 res =
sscanf(buf,
"0x%X", &addr);
329 dev->dfsentry->mmio32read_next =
addr;
334 static int mmio32write__write_file(
struct b43_wldev *dev,
335 const char *buf,
size_t count)
341 res =
sscanf(buf,
"0x%X 0x%X 0x%X", &addr, &mask, &
set);
346 if ((mask > 0xFFFFFFFF) || (
set > 0xFFFFFFFF))
354 val = b43_read32(dev, addr);
357 b43_write32(dev, addr, val);
363 char *buf,
size_t bufsize)
365 struct b43_txstatus_log *
log = &dev->dfsentry->txstatlog;
371 fappend(
"Nothing transmitted, yet\n");
374 fappend(
"b43 TX status reports:\n\n"
375 "index | cookie | seq | phy_stat | frame_count | "
376 "rts_count | supp_reason | pm_indicated | "
377 "intermediate | for_ampdu | acked\n" "---\n");
381 if (i == B43_NR_LOGGED_TXSTATUS)
383 stat = &(log->log[
i]);
386 "0x%04X | 0x%04X | 0x%02X | "
407 static int restart_write_file(
struct b43_wldev *dev,
408 const char *buf,
size_t count)
412 if (count > 0 && buf[0] ==
'1') {
420 static unsigned long calc_expire_secs(
unsigned long now,
422 unsigned long expire)
424 expire = time + expire;
435 return (expire - now) /
HZ;
439 char *buf,
size_t bufsize)
449 fappend(
"Device is not a G-PHY\n");
453 lo = phy->
g->lo_control;
454 fappend(
"-- Local Oscillator calibration data --\n\n");
455 fappend(
"HW-power-control enabled: %d\n",
456 dev->
phy.hardware_power_control);
457 fappend(
"TX Bias: 0x%02X, TX Magn: 0x%02X (expire in %lu sec)\n",
461 fappend(
"Power Vector: 0x%08X%08X (expires in %lu sec)\n",
462 (
unsigned int)((lo->
power_vector & 0xFFFFFFFF00000000ULL) >> 32),
463 (
unsigned int)(lo->
power_vector & 0x00000000FFFFFFFFULL),
467 fappend(
"\nCalibrated settings:\n");
471 active = (b43_compare_bbatt(&cal->
bbatt, &phy->
g->bbatt) &&
472 b43_compare_rfatt(&cal->
rfatt, &phy->
g->rfatt));
473 fappend(
"BB(%d), RF(%d,%d) -> I=%d, Q=%d "
474 "(expires in %lu sec)%s\n",
480 active ?
" ACTIVE" :
"");
483 fappend(
"\nUsed RF attenuation values: Value(WithPadmix flag)\n");
490 fappend(
"\nUsed Baseband attenuation values:\n");
498 return err ? err :
count;
503 static ssize_t b43_debugfs_read(
struct file *
file,
char __user *userbuf,
504 size_t count, loff_t *ppos)
508 struct b43_dfs_file *dfile;
511 const size_t bufsize = 1024 * 16;
512 const size_t buforder =
get_order(bufsize);
532 dfile = fops_to_dfs_file(dev, dfops);
534 if (!dfile->buffer) {
541 ret = dfops->
read(dev, buf, bufsize);
547 dfile->data_len =
ret;
554 if (*ppos >= dfile->data_len) {
555 free_pages((
unsigned long)dfile->buffer, buforder);
556 dfile->buffer =
NULL;
562 return err ? err :
ret;
565 static ssize_t b43_debugfs_write(
struct file *file,
566 const char __user *userbuf,
567 size_t count, loff_t *ppos)
603 err = dfops->
write(dev, buf, count);
612 return err ? err :
count;
616 #define B43_DEBUGFS_FOPS(name, _read, _write) \
617 static struct b43_debugfs_fops fops_##name = { \
621 .open = simple_open, \
622 .read = b43_debugfs_read, \
623 .write = b43_debugfs_write, \
624 .llseek = generic_file_llseek, \
626 .file_struct_offset = offsetof(struct b43_dfsentry, \
634 B43_DEBUGFS_FOPS(mmio16read, mmio16read__read_file, mmio16read__write_file);
636 B43_DEBUGFS_FOPS(mmio32read, mmio32read__read_file, mmio32read__write_file);
647 enabled = (dev->dfsentry && dev->dfsentry->dyn_debug[
feature]);
657 static void b43_remove_dynamic_debug(
struct b43_wldev *dev)
659 struct b43_dfsentry *
e = dev->dfsentry;
666 static void b43_add_dynamic_debug(
struct b43_wldev *dev)
668 struct b43_dfsentry *e = dev->dfsentry;
671 #define add_dyn_dbg(name, id, initstate) do { \
672 e->dyn_debug[id] = (initstate); \
673 d = debugfs_create_bool(name, 0600, e->subdir, \
674 &(e->dyn_debug[id])); \
676 e->dyn_debug_dentries[id] = d; \
694 struct b43_dfsentry *
e;
695 struct b43_txstatus_log *
log;
701 b43err(dev->
wl,
"debugfs: add device OOM\n");
706 log->log = kcalloc(B43_NR_LOGGED_TXSTATUS,
709 b43err(dev->
wl,
"debugfs: add device txstatus OOM\n");
717 snprintf(devdir,
sizeof(devdir),
"%s", wiphy_name(dev->
wl->hw->wiphy));
719 if (!e->subdir || IS_ERR(e->subdir)) {
720 if (e->subdir == ERR_PTR(-
ENODEV)) {
721 b43dbg(dev->
wl,
"DebugFS (CONFIG_DEBUG_FS) not "
722 "enabled in kernel config\n");
724 b43err(dev->
wl,
"debugfs: cannot create %s directory\n",
727 dev->dfsentry =
NULL;
733 e->mmio16read_next = 0xFFFF;
734 e->mmio32read_next = 0xFFFF;
735 e->shm16read_routing_next = 0xFFFFFFFF;
736 e->shm16read_addr_next = 0xFFFFFFFF;
737 e->shm32read_routing_next = 0xFFFFFFFF;
738 e->shm32read_addr_next = 0xFFFFFFFF;
740 #define ADD_FILE(name, mode) \
743 d = debugfs_create_file(__stringify(name), \
744 mode, e->subdir, dev, \
745 &fops_##name.fops); \
746 e->file_##name.dentry = NULL; \
748 e->file_##name.dentry = d; \
766 b43_add_dynamic_debug(dev);
771 struct b43_dfsentry *
e;
778 b43_remove_dynamic_debug(dev);
793 kfree(e->txstatlog.log);
800 struct b43_dfsentry *e = dev->dfsentry;
801 struct b43_txstatus_log *
log;
809 if (i == B43_NR_LOGGED_TXSTATUS)
812 cur = &(log->log[
i]);
813 memcpy(cur, status,
sizeof(*cur));