Linux 4.18.10
[linux/fpc-iii.git] / drivers / isdn / capi / kcapi_proc.c
blobc94bd12c0f7c6d04a6d1c87cebb8d091cb11e06e
1 /*
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.
13 #include "kcapi.h"
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/init.h>
17 #include <linux/export.h>
19 static char *state2str(unsigned short state)
21 switch (state) {
22 case CAPI_CTR_DETECTED: return "detected";
23 case CAPI_CTR_LOADING: return "loading";
24 case CAPI_CTR_RUNNING: return "running";
25 default: return "???";
29 // /proc/capi
30 // ===========================================================================
32 // /proc/capi/controller:
33 // cnr driver cardstate name driverinfo
34 // /proc/capi/contrstats:
35 // cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
36 // ---------------------------------------------------------------------------
38 static void *controller_start(struct seq_file *seq, loff_t *pos)
39 __acquires(capi_controller_lock)
41 mutex_lock(&capi_controller_lock);
43 if (*pos < CAPI_MAXCONTR)
44 return &capi_controller[*pos];
46 return NULL;
49 static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
51 ++*pos;
52 if (*pos < CAPI_MAXCONTR)
53 return &capi_controller[*pos];
55 return NULL;
58 static void controller_stop(struct seq_file *seq, void *v)
59 __releases(capi_controller_lock)
61 mutex_unlock(&capi_controller_lock);
64 static int controller_show(struct seq_file *seq, void *v)
66 struct capi_ctr *ctr = *(struct capi_ctr **) v;
68 if (!ctr)
69 return 0;
71 seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
72 ctr->cnr, ctr->driver_name,
73 state2str(ctr->state),
74 ctr->name,
75 ctr->procinfo ? ctr->procinfo(ctr) : "");
77 return 0;
80 static int contrstats_show(struct seq_file *seq, void *v)
82 struct capi_ctr *ctr = *(struct capi_ctr **) v;
84 if (!ctr)
85 return 0;
87 seq_printf(seq, "%d %lu %lu %lu %lu\n",
88 ctr->cnr,
89 ctr->nrecvctlpkt,
90 ctr->nrecvdatapkt,
91 ctr->nsentctlpkt,
92 ctr->nsentdatapkt);
94 return 0;
97 static const struct seq_operations seq_controller_ops = {
98 .start = controller_start,
99 .next = controller_next,
100 .stop = controller_stop,
101 .show = controller_show,
104 static const struct seq_operations seq_contrstats_ops = {
105 .start = controller_start,
106 .next = controller_next,
107 .stop = controller_stop,
108 .show = contrstats_show,
111 // /proc/capi/applications:
112 // applid l3cnt dblkcnt dblklen #ncci recvqueuelen
113 // /proc/capi/applstats:
114 // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
115 // ---------------------------------------------------------------------------
117 static void *applications_start(struct seq_file *seq, loff_t *pos)
118 __acquires(capi_controller_lock)
120 mutex_lock(&capi_controller_lock);
122 if (*pos < CAPI_MAXAPPL)
123 return &capi_applications[*pos];
125 return NULL;
128 static void *
129 applications_next(struct seq_file *seq, void *v, loff_t *pos)
131 ++*pos;
132 if (*pos < CAPI_MAXAPPL)
133 return &capi_applications[*pos];
135 return NULL;
138 static void applications_stop(struct seq_file *seq, void *v)
139 __releases(capi_controller_lock)
141 mutex_unlock(&capi_controller_lock);
144 static int
145 applications_show(struct seq_file *seq, void *v)
147 struct capi20_appl *ap = *(struct capi20_appl **) v;
149 if (!ap)
150 return 0;
152 seq_printf(seq, "%u %d %d %d\n",
153 ap->applid,
154 ap->rparam.level3cnt,
155 ap->rparam.datablkcnt,
156 ap->rparam.datablklen);
158 return 0;
161 static int
162 applstats_show(struct seq_file *seq, void *v)
164 struct capi20_appl *ap = *(struct capi20_appl **) v;
166 if (!ap)
167 return 0;
169 seq_printf(seq, "%u %lu %lu %lu %lu\n",
170 ap->applid,
171 ap->nrecvctlpkt,
172 ap->nrecvdatapkt,
173 ap->nsentctlpkt,
174 ap->nsentdatapkt);
176 return 0;
179 static const struct seq_operations seq_applications_ops = {
180 .start = applications_start,
181 .next = applications_next,
182 .stop = applications_stop,
183 .show = applications_show,
186 static const struct seq_operations seq_applstats_ops = {
187 .start = applications_start,
188 .next = applications_next,
189 .stop = applications_stop,
190 .show = applstats_show,
193 // ---------------------------------------------------------------------------
195 static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
196 __acquires(&capi_drivers_lock)
198 mutex_lock(&capi_drivers_lock);
199 return seq_list_start(&capi_drivers, *pos);
202 static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
204 return seq_list_next(v, &capi_drivers, pos);
207 static void capi_driver_stop(struct seq_file *seq, void *v)
208 __releases(&capi_drivers_lock)
210 mutex_unlock(&capi_drivers_lock);
213 static int capi_driver_show(struct seq_file *seq, void *v)
215 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
217 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
218 return 0;
221 static const struct seq_operations seq_capi_driver_ops = {
222 .start = capi_driver_start,
223 .next = capi_driver_next,
224 .stop = capi_driver_stop,
225 .show = capi_driver_show,
228 // ---------------------------------------------------------------------------
230 void __init
231 kcapi_proc_init(void)
233 proc_mkdir("capi", NULL);
234 proc_mkdir("capi/controllers", NULL);
235 proc_create_seq("capi/controller", 0, NULL, &seq_controller_ops);
236 proc_create_seq("capi/contrstats", 0, NULL, &seq_contrstats_ops);
237 proc_create_seq("capi/applications", 0, NULL, &seq_applications_ops);
238 proc_create_seq("capi/applstats", 0, NULL, &seq_applstats_ops);
239 proc_create_seq("capi/driver", 0, NULL, &seq_capi_driver_ops);
242 void __exit
243 kcapi_proc_exit(void)
245 remove_proc_entry("capi/driver", NULL);
246 remove_proc_entry("capi/controller", NULL);
247 remove_proc_entry("capi/contrstats", NULL);
248 remove_proc_entry("capi/applications", NULL);
249 remove_proc_entry("capi/applstats", NULL);
250 remove_proc_entry("capi/controllers", NULL);
251 remove_proc_entry("capi", NULL);