Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | ||
52253031 | 18 | static char *state2str(unsigned short state) |
1da177e4 | 19 | { |
52253031 JK |
20 | switch (state) { |
21 | case CAPI_CTR_DETECTED: return "detected"; | |
22 | case CAPI_CTR_LOADING: return "loading"; | |
23 | case CAPI_CTR_RUNNING: return "running"; | |
1da177e4 LT |
24 | 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 | ||
37 | static void *controller_start(struct seq_file *seq, loff_t *pos) | |
38 | { | |
39 | if (*pos < CAPI_MAXCONTR) | |
52253031 | 40 | return &capi_controller[*pos]; |
1da177e4 LT |
41 | |
42 | return NULL; | |
43 | } | |
44 | ||
45 | static void *controller_next(struct seq_file *seq, void *v, loff_t *pos) | |
46 | { | |
47 | ++*pos; | |
48 | if (*pos < CAPI_MAXCONTR) | |
52253031 | 49 | return &capi_controller[*pos]; |
1da177e4 LT |
50 | |
51 | return NULL; | |
52 | } | |
53 | ||
54 | static void controller_stop(struct seq_file *seq, void *v) | |
55 | { | |
56 | } | |
57 | ||
58 | static int controller_show(struct seq_file *seq, void *v) | |
59 | { | |
60 | struct capi_ctr *ctr = *(struct capi_ctr **) v; | |
61 | ||
62 | if (!ctr) | |
63 | return 0; | |
64 | ||
65 | seq_printf(seq, "%d %-10s %-8s %-16s %s\n", | |
66 | ctr->cnr, ctr->driver_name, | |
52253031 | 67 | state2str(ctr->state), |
1da177e4 LT |
68 | ctr->name, |
69 | ctr->procinfo ? ctr->procinfo(ctr) : ""); | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | static int contrstats_show(struct seq_file *seq, void *v) | |
75 | { | |
76 | struct capi_ctr *ctr = *(struct capi_ctr **) v; | |
77 | ||
78 | if (!ctr) | |
79 | return 0; | |
80 | ||
81 | seq_printf(seq, "%d %lu %lu %lu %lu\n", | |
82 | ctr->cnr, | |
83 | ctr->nrecvctlpkt, | |
84 | ctr->nrecvdatapkt, | |
85 | ctr->nsentctlpkt, | |
86 | ctr->nsentdatapkt); | |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
88e9d34c | 91 | static const struct seq_operations seq_controller_ops = { |
1da177e4 LT |
92 | .start = controller_start, |
93 | .next = controller_next, | |
94 | .stop = controller_stop, | |
95 | .show = controller_show, | |
96 | }; | |
97 | ||
88e9d34c | 98 | static const struct seq_operations seq_contrstats_ops = { |
1da177e4 LT |
99 | .start = controller_start, |
100 | .next = controller_next, | |
101 | .stop = controller_stop, | |
102 | .show = contrstats_show, | |
103 | }; | |
104 | ||
105 | static int seq_controller_open(struct inode *inode, struct file *file) | |
106 | { | |
107 | return seq_open(file, &seq_controller_ops); | |
108 | } | |
109 | ||
110 | static int seq_contrstats_open(struct inode *inode, struct file *file) | |
111 | { | |
112 | return seq_open(file, &seq_contrstats_ops); | |
113 | } | |
114 | ||
2b8693c0 | 115 | static const struct file_operations proc_controller_ops = { |
ac41cfd1 | 116 | .owner = THIS_MODULE, |
1da177e4 LT |
117 | .open = seq_controller_open, |
118 | .read = seq_read, | |
119 | .llseek = seq_lseek, | |
120 | .release = seq_release, | |
121 | }; | |
122 | ||
2b8693c0 | 123 | static const struct file_operations proc_contrstats_ops = { |
ac41cfd1 | 124 | .owner = THIS_MODULE, |
1da177e4 LT |
125 | .open = seq_contrstats_open, |
126 | .read = seq_read, | |
127 | .llseek = seq_lseek, | |
128 | .release = seq_release, | |
129 | }; | |
130 | ||
131 | // /proc/capi/applications: | |
132 | // applid l3cnt dblkcnt dblklen #ncci recvqueuelen | |
133 | // /proc/capi/applstats: | |
134 | // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt | |
135 | // --------------------------------------------------------------------------- | |
136 | ||
137 | static void * | |
138 | applications_start(struct seq_file *seq, loff_t *pos) | |
139 | { | |
140 | if (*pos < CAPI_MAXAPPL) | |
141 | return &capi_applications[*pos]; | |
142 | ||
143 | return NULL; | |
144 | } | |
145 | ||
146 | static void * | |
147 | applications_next(struct seq_file *seq, void *v, loff_t *pos) | |
148 | { | |
149 | ++*pos; | |
150 | if (*pos < CAPI_MAXAPPL) | |
151 | return &capi_applications[*pos]; | |
152 | ||
153 | return NULL; | |
154 | } | |
155 | ||
156 | static void | |
157 | applications_stop(struct seq_file *seq, void *v) | |
158 | { | |
159 | } | |
160 | ||
161 | static int | |
162 | applications_show(struct seq_file *seq, void *v) | |
163 | { | |
164 | struct capi20_appl *ap = *(struct capi20_appl **) v; | |
165 | ||
166 | if (!ap) | |
167 | return 0; | |
168 | ||
169 | seq_printf(seq, "%u %d %d %d\n", | |
170 | ap->applid, | |
171 | ap->rparam.level3cnt, | |
172 | ap->rparam.datablkcnt, | |
173 | ap->rparam.datablklen); | |
174 | ||
175 | return 0; | |
176 | } | |
177 | ||
178 | static int | |
179 | applstats_show(struct seq_file *seq, void *v) | |
180 | { | |
181 | struct capi20_appl *ap = *(struct capi20_appl **) v; | |
182 | ||
183 | if (!ap) | |
184 | return 0; | |
185 | ||
186 | seq_printf(seq, "%u %lu %lu %lu %lu\n", | |
187 | ap->applid, | |
188 | ap->nrecvctlpkt, | |
189 | ap->nrecvdatapkt, | |
190 | ap->nsentctlpkt, | |
191 | ap->nsentdatapkt); | |
192 | ||
193 | return 0; | |
194 | } | |
195 | ||
88e9d34c | 196 | static const struct seq_operations seq_applications_ops = { |
1da177e4 LT |
197 | .start = applications_start, |
198 | .next = applications_next, | |
199 | .stop = applications_stop, | |
200 | .show = applications_show, | |
201 | }; | |
202 | ||
88e9d34c | 203 | static const struct seq_operations seq_applstats_ops = { |
1da177e4 LT |
204 | .start = applications_start, |
205 | .next = applications_next, | |
206 | .stop = applications_stop, | |
207 | .show = applstats_show, | |
208 | }; | |
209 | ||
210 | static int | |
211 | seq_applications_open(struct inode *inode, struct file *file) | |
212 | { | |
213 | return seq_open(file, &seq_applications_ops); | |
214 | } | |
215 | ||
216 | static int | |
217 | seq_applstats_open(struct inode *inode, struct file *file) | |
218 | { | |
219 | return seq_open(file, &seq_applstats_ops); | |
220 | } | |
221 | ||
2b8693c0 | 222 | static const struct file_operations proc_applications_ops = { |
ac41cfd1 | 223 | .owner = THIS_MODULE, |
1da177e4 LT |
224 | .open = seq_applications_open, |
225 | .read = seq_read, | |
226 | .llseek = seq_lseek, | |
227 | .release = seq_release, | |
228 | }; | |
229 | ||
2b8693c0 | 230 | static const struct file_operations proc_applstats_ops = { |
ac41cfd1 | 231 | .owner = THIS_MODULE, |
1da177e4 LT |
232 | .open = seq_applstats_open, |
233 | .read = seq_read, | |
234 | .llseek = seq_lseek, | |
235 | .release = seq_release, | |
236 | }; | |
237 | ||
1da177e4 LT |
238 | // --------------------------------------------------------------------------- |
239 | ||
1da177e4 | 240 | static void *capi_driver_start(struct seq_file *seq, loff_t *pos) |
dfe925e8 | 241 | __acquires(&capi_drivers_list_lock) |
1da177e4 | 242 | { |
1da177e4 | 243 | read_lock(&capi_drivers_list_lock); |
2b7c3029 | 244 | return seq_list_start(&capi_drivers, *pos); |
1da177e4 LT |
245 | } |
246 | ||
247 | static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos) | |
248 | { | |
2b7c3029 | 249 | return seq_list_next(v, &capi_drivers, pos); |
1da177e4 LT |
250 | } |
251 | ||
252 | static void capi_driver_stop(struct seq_file *seq, void *v) | |
dfe925e8 | 253 | __releases(&capi_drivers_list_lock) |
1da177e4 LT |
254 | { |
255 | read_unlock(&capi_drivers_list_lock); | |
256 | } | |
257 | ||
258 | static int capi_driver_show(struct seq_file *seq, void *v) | |
259 | { | |
2b7c3029 PE |
260 | struct capi_driver *drv = list_entry(v, struct capi_driver, list); |
261 | ||
1da177e4 LT |
262 | seq_printf(seq, "%-32s %s\n", drv->name, drv->revision); |
263 | return 0; | |
264 | } | |
265 | ||
88e9d34c | 266 | static const struct seq_operations seq_capi_driver_ops = { |
1da177e4 LT |
267 | .start = capi_driver_start, |
268 | .next = capi_driver_next, | |
269 | .stop = capi_driver_stop, | |
270 | .show = capi_driver_show, | |
271 | }; | |
272 | ||
273 | static int | |
274 | seq_capi_driver_open(struct inode *inode, struct file *file) | |
275 | { | |
276 | int err; | |
277 | err = seq_open(file, &seq_capi_driver_ops); | |
278 | return err; | |
279 | } | |
280 | ||
2b8693c0 | 281 | static const struct file_operations proc_driver_ops = { |
ac41cfd1 | 282 | .owner = THIS_MODULE, |
1da177e4 LT |
283 | .open = seq_capi_driver_open, |
284 | .read = seq_read, | |
285 | .llseek = seq_lseek, | |
286 | .release = seq_release, | |
287 | }; | |
288 | ||
289 | // --------------------------------------------------------------------------- | |
290 | ||
291 | void __init | |
292 | kcapi_proc_init(void) | |
293 | { | |
294 | proc_mkdir("capi", NULL); | |
295 | proc_mkdir("capi/controllers", NULL); | |
ac41cfd1 DL |
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); | |
1da177e4 LT |
301 | } |
302 | ||
303 | void __exit | |
304 | kcapi_proc_exit(void) | |
305 | { | |
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); | |
313 | } |