2 * Kernel CAPI 2.0 Module - /proc/capi handling
4 * Copyright 1999 by Carsten Paeth <calle@calle.de>
5 * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/init.h>
17 #include <linux/export.h>
19 static char *state2str(unsigned short state
)
22 case CAPI_CTR_DETECTED
: return "detected";
23 case CAPI_CTR_LOADING
: return "loading";
24 case CAPI_CTR_RUNNING
: return "running";
25 default: return "???";
30 // ===========================================================================
32 // /proc/capi/controller:
33 // cnr driver cardstate name driverinfo
34 // /proc/capi/contrstats:
35 // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
36 // ---------------------------------------------------------------------------
38 static void *controller_start(struct seq_file
*seq
, loff_t
*pos
)
39 __acquires(capi_controller_lock
)
41 mutex_lock(&capi_controller_lock
);
43 if (*pos
< CAPI_MAXCONTR
)
44 return &capi_controller
[*pos
];
49 static void *controller_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
52 if (*pos
< CAPI_MAXCONTR
)
53 return &capi_controller
[*pos
];
58 static void controller_stop(struct seq_file
*seq
, void *v
)
59 __releases(capi_controller_lock
)
61 mutex_unlock(&capi_controller_lock
);
64 static int controller_show(struct seq_file
*seq
, void *v
)
66 struct capi_ctr
*ctr
= *(struct capi_ctr
**) v
;
71 seq_printf(seq
, "%d %-10s %-8s %-16s %s\n",
72 ctr
->cnr
, ctr
->driver_name
,
73 state2str(ctr
->state
),
75 ctr
->procinfo
? ctr
->procinfo(ctr
) : "");
80 static int contrstats_show(struct seq_file
*seq
, void *v
)
82 struct capi_ctr
*ctr
= *(struct capi_ctr
**) v
;
87 seq_printf(seq
, "%d %lu %lu %lu %lu\n",
97 static const struct seq_operations seq_controller_ops
= {
98 .start
= controller_start
,
99 .next
= controller_next
,
100 .stop
= controller_stop
,
101 .show
= controller_show
,
104 static const struct seq_operations seq_contrstats_ops
= {
105 .start
= controller_start
,
106 .next
= controller_next
,
107 .stop
= controller_stop
,
108 .show
= contrstats_show
,
111 static int seq_controller_open(struct inode
*inode
, struct file
*file
)
113 return seq_open(file
, &seq_controller_ops
);
116 static int seq_contrstats_open(struct inode
*inode
, struct file
*file
)
118 return seq_open(file
, &seq_contrstats_ops
);
121 static const struct file_operations proc_controller_ops
= {
122 .owner
= THIS_MODULE
,
123 .open
= seq_controller_open
,
126 .release
= seq_release
,
129 static const struct file_operations proc_contrstats_ops
= {
130 .owner
= THIS_MODULE
,
131 .open
= seq_contrstats_open
,
134 .release
= seq_release
,
137 // /proc/capi/applications:
138 // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
139 // /proc/capi/applstats:
140 // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
141 // ---------------------------------------------------------------------------
143 static void *applications_start(struct seq_file
*seq
, loff_t
*pos
)
144 __acquires(capi_controller_lock
)
146 mutex_lock(&capi_controller_lock
);
148 if (*pos
< CAPI_MAXAPPL
)
149 return &capi_applications
[*pos
];
155 applications_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
158 if (*pos
< CAPI_MAXAPPL
)
159 return &capi_applications
[*pos
];
164 static void applications_stop(struct seq_file
*seq
, void *v
)
165 __releases(capi_controller_lock
)
167 mutex_unlock(&capi_controller_lock
);
171 applications_show(struct seq_file
*seq
, void *v
)
173 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
178 seq_printf(seq
, "%u %d %d %d\n",
180 ap
->rparam
.level3cnt
,
181 ap
->rparam
.datablkcnt
,
182 ap
->rparam
.datablklen
);
188 applstats_show(struct seq_file
*seq
, void *v
)
190 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
195 seq_printf(seq
, "%u %lu %lu %lu %lu\n",
205 static const struct seq_operations seq_applications_ops
= {
206 .start
= applications_start
,
207 .next
= applications_next
,
208 .stop
= applications_stop
,
209 .show
= applications_show
,
212 static const struct seq_operations seq_applstats_ops
= {
213 .start
= applications_start
,
214 .next
= applications_next
,
215 .stop
= applications_stop
,
216 .show
= applstats_show
,
220 seq_applications_open(struct inode
*inode
, struct file
*file
)
222 return seq_open(file
, &seq_applications_ops
);
226 seq_applstats_open(struct inode
*inode
, struct file
*file
)
228 return seq_open(file
, &seq_applstats_ops
);
231 static const struct file_operations proc_applications_ops
= {
232 .owner
= THIS_MODULE
,
233 .open
= seq_applications_open
,
236 .release
= seq_release
,
239 static const struct file_operations proc_applstats_ops
= {
240 .owner
= THIS_MODULE
,
241 .open
= seq_applstats_open
,
244 .release
= seq_release
,
247 // ---------------------------------------------------------------------------
249 static void *capi_driver_start(struct seq_file
*seq
, loff_t
*pos
)
250 __acquires(&capi_drivers_lock
)
252 mutex_lock(&capi_drivers_lock
);
253 return seq_list_start(&capi_drivers
, *pos
);
256 static void *capi_driver_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
258 return seq_list_next(v
, &capi_drivers
, pos
);
261 static void capi_driver_stop(struct seq_file
*seq
, void *v
)
262 __releases(&capi_drivers_lock
)
264 mutex_unlock(&capi_drivers_lock
);
267 static int capi_driver_show(struct seq_file
*seq
, void *v
)
269 struct capi_driver
*drv
= list_entry(v
, struct capi_driver
, list
);
271 seq_printf(seq
, "%-32s %s\n", drv
->name
, drv
->revision
);
275 static const struct seq_operations seq_capi_driver_ops
= {
276 .start
= capi_driver_start
,
277 .next
= capi_driver_next
,
278 .stop
= capi_driver_stop
,
279 .show
= capi_driver_show
,
283 seq_capi_driver_open(struct inode
*inode
, struct file
*file
)
286 err
= seq_open(file
, &seq_capi_driver_ops
);
290 static const struct file_operations proc_driver_ops
= {
291 .owner
= THIS_MODULE
,
292 .open
= seq_capi_driver_open
,
295 .release
= seq_release
,
298 // ---------------------------------------------------------------------------
301 kcapi_proc_init(void)
303 proc_mkdir("capi", NULL
);
304 proc_mkdir("capi/controllers", NULL
);
305 proc_create("capi/controller", 0, NULL
, &proc_controller_ops
);
306 proc_create("capi/contrstats", 0, NULL
, &proc_contrstats_ops
);
307 proc_create("capi/applications", 0, NULL
, &proc_applications_ops
);
308 proc_create("capi/applstats", 0, NULL
, &proc_applstats_ops
);
309 proc_create("capi/driver", 0, NULL
, &proc_driver_ops
);
313 kcapi_proc_exit(void)
315 remove_proc_entry("capi/driver", NULL
);
316 remove_proc_entry("capi/controller", NULL
);
317 remove_proc_entry("capi/contrstats", NULL
);
318 remove_proc_entry("capi/applications", NULL
);
319 remove_proc_entry("capi/applstats", NULL
);
320 remove_proc_entry("capi/controllers", NULL
);
321 remove_proc_entry("capi", NULL
);