blob: 845a797b00309e2fb45fb1ce3f9defd5ed943146 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
9 *
10 */
11
12
13#include "kcapi.h"
14#include <linux/proc_fs.h>
15#include <linux/seq_file.h>
16#include <linux/init.h>
17
18static char *
19cardstate2str(unsigned short cardstate)
20{
21 switch (cardstate) {
22 case CARD_DETECTED: return "detected";
23 case CARD_LOADING: return "loading";
24 case CARD_RUNNING: return "running";
25 default: return "???";
26 }
27}
28
29// /proc/capi
30// ===========================================================================
31
32// /proc/capi/controller:
33// cnr driver cardstate name driverinfo
34// /proc/capi/contrstats:
35// cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
36// ---------------------------------------------------------------------------
37
38static void *controller_start(struct seq_file *seq, loff_t *pos)
39{
40 if (*pos < CAPI_MAXCONTR)
41 return &capi_cards[*pos];
42
43 return NULL;
44}
45
46static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
47{
48 ++*pos;
49 if (*pos < CAPI_MAXCONTR)
50 return &capi_cards[*pos];
51
52 return NULL;
53}
54
55static void controller_stop(struct seq_file *seq, void *v)
56{
57}
58
59static int controller_show(struct seq_file *seq, void *v)
60{
61 struct capi_ctr *ctr = *(struct capi_ctr **) v;
62
63 if (!ctr)
64 return 0;
65
66 seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
67 ctr->cnr, ctr->driver_name,
68 cardstate2str(ctr->cardstate),
69 ctr->name,
70 ctr->procinfo ? ctr->procinfo(ctr) : "");
71
72 return 0;
73}
74
75static int contrstats_show(struct seq_file *seq, void *v)
76{
77 struct capi_ctr *ctr = *(struct capi_ctr **) v;
78
79 if (!ctr)
80 return 0;
81
82 seq_printf(seq, "%d %lu %lu %lu %lu\n",
83 ctr->cnr,
84 ctr->nrecvctlpkt,
85 ctr->nrecvdatapkt,
86 ctr->nsentctlpkt,
87 ctr->nsentdatapkt);
88
89 return 0;
90}
91
Adrian Bunk408b6642005-05-01 08:59:29 -070092static struct seq_operations seq_controller_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .start = controller_start,
94 .next = controller_next,
95 .stop = controller_stop,
96 .show = controller_show,
97};
98
Adrian Bunk408b6642005-05-01 08:59:29 -070099static struct seq_operations seq_contrstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 .start = controller_start,
101 .next = controller_next,
102 .stop = controller_stop,
103 .show = contrstats_show,
104};
105
106static int seq_controller_open(struct inode *inode, struct file *file)
107{
108 return seq_open(file, &seq_controller_ops);
109}
110
111static int seq_contrstats_open(struct inode *inode, struct file *file)
112{
113 return seq_open(file, &seq_contrstats_ops);
114}
115
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800116static const struct file_operations proc_controller_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .open = seq_controller_open,
118 .read = seq_read,
119 .llseek = seq_lseek,
120 .release = seq_release,
121};
122
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800123static const struct file_operations proc_contrstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .open = seq_contrstats_open,
125 .read = seq_read,
126 .llseek = seq_lseek,
127 .release = seq_release,
128};
129
130// /proc/capi/applications:
131// applid l3cnt dblkcnt dblklen #ncci recvqueuelen
132// /proc/capi/applstats:
133// applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
134// ---------------------------------------------------------------------------
135
136static void *
137applications_start(struct seq_file *seq, loff_t *pos)
138{
139 if (*pos < CAPI_MAXAPPL)
140 return &capi_applications[*pos];
141
142 return NULL;
143}
144
145static void *
146applications_next(struct seq_file *seq, void *v, loff_t *pos)
147{
148 ++*pos;
149 if (*pos < CAPI_MAXAPPL)
150 return &capi_applications[*pos];
151
152 return NULL;
153}
154
155static void
156applications_stop(struct seq_file *seq, void *v)
157{
158}
159
160static int
161applications_show(struct seq_file *seq, void *v)
162{
163 struct capi20_appl *ap = *(struct capi20_appl **) v;
164
165 if (!ap)
166 return 0;
167
168 seq_printf(seq, "%u %d %d %d\n",
169 ap->applid,
170 ap->rparam.level3cnt,
171 ap->rparam.datablkcnt,
172 ap->rparam.datablklen);
173
174 return 0;
175}
176
177static int
178applstats_show(struct seq_file *seq, void *v)
179{
180 struct capi20_appl *ap = *(struct capi20_appl **) v;
181
182 if (!ap)
183 return 0;
184
185 seq_printf(seq, "%u %lu %lu %lu %lu\n",
186 ap->applid,
187 ap->nrecvctlpkt,
188 ap->nrecvdatapkt,
189 ap->nsentctlpkt,
190 ap->nsentdatapkt);
191
192 return 0;
193}
194
Adrian Bunk408b6642005-05-01 08:59:29 -0700195static struct seq_operations seq_applications_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 .start = applications_start,
197 .next = applications_next,
198 .stop = applications_stop,
199 .show = applications_show,
200};
201
Adrian Bunk408b6642005-05-01 08:59:29 -0700202static struct seq_operations seq_applstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .start = applications_start,
204 .next = applications_next,
205 .stop = applications_stop,
206 .show = applstats_show,
207};
208
209static int
210seq_applications_open(struct inode *inode, struct file *file)
211{
212 return seq_open(file, &seq_applications_ops);
213}
214
215static int
216seq_applstats_open(struct inode *inode, struct file *file)
217{
218 return seq_open(file, &seq_applstats_ops);
219}
220
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800221static const struct file_operations proc_applications_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .open = seq_applications_open,
223 .read = seq_read,
224 .llseek = seq_lseek,
225 .release = seq_release,
226};
227
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800228static const struct file_operations proc_applstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .open = seq_applstats_open,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = seq_release,
233};
234
235static void
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800236create_seq_entry(char *name, mode_t mode, const struct file_operations *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
238 struct proc_dir_entry *entry;
239 entry = create_proc_entry(name, mode, NULL);
240 if (entry)
241 entry->proc_fops = f;
242}
243
244// ---------------------------------------------------------------------------
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
247{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 read_lock(&capi_drivers_list_lock);
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700249 return seq_list_start(&capi_drivers, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
253{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700254 return seq_list_next(v, &capi_drivers, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
257static void capi_driver_stop(struct seq_file *seq, void *v)
258{
259 read_unlock(&capi_drivers_list_lock);
260}
261
262static int capi_driver_show(struct seq_file *seq, void *v)
263{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700264 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
267 return 0;
268}
269
Adrian Bunk408b6642005-05-01 08:59:29 -0700270static struct seq_operations seq_capi_driver_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 .start = capi_driver_start,
272 .next = capi_driver_next,
273 .stop = capi_driver_stop,
274 .show = capi_driver_show,
275};
276
277static int
278seq_capi_driver_open(struct inode *inode, struct file *file)
279{
280 int err;
281 err = seq_open(file, &seq_capi_driver_ops);
282 return err;
283}
284
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800285static const struct file_operations proc_driver_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .open = seq_capi_driver_open,
287 .read = seq_read,
288 .llseek = seq_lseek,
289 .release = seq_release,
290};
291
292// ---------------------------------------------------------------------------
293
294void __init
295kcapi_proc_init(void)
296{
297 proc_mkdir("capi", NULL);
298 proc_mkdir("capi/controllers", NULL);
299 create_seq_entry("capi/controller", 0, &proc_controller_ops);
300 create_seq_entry("capi/contrstats", 0, &proc_contrstats_ops);
301 create_seq_entry("capi/applications", 0, &proc_applications_ops);
302 create_seq_entry("capi/applstats", 0, &proc_applstats_ops);
303 create_seq_entry("capi/driver", 0, &proc_driver_ops);
304}
305
306void __exit
307kcapi_proc_exit(void)
308{
309 remove_proc_entry("capi/driver", NULL);
310 remove_proc_entry("capi/controller", NULL);
311 remove_proc_entry("capi/contrstats", NULL);
312 remove_proc_entry("capi/applications", NULL);
313 remove_proc_entry("capi/applstats", NULL);
314 remove_proc_entry("capi/controllers", NULL);
315 remove_proc_entry("capi", NULL);
316}