aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2006-01-23 16:59:58 -0500
committerJohn W. Linville <linville@tuxdriver.com>2006-03-27 11:18:23 -0500
commitf222313a61a5e134de80767b35c672b91e78383c (patch)
treec3a8dca8a021bd88f58112e70ce52cfb28e99ff1 /drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
parent5d5d7727a8cde78f798ecf04bac8031eff536f9d (diff)
[PATCH] wireless: import bcm43xx sources
Import the bcm43xx driver from the upstream sources here: ftp://ftp.berlios.de/pub/bcm43xx/snapshots/bcm43xx/bcm43xx-20060123.tar.bz2 Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c')
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c503
1 files changed, 503 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
new file mode 100644
index 000000000000..f8cfc84ca0da
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
@@ -0,0 +1,503 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 debugfs driver debugging code
6
7 Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
8
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.
13
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.
18
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.
23
24*/
25
26
27
28#include <linux/fs.h>
29#include <linux/debugfs.h>
30#include <linux/slab.h>
31#include <linux/netdevice.h>
32#include <linux/pci.h>
33#include <asm/io.h>
34
35#include "bcm43xx.h"
36#include "bcm43xx_main.h"
37#include "bcm43xx_debugfs.h"
38#include "bcm43xx_dma.h"
39#include "bcm43xx_pio.h"
40
41#define REALLY_BIG_BUFFER_SIZE (1024*256)
42
43static struct bcm43xx_debugfs fs;
44static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
45static DECLARE_MUTEX(big_buffer_sem);
46
47
48static ssize_t write_file_dummy(struct file *file, const char __user *buf,
49 size_t count, loff_t *ppos)
50{
51 return count;
52}
53
54static int open_file_generic(struct inode *inode, struct file *file)
55{
56 file->private_data = inode->u.generic_ip;
57 return 0;
58}
59
60#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
61
62static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
63 size_t count, loff_t *ppos)
64{
65 const size_t len = REALLY_BIG_BUFFER_SIZE;
66
67 struct bcm43xx_private *bcm = file->private_data;
68 char *buf = really_big_buffer;
69 size_t pos = 0;
70 ssize_t res;
71 struct net_device *net_dev;
72 struct pci_dev *pci_dev;
73 unsigned long flags;
74 u16 tmp16;
75 int i;
76
77 down(&big_buffer_sem);
78
79 spin_lock_irqsave(&bcm->lock, flags);
80 if (!bcm->initialized) {
81 fappend("Board not initialized.\n");
82 goto out;
83 }
84 net_dev = bcm->net_dev;
85 pci_dev = bcm->pci_dev;
86
87 /* This is where the information is written to the "devinfo" file */
88 fappend("*** %s devinfo ***\n", net_dev->name);
89 fappend("vendor: 0x%04x device: 0x%04x\n",
90 pci_dev->vendor, pci_dev->device);
91 fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
92 pci_dev->subsystem_vendor, pci_dev->subsystem_device);
93 fappend("IRQ: %d\n", bcm->irq);
94 fappend("mmio_addr: 0x%p mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
95 fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
96 if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
97 fappend("Radio disabled by hardware!\n");
98 if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
99 fappend("Radio disabled by hardware!\n");
100 fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm->board_vendor,
101 bcm->board_type);
102
103 fappend("\nCores:\n");
104#define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
105 "rev: 0x%02x, index: 0x%02x\n", \
106 (info).flags & BCM43xx_COREFLAG_AVAILABLE \
107 ? "available" : "nonavailable", \
108 (info).flags & BCM43xx_COREFLAG_ENABLED \
109 ? "enabled" : "disabled", \
110 (info).id, (info).rev, (info).index)
111 fappend_core("CHIPCOMMON", bcm->core_chipcommon);
112 fappend_core("PCI", bcm->core_pci);
113 fappend_core("V90", bcm->core_v90);
114 fappend_core("PCMCIA", bcm->core_pcmcia);
115 fappend_core("ETHERNET", bcm->core_ethernet);
116 fappend_core("first 80211", bcm->core_80211[0]);
117 fappend_core("second 80211", bcm->core_80211[1]);
118#undef fappend_core
119 tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
120 fappend("LEDs: ");
121 for (i = 0; i < BCM43xx_NR_LEDS; i++)
122 fappend("%d ", !!(tmp16 & (1 << i)));
123 fappend("\n");
124
125out:
126 spin_unlock_irqrestore(&bcm->lock, flags);
127 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
128 up(&big_buffer_sem);
129 return res;
130}
131
132static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
133 size_t count, loff_t *ppos)
134{
135 const size_t len = REALLY_BIG_BUFFER_SIZE;
136
137 char *buf = really_big_buffer;
138 size_t pos = 0;
139 ssize_t res;
140
141 down(&big_buffer_sem);
142
143 /* This is where the information is written to the "driver" file */
144 fappend(BCM43xx_DRIVER_NAME "\n");
145 fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
146
147 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
148 up(&big_buffer_sem);
149 return res;
150}
151
152static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
153 size_t count, loff_t *ppos)
154{
155 const size_t len = REALLY_BIG_BUFFER_SIZE;
156
157 struct bcm43xx_private *bcm = file->private_data;
158 char *buf = really_big_buffer;
159 size_t pos = 0;
160 ssize_t res;
161 unsigned long flags;
162
163 down(&big_buffer_sem);
164 spin_lock_irqsave(&bcm->lock, flags);
165 if (!bcm->initialized) {
166 fappend("Board not initialized.\n");
167 goto out;
168 }
169
170 /* This is where the information is written to the "sprom_dump" file */
171 fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
172
173out:
174 spin_unlock_irqrestore(&bcm->lock, flags);
175 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
176 up(&big_buffer_sem);
177 return res;
178}
179
180static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
181 size_t count, loff_t *ppos)
182{
183 const size_t len = REALLY_BIG_BUFFER_SIZE;
184
185 struct bcm43xx_private *bcm = file->private_data;
186 char *buf = really_big_buffer;
187 size_t pos = 0;
188 ssize_t res;
189 unsigned long flags;
190 u64 tsf;
191
192 down(&big_buffer_sem);
193 spin_lock_irqsave(&bcm->lock, flags);
194 if (!bcm->initialized) {
195 fappend("Board not initialized.\n");
196 goto out;
197 }
198 bcm43xx_tsf_read(bcm, &tsf);
199 fappend("0x%08x%08x\n",
200 (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
201 (unsigned int)(tsf & 0xFFFFFFFFULL));
202
203out:
204 spin_unlock_irqrestore(&bcm->lock, flags);
205 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
206 up(&big_buffer_sem);
207 return res;
208}
209
210static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
211 size_t count, loff_t *ppos)
212{
213 struct bcm43xx_private *bcm = file->private_data;
214 char *buf = really_big_buffer;
215 ssize_t buf_size;
216 ssize_t res;
217 unsigned long flags;
218 u64 tsf;
219
220 buf_size = min(count, sizeof (really_big_buffer) - 1);
221 down(&big_buffer_sem);
222 if (copy_from_user(buf, user_buf, buf_size)) {
223 res = -EFAULT;
224 goto out_up;
225 }
226 spin_lock_irqsave(&bcm->lock, flags);
227 if (!bcm->initialized) {
228 printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
229 res = -EFAULT;
230 goto out_unlock;
231 }
232 if (sscanf(buf, "%lli", &tsf) != 1) {
233 printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
234 res = -EINVAL;
235 goto out_unlock;
236 }
237 bcm43xx_tsf_write(bcm, tsf);
238 res = buf_size;
239
240out_unlock:
241 spin_unlock_irqrestore(&bcm->lock, flags);
242out_up:
243 up(&big_buffer_sem);
244 return res;
245}
246
247static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
248 size_t count, loff_t *ppos)
249{
250 const size_t len = REALLY_BIG_BUFFER_SIZE;
251
252 struct bcm43xx_private *bcm = file->private_data;
253 char *buf = really_big_buffer;
254 size_t pos = 0;
255 ssize_t res;
256 unsigned long flags;
257 struct bcm43xx_dfsentry *e;
258 struct bcm43xx_xmitstatus *status;
259 int i, cnt, j = 0;
260
261 down(&big_buffer_sem);
262 spin_lock_irqsave(&bcm->lock, flags);
263
264 fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
265 BCM43xx_NR_LOGGED_XMITSTATUS);
266 e = bcm->dfsentry;
267 if (e->xmitstatus_printing == 0) {
268 /* At the beginning, make a copy of all data to avoid
269 * concurrency, as this function is called multiple
270 * times for big logs. Without copying, the data might
271 * change between reads. This would result in total trash.
272 */
273 e->xmitstatus_printing = 1;
274 e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
275 e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
276 memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
277 BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
278 }
279 i = e->saved_xmitstatus_ptr - 1;
280 if (i < 0)
281 i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
282 cnt = e->saved_xmitstatus_cnt;
283 while (cnt) {
284 status = e->xmitstatus_print_buffer + i;
285 fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
286 "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
287 "unk: 0x%04x\n", j,
288 status->cookie, status->flags,
289 status->cnt1, status->cnt2, status->seq,
290 status->unknown);
291 j++;
292 cnt--;
293 i--;
294 if (i < 0)
295 i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
296 }
297
298 spin_unlock_irqrestore(&bcm->lock, flags);
299 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
300 spin_lock_irqsave(&bcm->lock, flags);
301 if (*ppos == pos) {
302 /* Done. Drop the copied data. */
303 e->xmitstatus_printing = 0;
304 }
305 spin_unlock_irqrestore(&bcm->lock, flags);
306 up(&big_buffer_sem);
307 return res;
308}
309
310#undef fappend
311
312
313static struct file_operations devinfo_fops = {
314 .read = devinfo_read_file,
315 .write = write_file_dummy,
316 .open = open_file_generic,
317};
318
319static struct file_operations spromdump_fops = {
320 .read = spromdump_read_file,
321 .write = write_file_dummy,
322 .open = open_file_generic,
323};
324
325static struct file_operations drvinfo_fops = {
326 .read = drvinfo_read_file,
327 .write = write_file_dummy,
328 .open = open_file_generic,
329};
330
331static struct file_operations tsf_fops = {
332 .read = tsf_read_file,
333 .write = tsf_write_file,
334 .open = open_file_generic,
335};
336
337static struct file_operations txstat_fops = {
338 .read = txstat_read_file,
339 .write = write_file_dummy,
340 .open = open_file_generic,
341};
342
343
344void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
345{
346 struct bcm43xx_dfsentry *e;
347 char devdir[IFNAMSIZ];
348
349 assert(bcm);
350 e = kzalloc(sizeof(*e), GFP_KERNEL);
351 if (!e) {
352 printk(KERN_ERR PFX "out of memory\n");
353 return;
354 }
355 e->bcm = bcm;
356 e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
357 * sizeof(*(e->xmitstatus_buffer)),
358 GFP_KERNEL);
359 if (!e->xmitstatus_buffer) {
360 printk(KERN_ERR PFX "out of memory\n");
361 kfree(e);
362 return;
363 }
364 e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
365 * sizeof(*(e->xmitstatus_buffer)),
366 GFP_KERNEL);
367 if (!e->xmitstatus_print_buffer) {
368 printk(KERN_ERR PFX "out of memory\n");
369 kfree(e);
370 return;
371 }
372
373
374 bcm->dfsentry = e;
375
376 strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
377 e->subdir = debugfs_create_dir(devdir, fs.root);
378 e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
379 bcm, &devinfo_fops);
380 if (!e->dentry_devinfo)
381 printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
382 e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
383 bcm, &spromdump_fops);
384 if (!e->dentry_spromdump)
385 printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
386 e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
387 bcm, &tsf_fops);
388 if (!e->dentry_tsf)
389 printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
390 e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
391 bcm, &txstat_fops);
392 if (!e->dentry_txstat)
393 printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
394}
395
396void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
397{
398 struct bcm43xx_dfsentry *e;
399
400 if (!bcm)
401 return;
402
403 e = bcm->dfsentry;
404 assert(e);
405 debugfs_remove(e->dentry_spromdump);
406 debugfs_remove(e->dentry_devinfo);
407 debugfs_remove(e->dentry_tsf);
408 debugfs_remove(e->dentry_txstat);
409 debugfs_remove(e->subdir);
410 kfree(e->xmitstatus_buffer);
411 kfree(e->xmitstatus_print_buffer);
412 kfree(e);
413}
414
415void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
416 struct bcm43xx_xmitstatus *status)
417{
418 struct bcm43xx_dfsentry *e;
419 struct bcm43xx_xmitstatus *savedstatus;
420
421 /* This is protected by bcm->lock */
422 e = bcm->dfsentry;
423 assert(e);
424 savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
425 memcpy(savedstatus, status, sizeof(*status));
426 e->xmitstatus_ptr++;
427 if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
428 e->xmitstatus_ptr = 0;
429 if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
430 e->xmitstatus_cnt++;
431}
432
433void bcm43xx_debugfs_init(void)
434{
435 memset(&fs, 0, sizeof(fs));
436 fs.root = debugfs_create_dir(DRV_NAME, NULL);
437 if (!fs.root)
438 printk(KERN_ERR PFX "debugfs: creating \"" DRV_NAME "\" subdir failed!\n");
439 fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
440 if (!fs.dentry_driverinfo)
441 printk(KERN_ERR PFX "debugfs: creating \"" DRV_NAME "/driver\" failed!\n");
442}
443
444void bcm43xx_debugfs_exit(void)
445{
446 debugfs_remove(fs.dentry_driverinfo);
447 debugfs_remove(fs.root);
448}
449
450void bcm43xx_printk_dump(const char *data,
451 size_t size,
452 const char *description)
453{
454 size_t i;
455 char c;
456
457 printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
458 description, size);
459 for (i = 0; i < size; i++) {
460 c = data[i];
461 if (i % 8 == 0)
462 printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
463 else
464 printk("0x%02x, ", c & 0xff);
465 }
466 printk("\n");
467}
468
469void bcm43xx_printk_bitdump(const unsigned char *data,
470 size_t bytes, int msb_to_lsb,
471 const char *description)
472{
473 size_t i;
474 int j;
475 const unsigned char *d;
476
477 printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
478 description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
479 for (i = 0; i < bytes; i++) {
480 d = data + i;
481 if (i % 8 == 0)
482 printk("\n" KERN_INFO PFX "0x%08x: ", i);
483 if (msb_to_lsb) {
484 for (j = 7; j >= 0; j--) {
485 if (*d & (1 << j))
486 printk("1");
487 else
488 printk("0");
489 }
490 } else {
491 for (j = 0; j < 8; j++) {
492 if (*d & (1 << j))
493 printk("1");
494 else
495 printk("0");
496 }
497 }
498 printk(" ");
499 }
500 printk("\n");
501}
502
503/* vim: set ts=8 sw=8 sts=8: */