Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / sfc_netback / accel_debugfs.c
1 /****************************************************************************
2  * Solarflare driver for Xen network acceleration
3  *
4  * Copyright 2006-2008: Solarflare Communications Inc,
5  *                      9501 Jeronimo Road, Suite 250,
6  *                      Irvine, CA 92618, USA
7  *
8  * Maintained by Solarflare Communications <linux-xen-drivers@solarflare.com>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License version 2 as published
12  * by the Free Software Foundation, incorporated herein by reference.
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; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  ****************************************************************************
23  */
24
25 #include <linux/fs.h>
26 #include <linux/debugfs.h>
27
28 #include "accel.h"
29
30 #if defined(CONFIG_DEBUG_FS)
31 static struct dentry *sfc_debugfs_root = NULL;
32 #endif
33
34 #if NETBACK_ACCEL_STATS
35 struct netback_accel_global_stats global_stats;
36 #if defined(CONFIG_DEBUG_FS)
37 static struct netback_accel_global_dbfs  global_dbfs;
38 #endif
39 #endif
40
41 void netback_accel_debugfs_init(void) 
42 {
43 #if defined(CONFIG_DEBUG_FS)
44         sfc_debugfs_root = debugfs_create_dir("sfc_netback", NULL);
45         if (sfc_debugfs_root == NULL)
46                 return;
47
48         global_dbfs.num_fwds = debugfs_create_u32
49                 ("num_fwds", S_IRUSR | S_IRGRP | S_IROTH,
50                  sfc_debugfs_root, &global_stats.num_fwds);
51         global_dbfs.dl_tx_packets = debugfs_create_u64
52                 ("dl_tx_packets", S_IRUSR | S_IRGRP | S_IROTH,
53                  sfc_debugfs_root, &global_stats.dl_tx_packets);
54         global_dbfs.dl_rx_packets = debugfs_create_u64
55                 ("dl_rx_packets", S_IRUSR | S_IRGRP | S_IROTH,
56                  sfc_debugfs_root, &global_stats.dl_rx_packets);
57         global_dbfs.dl_tx_bad_packets = debugfs_create_u64
58                 ("dl_tx_bad_packets", S_IRUSR | S_IRGRP | S_IROTH,
59                  sfc_debugfs_root, &global_stats.dl_tx_bad_packets);
60 #endif
61 }
62
63
64 void netback_accel_debugfs_fini(void)
65 {
66 #if defined(CONFIG_DEBUG_FS)
67         debugfs_remove(global_dbfs.num_fwds);
68         debugfs_remove(global_dbfs.dl_tx_packets);
69         debugfs_remove(global_dbfs.dl_rx_packets);
70         debugfs_remove(global_dbfs.dl_tx_bad_packets);
71
72         debugfs_remove(sfc_debugfs_root);
73 #endif
74 }
75
76
77 int netback_accel_debugfs_create(struct netback_accel *bend)
78 {
79 #if defined(CONFIG_DEBUG_FS)
80         /* Smallest length is 7 (vif0.0\n) */
81         int length = 7, temp;
82
83         if (sfc_debugfs_root == NULL)
84                 return -ENOENT;
85
86         /* Work out length of string representation of far_end and vif_num */
87         temp = bend->far_end;
88         while (temp > 9) {
89                 length++;
90                 temp = temp / 10;
91         }
92         temp = bend->vif_num;
93         while (temp > 9) {
94                 length++;
95                 temp = temp / 10;
96         }
97
98         bend->dbfs_dir_name = kmalloc(length, GFP_KERNEL);
99         if (bend->dbfs_dir_name == NULL)
100                 return -ENOMEM;
101         sprintf(bend->dbfs_dir_name, "vif%d.%d", bend->far_end, bend->vif_num);
102
103         bend->dbfs_dir = debugfs_create_dir(bend->dbfs_dir_name, 
104                                             sfc_debugfs_root);
105         if (bend->dbfs_dir == NULL) {
106                 kfree(bend->dbfs_dir_name);
107                 return -ENOMEM;
108         }
109
110 #if NETBACK_ACCEL_STATS
111         bend->dbfs.evq_wakeups = debugfs_create_u64
112                 ("evq_wakeups", S_IRUSR | S_IRGRP | S_IROTH,
113                  bend->dbfs_dir, &bend->stats.evq_wakeups);
114         bend->dbfs.evq_timeouts = debugfs_create_u64
115                 ("evq_timeouts", S_IRUSR | S_IRGRP | S_IROTH,
116                  bend->dbfs_dir, &bend->stats.evq_timeouts);
117         bend->dbfs.num_filters = debugfs_create_u32
118                 ("num_filters", S_IRUSR | S_IRGRP | S_IROTH,
119                  bend->dbfs_dir, &bend->stats.num_filters);
120         bend->dbfs.num_buffer_pages = debugfs_create_u32
121                 ("num_buffer_pages", S_IRUSR | S_IRGRP | S_IROTH,
122                  bend->dbfs_dir, &bend->stats.num_buffer_pages);
123 #endif
124 #endif
125         return 0;
126 }
127
128
129 int netback_accel_debugfs_remove(struct netback_accel *bend)
130 {
131 #if defined(CONFIG_DEBUG_FS)
132         if (bend->dbfs_dir != NULL) {
133 #if NETBACK_ACCEL_STATS
134                 debugfs_remove(bend->dbfs.evq_wakeups);
135                 debugfs_remove(bend->dbfs.evq_timeouts);
136                 debugfs_remove(bend->dbfs.num_filters);
137                 debugfs_remove(bend->dbfs.num_buffer_pages);
138 #endif
139                 debugfs_remove(bend->dbfs_dir);
140         }
141
142         if (bend->dbfs_dir_name)
143                 kfree(bend->dbfs_dir_name);
144 #endif
145         return 0;
146 }
147
148