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
)
39 if (*pos
< CAPI_MAXCONTR
)
40 return &capi_controller
[*pos
];
45 static void *controller_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
48 if (*pos
< CAPI_MAXCONTR
)
49 return &capi_controller
[*pos
];
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
;
65 seq_printf(seq
, "%d %-10s %-8s %-16s %s\n",
66 ctr
->cnr
, ctr
->driver_name
,
67 state2str(ctr
->state
),
69 ctr
->procinfo
? ctr
->procinfo(ctr
) : "");
74 static int contrstats_show(struct seq_file
*seq
, void *v
)
76 struct capi_ctr
*ctr
= *(struct capi_ctr
**) v
;
81 seq_printf(seq
, "%d %lu %lu %lu %lu\n",
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
,
120 .release
= seq_release
,
123 static const struct file_operations proc_contrstats_ops
= {
124 .owner
= THIS_MODULE
,
125 .open
= seq_contrstats_open
,
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 // ---------------------------------------------------------------------------
138 applications_start(struct seq_file
*seq
, loff_t
*pos
)
140 if (*pos
< CAPI_MAXAPPL
)
141 return &capi_applications
[*pos
];
147 applications_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
150 if (*pos
< CAPI_MAXAPPL
)
151 return &capi_applications
[*pos
];
157 applications_stop(struct seq_file
*seq
, void *v
)
162 applications_show(struct seq_file
*seq
, void *v
)
164 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
169 seq_printf(seq
, "%u %d %d %d\n",
171 ap
->rparam
.level3cnt
,
172 ap
->rparam
.datablkcnt
,
173 ap
->rparam
.datablklen
);
179 applstats_show(struct seq_file
*seq
, void *v
)
181 struct capi20_appl
*ap
= *(struct capi20_appl
**) v
;
186 seq_printf(seq
, "%u %lu %lu %lu %lu\n",
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
,
211 seq_applications_open(struct inode
*inode
, struct file
*file
)
213 return seq_open(file
, &seq_applications_ops
);
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
,
227 .release
= seq_release
,
230 static const struct file_operations proc_applstats_ops
= {
231 .owner
= THIS_MODULE
,
232 .open
= seq_applstats_open
,
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
);
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
,
274 seq_capi_driver_open(struct inode
*inode
, struct file
*file
)
277 err
= seq_open(file
, &seq_capi_driver_ops
);
281 static const struct file_operations proc_driver_ops
= {
282 .owner
= THIS_MODULE
,
283 .open
= seq_capi_driver_open
,
286 .release
= seq_release
,
289 // ---------------------------------------------------------------------------
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
);
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
);