83bd4b0e11b01743a1bb0bb0b0e4eee1d994af0f
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / drivers / net / ag71xx / ag71xx_debugfs.c
1 /*
2 * Atheros AR71xx built-in ethernet mac driver
3 *
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Based on Atheros' AG7100 driver
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14 #include <linux/debugfs.h>
15
16 #include "ag71xx.h"
17
18 static struct dentry *ag71xx_debugfs_root;
19
20 static int ag71xx_debugfs_generic_open(struct inode *inode, struct file *file)
21 {
22 file->private_data = inode->i_private;
23 return 0;
24 }
25
26 void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status)
27 {
28 if (status)
29 ag->debug.int_stats.total++;
30 if (status & AG71XX_INT_TX_PS)
31 ag->debug.int_stats.tx_ps++;
32 if (status & AG71XX_INT_TX_UR)
33 ag->debug.int_stats.tx_ur++;
34 if (status & AG71XX_INT_TX_BE)
35 ag->debug.int_stats.tx_be++;
36 if (status & AG71XX_INT_RX_PR)
37 ag->debug.int_stats.rx_pr++;
38 if (status & AG71XX_INT_RX_OF)
39 ag->debug.int_stats.rx_of++;
40 if (status & AG71XX_INT_RX_BE)
41 ag->debug.int_stats.rx_be++;
42 }
43
44 static ssize_t read_file_int_stats(struct file *file, char __user *user_buf,
45 size_t count, loff_t *ppos)
46 {
47 #define PR_INT_STAT(_label, _field) \
48 len += snprintf(buf + len, sizeof(buf) - len, \
49 "%20s: %10lu\n", _label, ag->debug.int_stats._field);
50
51 struct ag71xx *ag = file->private_data;
52 char buf[256];
53 unsigned int len = 0;
54
55 PR_INT_STAT("TX Packet Sent", tx_ps);
56 PR_INT_STAT("TX Underrun", tx_ur);
57 PR_INT_STAT("TX Bus Error", tx_be);
58 PR_INT_STAT("RX Packet Received", rx_pr);
59 PR_INT_STAT("RX Overflow", rx_of);
60 PR_INT_STAT("RX Bus Error", rx_be);
61 len += snprintf(buf + len, sizeof(buf) - len, "\n");
62 PR_INT_STAT("Total", total);
63
64 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
65 #undef PR_INT_STAT
66 }
67
68 static const struct file_operations ag71xx_fops_int_stats = {
69 .open = ag71xx_debugfs_generic_open,
70 .read = read_file_int_stats,
71 .owner = THIS_MODULE
72 };
73
74 void ag71xx_debugfs_exit(struct ag71xx *ag)
75 {
76 debugfs_remove(ag->debug.debugfs_int_stats);
77 debugfs_remove(ag->debug.debugfs_dir);
78 }
79
80 int ag71xx_debugfs_init(struct ag71xx *ag)
81 {
82 ag->debug.debugfs_dir = debugfs_create_dir(ag->dev->name,
83 ag71xx_debugfs_root);
84 if (!ag->debug.debugfs_dir)
85 goto err;
86
87 ag->debug.debugfs_int_stats =
88 debugfs_create_file("int_stats",
89 S_IRUGO,
90 ag->debug.debugfs_dir,
91 ag,
92 &ag71xx_fops_int_stats);
93 if (!ag->debug.debugfs_int_stats)
94 goto err;
95
96 return 0;
97
98 err:
99 ag71xx_debugfs_exit(ag);
100 return -ENOMEM;
101 }
102
103 int ag71xx_debugfs_root_init(void)
104 {
105 if (ag71xx_debugfs_root)
106 return -EBUSY;
107
108 ag71xx_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
109 if (!ag71xx_debugfs_root)
110 return -ENOENT;
111
112 return 0;
113 }
114
115 void ag71xx_debugfs_root_exit(void)
116 {
117 debugfs_remove(ag71xx_debugfs_root);
118 ag71xx_debugfs_root = NULL;
119 }