CAPI: Convert capi drivers rwlock into mutex
[linux-2.6/kvm.git] / drivers / isdn / capi / kcapi_proc.c
blob71b07610ff311b74a6a819a5d8980d759b210b59
1 /*
2 * Kernel CAPI 2.0 Module - /proc/capi handling
3 *
4 * Copyright 1999 by Carsten Paeth <calle@calle.de>
5 * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
13 #include "kcapi.h"
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/init.h>
18 static char *state2str(unsigned short state)
20 switch (state) {
21 case CAPI_CTR_DETECTED: return "detected";
22 case CAPI_CTR_LOADING: return "loading";
23 case CAPI_CTR_RUNNING: return "running";
24 default: return "???";
28 // /proc/capi
29 // ===========================================================================
31 // /proc/capi/controller:
32 // cnr driver cardstate name driverinfo
33 // /proc/capi/contrstats:
34 // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
35 // ---------------------------------------------------------------------------
37 static void *controller_start(struct seq_file *seq, loff_t *pos)
39 if (*pos < CAPI_MAXCONTR)
40 return &capi_controller[*pos];
42 return NULL;
45 static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
47 ++*pos;
48 if (*pos < CAPI_MAXCONTR)
49 return &capi_controller[*pos];
51 return NULL;
54 static void controller_stop(struct seq_file *seq, void *v)
58 static int controller_show(struct seq_file *seq, void *v)
60 struct capi_ctr *ctr = *(struct capi_ctr **) v;
62 if (!ctr)
63 return 0;
65 seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
66 ctr->cnr, ctr->driver_name,
67 state2str(ctr->state),
68 ctr->name,
69 ctr->procinfo ? ctr->procinfo(ctr) : "");
71 return 0;
74 static int contrstats_show(struct seq_file *seq, void *v)
76 struct capi_ctr *ctr = *(struct capi_ctr **) v;
78 if (!ctr)
79 return 0;
81 seq_printf(seq, "%d %lu %lu %lu %lu\n",
82 ctr->cnr,
83 ctr->nrecvctlpkt,
84 ctr->nrecvdatapkt,
85 ctr->nsentctlpkt,
86 ctr->nsentdatapkt);
88 return 0;
91 static const struct seq_operations seq_controller_ops = {
92 .start = controller_start,
93 .next = controller_next,
94 .stop = controller_stop,
95 .show = controller_show,
98 static const struct seq_operations seq_contrstats_ops = {
99 .start = controller_start,
100 .next = controller_next,
101 .stop = controller_stop,
102 .show = contrstats_show,
105 static int seq_controller_open(struct inode *inode, struct file *file)
107 return seq_open(file, &seq_controller_ops);
110 static int seq_contrstats_open(struct inode *inode, struct file *file)
112 return seq_open(file, &seq_contrstats_ops);
115 static const struct file_operations proc_controller_ops = {
116 .owner = THIS_MODULE,
117 .open = seq_controller_open,
118 .read = seq_read,
119 .llseek = seq_lseek,
120 .release = seq_release,
123 static const struct file_operations proc_contrstats_ops = {
124 .owner = THIS_MODULE,
125 .open = seq_contrstats_open,
126 .read = seq_read,
127 .llseek = seq_lseek,
128 .release = seq_release,
131 // /proc/capi/applications:
132 // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
133 // /proc/capi/applstats:
134 // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
135 // ---------------------------------------------------------------------------
137 static void *
138 applications_start(struct seq_file *seq, loff_t *pos)
140 if (*pos < CAPI_MAXAPPL)
141 return &capi_applications[*pos];
143 return NULL;
146 static void *
147 applications_next(struct seq_file *seq, void *v, loff_t *pos)
149 ++*pos;
150 if (*pos < CAPI_MAXAPPL)
151 return &capi_applications[*pos];
153 return NULL;
156 static void
157 applications_stop(struct seq_file *seq, void *v)
161 static int
162 applications_show(struct seq_file *seq, void *v)
164 struct capi20_appl *ap = *(struct capi20_appl **) v;
166 if (!ap)
167 return 0;
169 seq_printf(seq, "%u %d %d %d\n",
170 ap->applid,
171 ap->rparam.level3cnt,
172 ap->rparam.datablkcnt,
173 ap->rparam.datablklen);
175 return 0;
178 static int
179 applstats_show(struct seq_file *seq, void *v)
181 struct capi20_appl *ap = *(struct capi20_appl **) v;
183 if (!ap)
184 return 0;
186 seq_printf(seq, "%u %lu %lu %lu %lu\n",
187 ap->applid,
188 ap->nrecvctlpkt,
189 ap->nrecvdatapkt,
190 ap->nsentctlpkt,
191 ap->nsentdatapkt);
193 return 0;
196 static const struct seq_operations seq_applications_ops = {
197 .start = applications_start,
198 .next = applications_next,
199 .stop = applications_stop,
200 .show = applications_show,
203 static const struct seq_operations seq_applstats_ops = {
204 .start = applications_start,
205 .next = applications_next,
206 .stop = applications_stop,
207 .show = applstats_show,
210 static int
211 seq_applications_open(struct inode *inode, struct file *file)
213 return seq_open(file, &seq_applications_ops);
216 static int
217 seq_applstats_open(struct inode *inode, struct file *file)
219 return seq_open(file, &seq_applstats_ops);
222 static const struct file_operations proc_applications_ops = {
223 .owner = THIS_MODULE,
224 .open = seq_applications_open,
225 .read = seq_read,
226 .llseek = seq_lseek,
227 .release = seq_release,
230 static const struct file_operations proc_applstats_ops = {
231 .owner = THIS_MODULE,
232 .open = seq_applstats_open,
233 .read = seq_read,
234 .llseek = seq_lseek,
235 .release = seq_release,
238 // ---------------------------------------------------------------------------
240 static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
241 __acquires(&capi_drivers_lock)
243 mutex_lock(&capi_drivers_lock);
244 return seq_list_start(&capi_drivers, *pos);
247 static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
249 return seq_list_next(v, &capi_drivers, pos);
252 static void capi_driver_stop(struct seq_file *seq, void *v)
253 __releases(&capi_drivers_lock)
255 mutex_unlock(&capi_drivers_lock);
258 static int capi_driver_show(struct seq_file *seq, void *v)
260 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
262 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
263 return 0;
266 static const struct seq_operations seq_capi_driver_ops = {
267 .start = capi_driver_start,
268 .next = capi_driver_next,
269 .stop = capi_driver_stop,
270 .show = capi_driver_show,
273 static int
274 seq_capi_driver_open(struct inode *inode, struct file *file)
276 int err;
277 err = seq_open(file, &seq_capi_driver_ops);
278 return err;
281 static const struct file_operations proc_driver_ops = {
282 .owner = THIS_MODULE,
283 .open = seq_capi_driver_open,
284 .read = seq_read,
285 .llseek = seq_lseek,
286 .release = seq_release,
289 // ---------------------------------------------------------------------------
291 void __init
292 kcapi_proc_init(void)
294 proc_mkdir("capi", NULL);
295 proc_mkdir("capi/controllers", NULL);
296 proc_create("capi/controller", 0, NULL, &proc_controller_ops);
297 proc_create("capi/contrstats", 0, NULL, &proc_contrstats_ops);
298 proc_create("capi/applications", 0, NULL, &proc_applications_ops);
299 proc_create("capi/applstats", 0, NULL, &proc_applstats_ops);
300 proc_create("capi/driver", 0, NULL, &proc_driver_ops);
303 void __exit
304 kcapi_proc_exit(void)
306 remove_proc_entry("capi/driver", NULL);
307 remove_proc_entry("capi/controller", NULL);
308 remove_proc_entry("capi/contrstats", NULL);
309 remove_proc_entry("capi/applications", NULL);
310 remove_proc_entry("capi/applstats", NULL);
311 remove_proc_entry("capi/controllers", NULL);
312 remove_proc_entry("capi", NULL);