blob: 3e6e17a24389e5d6e3641dd7fe81fbe2cd69f7a2 [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
Jan Kiszka52253032010-02-08 10:12:10 +000018static char *state2str(unsigned short state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Jan Kiszka52253032010-02-08 10:12:10 +000020 switch (state) {
21 case CAPI_CTR_DETECTED: return "detected";
22 case CAPI_CTR_LOADING: return "loading";
23 case CAPI_CTR_RUNNING: return "running";
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 default: return "???";
25 }
26}
27
28// /proc/capi
29// ===========================================================================
30
31// /proc/capi/controller:
32// cnr driver cardstate name driverinfo
33// /proc/capi/contrstats:
34// cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
35// ---------------------------------------------------------------------------
36
37static void *controller_start(struct seq_file *seq, loff_t *pos)
Jan Kiszka0ca3a012010-02-08 10:12:14 +000038 __acquires(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Jan Kiszka0ca3a012010-02-08 10:12:14 +000040 mutex_lock(&capi_controller_lock);
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 if (*pos < CAPI_MAXCONTR)
Jan Kiszka52253032010-02-08 10:12:10 +000043 return &capi_controller[*pos];
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 return NULL;
46}
47
48static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
49{
50 ++*pos;
51 if (*pos < CAPI_MAXCONTR)
Jan Kiszka52253032010-02-08 10:12:10 +000052 return &capi_controller[*pos];
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 return NULL;
55}
56
57static void controller_stop(struct seq_file *seq, void *v)
Jan Kiszka0ca3a012010-02-08 10:12:14 +000058 __releases(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Jan Kiszka0ca3a012010-02-08 10:12:14 +000060 mutex_unlock(&capi_controller_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
63static int controller_show(struct seq_file *seq, void *v)
64{
65 struct capi_ctr *ctr = *(struct capi_ctr **) v;
66
67 if (!ctr)
68 return 0;
69
70 seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
71 ctr->cnr, ctr->driver_name,
Jan Kiszka52253032010-02-08 10:12:10 +000072 state2str(ctr->state),
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ctr->name,
74 ctr->procinfo ? ctr->procinfo(ctr) : "");
75
76 return 0;
77}
78
79static int contrstats_show(struct seq_file *seq, void *v)
80{
81 struct capi_ctr *ctr = *(struct capi_ctr **) v;
82
83 if (!ctr)
84 return 0;
85
86 seq_printf(seq, "%d %lu %lu %lu %lu\n",
87 ctr->cnr,
88 ctr->nrecvctlpkt,
89 ctr->nrecvdatapkt,
90 ctr->nsentctlpkt,
91 ctr->nsentdatapkt);
92
93 return 0;
94}
95
James Morris88e9d342009-09-22 16:43:43 -070096static const struct seq_operations seq_controller_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .start = controller_start,
98 .next = controller_next,
99 .stop = controller_stop,
100 .show = controller_show,
101};
102
James Morris88e9d342009-09-22 16:43:43 -0700103static const struct seq_operations seq_contrstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 .start = controller_start,
105 .next = controller_next,
106 .stop = controller_stop,
107 .show = contrstats_show,
108};
109
110static int seq_controller_open(struct inode *inode, struct file *file)
111{
112 return seq_open(file, &seq_controller_ops);
113}
114
115static int seq_contrstats_open(struct inode *inode, struct file *file)
116{
117 return seq_open(file, &seq_contrstats_ops);
118}
119
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800120static const struct file_operations proc_controller_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700121 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .open = seq_controller_open,
123 .read = seq_read,
124 .llseek = seq_lseek,
125 .release = seq_release,
126};
127
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800128static const struct file_operations proc_contrstats_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700129 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .open = seq_contrstats_open,
131 .read = seq_read,
132 .llseek = seq_lseek,
133 .release = seq_release,
134};
135
136// /proc/capi/applications:
137// applid l3cnt dblkcnt dblklen #ncci recvqueuelen
138// /proc/capi/applstats:
139// applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
140// ---------------------------------------------------------------------------
141
142static void *
143applications_start(struct seq_file *seq, loff_t *pos)
144{
145 if (*pos < CAPI_MAXAPPL)
146 return &capi_applications[*pos];
147
148 return NULL;
149}
150
151static void *
152applications_next(struct seq_file *seq, void *v, loff_t *pos)
153{
154 ++*pos;
155 if (*pos < CAPI_MAXAPPL)
156 return &capi_applications[*pos];
157
158 return NULL;
159}
160
161static void
162applications_stop(struct seq_file *seq, void *v)
163{
164}
165
166static int
167applications_show(struct seq_file *seq, void *v)
168{
169 struct capi20_appl *ap = *(struct capi20_appl **) v;
170
171 if (!ap)
172 return 0;
173
174 seq_printf(seq, "%u %d %d %d\n",
175 ap->applid,
176 ap->rparam.level3cnt,
177 ap->rparam.datablkcnt,
178 ap->rparam.datablklen);
179
180 return 0;
181}
182
183static int
184applstats_show(struct seq_file *seq, void *v)
185{
186 struct capi20_appl *ap = *(struct capi20_appl **) v;
187
188 if (!ap)
189 return 0;
190
191 seq_printf(seq, "%u %lu %lu %lu %lu\n",
192 ap->applid,
193 ap->nrecvctlpkt,
194 ap->nrecvdatapkt,
195 ap->nsentctlpkt,
196 ap->nsentdatapkt);
197
198 return 0;
199}
200
James Morris88e9d342009-09-22 16:43:43 -0700201static const struct seq_operations seq_applications_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .start = applications_start,
203 .next = applications_next,
204 .stop = applications_stop,
205 .show = applications_show,
206};
207
James Morris88e9d342009-09-22 16:43:43 -0700208static const struct seq_operations seq_applstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 .start = applications_start,
210 .next = applications_next,
211 .stop = applications_stop,
212 .show = applstats_show,
213};
214
215static int
216seq_applications_open(struct inode *inode, struct file *file)
217{
218 return seq_open(file, &seq_applications_ops);
219}
220
221static int
222seq_applstats_open(struct inode *inode, struct file *file)
223{
224 return seq_open(file, &seq_applstats_ops);
225}
226
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800227static const struct file_operations proc_applications_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700228 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .open = seq_applications_open,
230 .read = seq_read,
231 .llseek = seq_lseek,
232 .release = seq_release,
233};
234
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800235static const struct file_operations proc_applstats_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700236 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .open = seq_applstats_open,
238 .read = seq_read,
239 .llseek = seq_lseek,
240 .release = seq_release,
241};
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243// ---------------------------------------------------------------------------
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000246 __acquires(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000248 mutex_lock(&capi_drivers_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)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000258 __releases(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000260 mutex_unlock(&capi_drivers_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263static int capi_driver_show(struct seq_file *seq, void *v)
264{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700265 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
268 return 0;
269}
270
James Morris88e9d342009-09-22 16:43:43 -0700271static const struct seq_operations seq_capi_driver_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .start = capi_driver_start,
273 .next = capi_driver_next,
274 .stop = capi_driver_stop,
275 .show = capi_driver_show,
276};
277
278static int
279seq_capi_driver_open(struct inode *inode, struct file *file)
280{
281 int err;
282 err = seq_open(file, &seq_capi_driver_ops);
283 return err;
284}
285
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800286static const struct file_operations proc_driver_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700287 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 .open = seq_capi_driver_open,
289 .read = seq_read,
290 .llseek = seq_lseek,
291 .release = seq_release,
292};
293
294// ---------------------------------------------------------------------------
295
296void __init
297kcapi_proc_init(void)
298{
299 proc_mkdir("capi", NULL);
300 proc_mkdir("capi/controllers", NULL);
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700301 proc_create("capi/controller", 0, NULL, &proc_controller_ops);
302 proc_create("capi/contrstats", 0, NULL, &proc_contrstats_ops);
303 proc_create("capi/applications", 0, NULL, &proc_applications_ops);
304 proc_create("capi/applstats", 0, NULL, &proc_applstats_ops);
305 proc_create("capi/driver", 0, NULL, &proc_driver_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
308void __exit
309kcapi_proc_exit(void)
310{
311 remove_proc_entry("capi/driver", NULL);
312 remove_proc_entry("capi/controller", NULL);
313 remove_proc_entry("capi/contrstats", NULL);
314 remove_proc_entry("capi/applications", NULL);
315 remove_proc_entry("capi/applstats", NULL);
316 remove_proc_entry("capi/controllers", NULL);
317 remove_proc_entry("capi", NULL);
318}