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>
18 static char *state2str(unsigned short 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 "???";
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
)
38 __acquires(capi_controller_lock
)
40 mutex_lock(&capi_controller_lock
);
42 if (*pos
< CAPI_MAXCONTR
)
43 return &capi_controller
[*pos
];
48 static void *controller_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
51 if (*pos
< CAPI_MAXCONTR
)
52 return &capi_controller
[*pos
];
57 static void controller_stop(struct seq_file
*seq
, void *v
)
58 __releases(capi_controller_lock
)
60 mutex_unlock(&capi_controller_lock
);
63 static int controller_show(struct seq_file
*seq
, void *v
)
65 struct capi_ctr
*ctr
= *(struct capi_ctr
**) v
;
70 seq_printf(seq
, "%d %-10s %-8s %-16s %s\n",
71 ctr
->cnr
, ctr
->driver_name
,
72 state2str(ctr
->state
),
74 ctr
->procinfo
? ctr
->procinfo(ctr
) : "");
79 static int contrstats_show(struct seq_file
*seq
, void *v
)
81 struct capi_ctr
*ctr
= *(struct capi_ctr
**) v
;
86 seq_printf(seq
, "%d %lu %lu %lu %lu\n",
96 static const struct seq_operations seq_controller_ops
= {
97 .start
= controller_start
,
98 .next
= controller_next
,
99 .stop
= controller_stop
,
100 .show
= controller_show
,
103 static const struct seq_operations seq_contrstats_ops
= {
104 .start
= controller_start
,
105 .next
= controller_next
,
106 .stop
= controller_stop
,
107 .show
= contrstats_show
,
110 static int seq_controller_open(struct inode
*inode
, struct file
*file
)
112 return seq_open(file
, &seq_controller_ops
);
115 static int seq_contrstats_open(struct inode
*inode
, struct file
*file
)
117 return seq_open(file
, &seq_contrstats_ops
);
120 static const struct file_operations proc_controller_ops
= {
121 .owner
= THIS_MODULE
,
122 .open
= seq_controller_open
,
125 .release
= seq_release
,
128 static const struct file_operations proc_contrstats_ops
= {
129 .owner
= THIS_MODULE
,
130 .open
= seq_contrstats_open
,
133 .release
= seq_release
,
136 // /proc/capi/applications:
137 // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
138 // /proc/capi/applstats:
139 // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
140 // ---------------------------------------------------------------------------
142 static void *applications_start(struct seq_file
*seq
, loff_t
*pos
)
143 __acquires(capi_controller_lock
)
145 mutex_lock(&capi_controller_lock
);
147 if (*pos
< CAPI_MAXAPPL
)
148 return &capi_applications
[*pos
];
154 applications_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
157 if (*pos
< CAPI_MAXAPPL
)
158 return &capi_applications
[*pos
];
163 static void applications_stop(struct seq_file
*seq
, void *v
)
164 __releases(capi_controller_lock
)
166 mutex_unlock(&capi_controller_lock
);
170 applications_show(struct seq_file
*seq
, void *v
)
172 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
177 seq_printf(seq
, "%u %d %d %d\n",
179 ap
->rparam
.level3cnt
,
180 ap
->rparam
.datablkcnt
,
181 ap
->rparam
.datablklen
);
187 applstats_show(struct seq_file
*seq
, void *v
)
189 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
194 seq_printf(seq
, "%u %lu %lu %lu %lu\n",
204 static const struct seq_operations seq_applications_ops
= {
205 .start
= applications_start
,
206 .next
= applications_next
,
207 .stop
= applications_stop
,
208 .show
= applications_show
,
211 static const struct seq_operations seq_applstats_ops
= {
212 .start
= applications_start
,
213 .next
= applications_next
,
214 .stop
= applications_stop
,
215 .show
= applstats_show
,
219 seq_applications_open(struct inode
*inode
, struct file
*file
)
221 return seq_open(file
, &seq_applications_ops
);
225 seq_applstats_open(struct inode
*inode
, struct file
*file
)
227 return seq_open(file
, &seq_applstats_ops
);
230 static const struct file_operations proc_applications_ops
= {
231 .owner
= THIS_MODULE
,
232 .open
= seq_applications_open
,
235 .release
= seq_release
,
238 static const struct file_operations proc_applstats_ops
= {
239 .owner
= THIS_MODULE
,
240 .open
= seq_applstats_open
,
243 .release
= seq_release
,
246 // ---------------------------------------------------------------------------
248 static void *capi_driver_start(struct seq_file
*seq
, loff_t
*pos
)
249 __acquires(&capi_drivers_lock
)
251 mutex_lock(&capi_drivers_lock
);
252 return seq_list_start(&capi_drivers
, *pos
);
255 static void *capi_driver_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
257 return seq_list_next(v
, &capi_drivers
, pos
);
260 static void capi_driver_stop(struct seq_file
*seq
, void *v
)
261 __releases(&capi_drivers_lock
)
263 mutex_unlock(&capi_drivers_lock
);
266 static int capi_driver_show(struct seq_file
*seq
, void *v
)
268 struct capi_driver
*drv
= list_entry(v
, struct capi_driver
, list
);
270 seq_printf(seq
, "%-32s %s\n", drv
->name
, drv
->revision
);
274 static const struct seq_operations seq_capi_driver_ops
= {
275 .start
= capi_driver_start
,
276 .next
= capi_driver_next
,
277 .stop
= capi_driver_stop
,
278 .show
= capi_driver_show
,
282 seq_capi_driver_open(struct inode
*inode
, struct file
*file
)
285 err
= seq_open(file
, &seq_capi_driver_ops
);
289 static const struct file_operations proc_driver_ops
= {
290 .owner
= THIS_MODULE
,
291 .open
= seq_capi_driver_open
,
294 .release
= seq_release
,
297 // ---------------------------------------------------------------------------
300 kcapi_proc_init(void)
302 proc_mkdir("capi", NULL
);
303 proc_mkdir("capi/controllers", NULL
);
304 proc_create("capi/controller", 0, NULL
, &proc_controller_ops
);
305 proc_create("capi/contrstats", 0, NULL
, &proc_contrstats_ops
);
306 proc_create("capi/applications", 0, NULL
, &proc_applications_ops
);
307 proc_create("capi/applstats", 0, NULL
, &proc_applstats_ops
);
308 proc_create("capi/driver", 0, NULL
, &proc_driver_ops
);
312 kcapi_proc_exit(void)
314 remove_proc_entry("capi/driver", NULL
);
315 remove_proc_entry("capi/controller", NULL
);
316 remove_proc_entry("capi/contrstats", NULL
);
317 remove_proc_entry("capi/applications", NULL
);
318 remove_proc_entry("capi/applstats", NULL
);
319 remove_proc_entry("capi/controllers", NULL
);
320 remove_proc_entry("capi", NULL
);