blob: 68db3c5a10636a027ee72fce2341981046ca671a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Kernel CAPI 2.0 Module - /proc/capi handling
Joe Perches475be4d2012-02-19 19:52:38 -08003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 1999 by Carsten Paeth <calle@calle.de>
5 * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
Joe Perches475be4d2012-02-19 19:52:38 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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>
Paul Gortmaker5d76fc22011-07-10 12:23:16 -040017#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Jan Kiszka52253032010-02-08 10:12:10 +000019static char *state2str(unsigned short state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Jan Kiszka52253032010-02-08 10:12:10 +000021 switch (state) {
22 case CAPI_CTR_DETECTED: return "detected";
23 case CAPI_CTR_LOADING: return "loading";
24 case CAPI_CTR_RUNNING: return "running";
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 default: return "???";
26 }
27}
28
29// /proc/capi
30// ===========================================================================
31
Joe Perches475be4d2012-02-19 19:52:38 -080032// /proc/capi/controller:
Linus Torvalds1da177e2005-04-16 15:20:36 -070033// 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)
Jan Kiszka0ca3a012010-02-08 10:12:14 +000039 __acquires(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Jan Kiszka0ca3a012010-02-08 10:12:14 +000041 mutex_lock(&capi_controller_lock);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 if (*pos < CAPI_MAXCONTR)
Jan Kiszka52253032010-02-08 10:12:10 +000044 return &capi_controller[*pos];
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 return NULL;
47}
48
49static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
50{
51 ++*pos;
52 if (*pos < CAPI_MAXCONTR)
Jan Kiszka52253032010-02-08 10:12:10 +000053 return &capi_controller[*pos];
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 return NULL;
56}
57
58static void controller_stop(struct seq_file *seq, void *v)
Jan Kiszka0ca3a012010-02-08 10:12:14 +000059 __releases(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Jan Kiszka0ca3a012010-02-08 10:12:14 +000061 mutex_unlock(&capi_controller_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
64static int controller_show(struct seq_file *seq, void *v)
65{
66 struct capi_ctr *ctr = *(struct capi_ctr **) v;
67
68 if (!ctr)
69 return 0;
70
71 seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
72 ctr->cnr, ctr->driver_name,
Jan Kiszka52253032010-02-08 10:12:10 +000073 state2str(ctr->state),
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 ctr->name,
75 ctr->procinfo ? ctr->procinfo(ctr) : "");
76
77 return 0;
78}
79
80static int contrstats_show(struct seq_file *seq, void *v)
81{
82 struct capi_ctr *ctr = *(struct capi_ctr **) v;
83
84 if (!ctr)
85 return 0;
86
87 seq_printf(seq, "%d %lu %lu %lu %lu\n",
Joe Perches475be4d2012-02-19 19:52:38 -080088 ctr->cnr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 ctr->nrecvctlpkt,
90 ctr->nrecvdatapkt,
91 ctr->nsentctlpkt,
92 ctr->nsentdatapkt);
93
94 return 0;
95}
96
James Morris88e9d342009-09-22 16:43:43 -070097static const struct seq_operations seq_controller_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .start = controller_start,
99 .next = controller_next,
100 .stop = controller_stop,
101 .show = controller_show,
102};
103
James Morris88e9d342009-09-22 16:43:43 -0700104static const struct seq_operations seq_contrstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .start = controller_start,
106 .next = controller_next,
107 .stop = controller_stop,
108 .show = contrstats_show,
109};
110
111static int seq_controller_open(struct inode *inode, struct file *file)
112{
113 return seq_open(file, &seq_controller_ops);
114}
115
116static int seq_contrstats_open(struct inode *inode, struct file *file)
117{
118 return seq_open(file, &seq_contrstats_ops);
119}
120
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800121static const struct file_operations proc_controller_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700122 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .open = seq_controller_open,
124 .read = seq_read,
125 .llseek = seq_lseek,
126 .release = seq_release,
127};
128
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800129static const struct file_operations proc_contrstats_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700130 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .open = seq_contrstats_open,
132 .read = seq_read,
133 .llseek = seq_lseek,
134 .release = seq_release,
135};
136
Joe Perches475be4d2012-02-19 19:52:38 -0800137// /proc/capi/applications:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138// applid l3cnt dblkcnt dblklen #ncci recvqueuelen
Joe Perches475be4d2012-02-19 19:52:38 -0800139// /proc/capi/applstats:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140// applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
141// ---------------------------------------------------------------------------
142
Jan Kiszka88c896e2010-02-08 10:12:15 +0000143static void *applications_start(struct seq_file *seq, loff_t *pos)
144 __acquires(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Jan Kiszka88c896e2010-02-08 10:12:15 +0000146 mutex_lock(&capi_controller_lock);
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (*pos < CAPI_MAXAPPL)
149 return &capi_applications[*pos];
150
151 return NULL;
152}
153
154static void *
155applications_next(struct seq_file *seq, void *v, loff_t *pos)
156{
157 ++*pos;
158 if (*pos < CAPI_MAXAPPL)
159 return &capi_applications[*pos];
160
161 return NULL;
162}
163
Jan Kiszka88c896e2010-02-08 10:12:15 +0000164static void applications_stop(struct seq_file *seq, void *v)
165 __releases(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Jan Kiszka88c896e2010-02-08 10:12:15 +0000167 mutex_unlock(&capi_controller_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170static int
171applications_show(struct seq_file *seq, void *v)
172{
173 struct capi20_appl *ap = *(struct capi20_appl **) v;
174
175 if (!ap)
176 return 0;
177
178 seq_printf(seq, "%u %d %d %d\n",
179 ap->applid,
180 ap->rparam.level3cnt,
181 ap->rparam.datablkcnt,
182 ap->rparam.datablklen);
183
184 return 0;
185}
186
187static int
188applstats_show(struct seq_file *seq, void *v)
189{
190 struct capi20_appl *ap = *(struct capi20_appl **) v;
191
192 if (!ap)
193 return 0;
194
195 seq_printf(seq, "%u %lu %lu %lu %lu\n",
196 ap->applid,
197 ap->nrecvctlpkt,
198 ap->nrecvdatapkt,
199 ap->nsentctlpkt,
200 ap->nsentdatapkt);
201
202 return 0;
203}
204
James Morris88e9d342009-09-22 16:43:43 -0700205static const struct seq_operations seq_applications_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .start = applications_start,
207 .next = applications_next,
208 .stop = applications_stop,
209 .show = applications_show,
210};
211
James Morris88e9d342009-09-22 16:43:43 -0700212static const struct seq_operations seq_applstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .start = applications_start,
214 .next = applications_next,
215 .stop = applications_stop,
216 .show = applstats_show,
217};
218
219static int
220seq_applications_open(struct inode *inode, struct file *file)
221{
222 return seq_open(file, &seq_applications_ops);
223}
224
225static int
226seq_applstats_open(struct inode *inode, struct file *file)
227{
228 return seq_open(file, &seq_applstats_ops);
229}
230
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800231static const struct file_operations proc_applications_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700232 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .open = seq_applications_open,
234 .read = seq_read,
235 .llseek = seq_lseek,
236 .release = seq_release,
237};
238
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800239static const struct file_operations proc_applstats_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700240 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .open = seq_applstats_open,
242 .read = seq_read,
243 .llseek = seq_lseek,
244 .release = seq_release,
245};
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247// ---------------------------------------------------------------------------
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000250 __acquires(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000252 mutex_lock(&capi_drivers_lock);
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700253 return seq_list_start(&capi_drivers, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
256static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
257{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700258 return seq_list_next(v, &capi_drivers, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261static void capi_driver_stop(struct seq_file *seq, void *v)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000262 __releases(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000264 mutex_unlock(&capi_drivers_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267static int capi_driver_show(struct seq_file *seq, void *v)
268{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700269 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
272 return 0;
273}
274
James Morris88e9d342009-09-22 16:43:43 -0700275static const struct seq_operations seq_capi_driver_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .start = capi_driver_start,
277 .next = capi_driver_next,
278 .stop = capi_driver_stop,
279 .show = capi_driver_show,
280};
281
282static int
283seq_capi_driver_open(struct inode *inode, struct file *file)
284{
285 int err;
286 err = seq_open(file, &seq_capi_driver_ops);
287 return err;
288}
289
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800290static const struct file_operations proc_driver_ops = {
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700291 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .open = seq_capi_driver_open,
293 .read = seq_read,
294 .llseek = seq_lseek,
295 .release = seq_release,
296};
297
298// ---------------------------------------------------------------------------
299
Joe Perches475be4d2012-02-19 19:52:38 -0800300void __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301kcapi_proc_init(void)
302{
303 proc_mkdir("capi", NULL);
304 proc_mkdir("capi/controllers", NULL);
Denis V. Lunevac41cfd2008-04-29 01:02:30 -0700305 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
312void __exit
313kcapi_proc_exit(void)
314{
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);
322}