blob: c94bd12c0f7c6d04a6d1c87cebb8d091cb11e06e [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
Joe Perches475be4d2012-02-19 19:52:38 -0800111// /proc/capi/applications:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112// applid l3cnt dblkcnt dblklen #ncci recvqueuelen
Joe Perches475be4d2012-02-19 19:52:38 -0800113// /proc/capi/applstats:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114// applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
115// ---------------------------------------------------------------------------
116
Jan Kiszka88c896e2010-02-08 10:12:15 +0000117static void *applications_start(struct seq_file *seq, loff_t *pos)
118 __acquires(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Jan Kiszka88c896e2010-02-08 10:12:15 +0000120 mutex_lock(&capi_controller_lock);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (*pos < CAPI_MAXAPPL)
123 return &capi_applications[*pos];
124
125 return NULL;
126}
127
128static void *
129applications_next(struct seq_file *seq, void *v, loff_t *pos)
130{
131 ++*pos;
132 if (*pos < CAPI_MAXAPPL)
133 return &capi_applications[*pos];
134
135 return NULL;
136}
137
Jan Kiszka88c896e2010-02-08 10:12:15 +0000138static void applications_stop(struct seq_file *seq, void *v)
139 __releases(capi_controller_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Jan Kiszka88c896e2010-02-08 10:12:15 +0000141 mutex_unlock(&capi_controller_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144static int
145applications_show(struct seq_file *seq, void *v)
146{
147 struct capi20_appl *ap = *(struct capi20_appl **) v;
148
149 if (!ap)
150 return 0;
151
152 seq_printf(seq, "%u %d %d %d\n",
153 ap->applid,
154 ap->rparam.level3cnt,
155 ap->rparam.datablkcnt,
156 ap->rparam.datablklen);
157
158 return 0;
159}
160
161static int
162applstats_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 %lu %lu %lu %lu\n",
170 ap->applid,
171 ap->nrecvctlpkt,
172 ap->nrecvdatapkt,
173 ap->nsentctlpkt,
174 ap->nsentdatapkt);
175
176 return 0;
177}
178
James Morris88e9d342009-09-22 16:43:43 -0700179static const struct seq_operations seq_applications_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .start = applications_start,
181 .next = applications_next,
182 .stop = applications_stop,
183 .show = applications_show,
184};
185
James Morris88e9d342009-09-22 16:43:43 -0700186static const struct seq_operations seq_applstats_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 .start = applications_start,
188 .next = applications_next,
189 .stop = applications_stop,
190 .show = applstats_show,
191};
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193// ---------------------------------------------------------------------------
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static void *capi_driver_start(struct seq_file *seq, loff_t *pos)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000196 __acquires(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000198 mutex_lock(&capi_drivers_lock);
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700199 return seq_list_start(&capi_drivers, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
202static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos)
203{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700204 return seq_list_next(v, &capi_drivers, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207static void capi_driver_stop(struct seq_file *seq, void *v)
Jan Kiszka9717fb82010-02-08 10:12:11 +0000208 __releases(&capi_drivers_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Jan Kiszka9717fb82010-02-08 10:12:11 +0000210 mutex_unlock(&capi_drivers_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
213static int capi_driver_show(struct seq_file *seq, void *v)
214{
Pavel Emelianov2b7c3022007-07-17 04:04:18 -0700215 struct capi_driver *drv = list_entry(v, struct capi_driver, list);
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 seq_printf(seq, "%-32s %s\n", drv->name, drv->revision);
218 return 0;
219}
220
James Morris88e9d342009-09-22 16:43:43 -0700221static const struct seq_operations seq_capi_driver_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .start = capi_driver_start,
223 .next = capi_driver_next,
224 .stop = capi_driver_stop,
225 .show = capi_driver_show,
226};
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228// ---------------------------------------------------------------------------
229
Joe Perches475be4d2012-02-19 19:52:38 -0800230void __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231kcapi_proc_init(void)
232{
233 proc_mkdir("capi", NULL);
234 proc_mkdir("capi/controllers", NULL);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200235 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242void __exit
243kcapi_proc_exit(void)
244{
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);
252}