xref: /OK3568_Linux_fs/kernel/drivers/isdn/capi/kcapi_proc.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Kernel CAPI 2.0 Module - /proc/capi handling
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright 1999 by Carsten Paeth <calle@calle.de>
5*4882a593Smuzhiyun  * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This software may be used and distributed according to the terms
8*4882a593Smuzhiyun  * of the GNU General Public License, incorporated herein by reference.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include "kcapi.h"
14*4882a593Smuzhiyun #include <linux/proc_fs.h>
15*4882a593Smuzhiyun #include <linux/seq_file.h>
16*4882a593Smuzhiyun #include <linux/init.h>
17*4882a593Smuzhiyun #include <linux/export.h>
18*4882a593Smuzhiyun 
state2str(unsigned short state)19*4882a593Smuzhiyun static char *state2str(unsigned short state)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun 	switch (state) {
22*4882a593Smuzhiyun 	case CAPI_CTR_DETECTED:	return "detected";
23*4882a593Smuzhiyun 	case CAPI_CTR_LOADING:	return "loading";
24*4882a593Smuzhiyun 	case CAPI_CTR_RUNNING:	return "running";
25*4882a593Smuzhiyun 	default:	        return "???";
26*4882a593Smuzhiyun 	}
27*4882a593Smuzhiyun }
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun // /proc/capi
30*4882a593Smuzhiyun // ===========================================================================
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun // /proc/capi/controller:
33*4882a593Smuzhiyun //      cnr driver cardstate name driverinfo
34*4882a593Smuzhiyun // /proc/capi/contrstats:
35*4882a593Smuzhiyun //      cnr nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
36*4882a593Smuzhiyun // ---------------------------------------------------------------------------
37*4882a593Smuzhiyun 
controller_start(struct seq_file * seq,loff_t * pos)38*4882a593Smuzhiyun static void *controller_start(struct seq_file *seq, loff_t *pos)
39*4882a593Smuzhiyun 	__acquires(capi_controller_lock)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	mutex_lock(&capi_controller_lock);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	if (*pos < CAPI_MAXCONTR)
44*4882a593Smuzhiyun 		return &capi_controller[*pos];
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	return NULL;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
controller_next(struct seq_file * seq,void * v,loff_t * pos)49*4882a593Smuzhiyun static void *controller_next(struct seq_file *seq, void *v, loff_t *pos)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun 	++*pos;
52*4882a593Smuzhiyun 	if (*pos < CAPI_MAXCONTR)
53*4882a593Smuzhiyun 		return &capi_controller[*pos];
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	return NULL;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
controller_stop(struct seq_file * seq,void * v)58*4882a593Smuzhiyun static void controller_stop(struct seq_file *seq, void *v)
59*4882a593Smuzhiyun 	__releases(capi_controller_lock)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	mutex_unlock(&capi_controller_lock);
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun 
controller_show(struct seq_file * seq,void * v)64*4882a593Smuzhiyun static int controller_show(struct seq_file *seq, void *v)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	struct capi_ctr *ctr = *(struct capi_ctr **) v;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	if (!ctr)
69*4882a593Smuzhiyun 		return 0;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	seq_printf(seq, "%d %-10s %-8s %-16s %s\n",
72*4882a593Smuzhiyun 		   ctr->cnr, ctr->driver_name,
73*4882a593Smuzhiyun 		   state2str(ctr->state),
74*4882a593Smuzhiyun 		   ctr->name,
75*4882a593Smuzhiyun 		   ctr->procinfo ?  ctr->procinfo(ctr) : "");
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	return 0;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
contrstats_show(struct seq_file * seq,void * v)80*4882a593Smuzhiyun static int contrstats_show(struct seq_file *seq, void *v)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun 	struct capi_ctr *ctr = *(struct capi_ctr **) v;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	if (!ctr)
85*4882a593Smuzhiyun 		return 0;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	seq_printf(seq, "%d %lu %lu %lu %lu\n",
88*4882a593Smuzhiyun 		   ctr->cnr,
89*4882a593Smuzhiyun 		   ctr->nrecvctlpkt,
90*4882a593Smuzhiyun 		   ctr->nrecvdatapkt,
91*4882a593Smuzhiyun 		   ctr->nsentctlpkt,
92*4882a593Smuzhiyun 		   ctr->nsentdatapkt);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	return 0;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun static const struct seq_operations seq_controller_ops = {
98*4882a593Smuzhiyun 	.start	= controller_start,
99*4882a593Smuzhiyun 	.next	= controller_next,
100*4882a593Smuzhiyun 	.stop	= controller_stop,
101*4882a593Smuzhiyun 	.show	= controller_show,
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun static const struct seq_operations seq_contrstats_ops = {
105*4882a593Smuzhiyun 	.start	= controller_start,
106*4882a593Smuzhiyun 	.next	= controller_next,
107*4882a593Smuzhiyun 	.stop	= controller_stop,
108*4882a593Smuzhiyun 	.show	= contrstats_show,
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun // /proc/capi/applications:
112*4882a593Smuzhiyun //      applid l3cnt dblkcnt dblklen #ncci recvqueuelen
113*4882a593Smuzhiyun // /proc/capi/applstats:
114*4882a593Smuzhiyun //      applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt
115*4882a593Smuzhiyun // ---------------------------------------------------------------------------
116*4882a593Smuzhiyun 
applications_start(struct seq_file * seq,loff_t * pos)117*4882a593Smuzhiyun static void *applications_start(struct seq_file *seq, loff_t *pos)
118*4882a593Smuzhiyun 	__acquires(capi_controller_lock)
119*4882a593Smuzhiyun {
120*4882a593Smuzhiyun 	mutex_lock(&capi_controller_lock);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	if (*pos < CAPI_MAXAPPL)
123*4882a593Smuzhiyun 		return &capi_applications[*pos];
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	return NULL;
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun static void *
applications_next(struct seq_file * seq,void * v,loff_t * pos)129*4882a593Smuzhiyun applications_next(struct seq_file *seq, void *v, loff_t *pos)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	++*pos;
132*4882a593Smuzhiyun 	if (*pos < CAPI_MAXAPPL)
133*4882a593Smuzhiyun 		return &capi_applications[*pos];
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	return NULL;
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun 
applications_stop(struct seq_file * seq,void * v)138*4882a593Smuzhiyun static void applications_stop(struct seq_file *seq, void *v)
139*4882a593Smuzhiyun 	__releases(capi_controller_lock)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun 	mutex_unlock(&capi_controller_lock);
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun static int
applications_show(struct seq_file * seq,void * v)145*4882a593Smuzhiyun applications_show(struct seq_file *seq, void *v)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun 	struct capi20_appl *ap = *(struct capi20_appl **) v;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	if (!ap)
150*4882a593Smuzhiyun 		return 0;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	seq_printf(seq, "%u %d %d %d\n",
153*4882a593Smuzhiyun 		   ap->applid,
154*4882a593Smuzhiyun 		   ap->rparam.level3cnt,
155*4882a593Smuzhiyun 		   ap->rparam.datablkcnt,
156*4882a593Smuzhiyun 		   ap->rparam.datablklen);
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	return 0;
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun static int
applstats_show(struct seq_file * seq,void * v)162*4882a593Smuzhiyun applstats_show(struct seq_file *seq, void *v)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun 	struct capi20_appl *ap = *(struct capi20_appl **) v;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	if (!ap)
167*4882a593Smuzhiyun 		return 0;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 	seq_printf(seq, "%u %lu %lu %lu %lu\n",
170*4882a593Smuzhiyun 		   ap->applid,
171*4882a593Smuzhiyun 		   ap->nrecvctlpkt,
172*4882a593Smuzhiyun 		   ap->nrecvdatapkt,
173*4882a593Smuzhiyun 		   ap->nsentctlpkt,
174*4882a593Smuzhiyun 		   ap->nsentdatapkt);
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	return 0;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun static const struct seq_operations seq_applications_ops = {
180*4882a593Smuzhiyun 	.start	= applications_start,
181*4882a593Smuzhiyun 	.next	= applications_next,
182*4882a593Smuzhiyun 	.stop	= applications_stop,
183*4882a593Smuzhiyun 	.show	= applications_show,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun static const struct seq_operations seq_applstats_ops = {
187*4882a593Smuzhiyun 	.start	= applications_start,
188*4882a593Smuzhiyun 	.next	= applications_next,
189*4882a593Smuzhiyun 	.stop	= applications_stop,
190*4882a593Smuzhiyun 	.show	= applstats_show,
191*4882a593Smuzhiyun };
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun // ---------------------------------------------------------------------------
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun /* /proc/capi/drivers is always empty */
empty_read(struct file * file,char __user * buf,size_t size,loff_t * off)196*4882a593Smuzhiyun static ssize_t empty_read(struct file *file, char __user *buf,
197*4882a593Smuzhiyun 			  size_t size, loff_t *off)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun 	return 0;
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun static const struct proc_ops empty_proc_ops = {
203*4882a593Smuzhiyun 	.proc_read	= empty_read,
204*4882a593Smuzhiyun };
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun // ---------------------------------------------------------------------------
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun void __init
kcapi_proc_init(void)209*4882a593Smuzhiyun kcapi_proc_init(void)
210*4882a593Smuzhiyun {
211*4882a593Smuzhiyun 	proc_mkdir("capi",             NULL);
212*4882a593Smuzhiyun 	proc_mkdir("capi/controllers", NULL);
213*4882a593Smuzhiyun 	proc_create_seq("capi/controller",   0, NULL, &seq_controller_ops);
214*4882a593Smuzhiyun 	proc_create_seq("capi/contrstats",   0, NULL, &seq_contrstats_ops);
215*4882a593Smuzhiyun 	proc_create_seq("capi/applications", 0, NULL, &seq_applications_ops);
216*4882a593Smuzhiyun 	proc_create_seq("capi/applstats",    0, NULL, &seq_applstats_ops);
217*4882a593Smuzhiyun 	proc_create("capi/driver",           0, NULL, &empty_proc_ops);
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun void
kcapi_proc_exit(void)221*4882a593Smuzhiyun kcapi_proc_exit(void)
222*4882a593Smuzhiyun {
223*4882a593Smuzhiyun 	remove_proc_entry("capi/driver",       NULL);
224*4882a593Smuzhiyun 	remove_proc_entry("capi/controller",   NULL);
225*4882a593Smuzhiyun 	remove_proc_entry("capi/contrstats",   NULL);
226*4882a593Smuzhiyun 	remove_proc_entry("capi/applications", NULL);
227*4882a593Smuzhiyun 	remove_proc_entry("capi/applstats",    NULL);
228*4882a593Smuzhiyun 	remove_proc_entry("capi/controllers",  NULL);
229*4882a593Smuzhiyun 	remove_proc_entry("capi",              NULL);
230*4882a593Smuzhiyun }
231