KEYS: Add MAINTAINERS record
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / atm / proc.c
blob7a96b2376bd7223ad951e66a4ad441fccbb32d0d
1 /* net/atm/proc.c - ATM /proc interface
3 * Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA
5 * seq_file api usage by romieu@fr.zoreil.com
7 * Evaluating the efficiency of the whole thing if left as an exercise to
8 * the reader.
9 */
11 #include <linux/module.h> /* for EXPORT_SYMBOL */
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/mm.h>
15 #include <linux/fs.h>
16 #include <linux/stat.h>
17 #include <linux/proc_fs.h>
18 #include <linux/seq_file.h>
19 #include <linux/errno.h>
20 #include <linux/atm.h>
21 #include <linux/atmdev.h>
22 #include <linux/netdevice.h>
23 #include <linux/atmclip.h>
24 #include <linux/init.h> /* for __init */
25 #include <net/net_namespace.h>
26 #include <net/atmclip.h>
27 #include <linux/uaccess.h>
28 #include <linux/param.h> /* for HZ */
29 #include <asm/atomic.h>
30 #include "resources.h"
31 #include "common.h" /* atm_proc_init prototype */
32 #include "signaling.h" /* to get sigd - ugly too */
34 static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
35 size_t count, loff_t *pos);
37 static const struct file_operations proc_atm_dev_ops = {
38 .owner = THIS_MODULE,
39 .read = proc_dev_atm_read,
42 static void add_stats(struct seq_file *seq, const char *aal,
43 const struct k_atm_aal_stats *stats)
45 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
46 atomic_read(&stats->tx), atomic_read(&stats->tx_err),
47 atomic_read(&stats->rx), atomic_read(&stats->rx_err),
48 atomic_read(&stats->rx_drop));
51 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
53 int i;
55 seq_printf(seq, "%3d %-8s", dev->number, dev->type);
56 for (i = 0; i < ESI_LEN; i++)
57 seq_printf(seq, "%02x", dev->esi[i]);
58 seq_puts(seq, " ");
59 add_stats(seq, "0", &dev->stats.aal0);
60 seq_puts(seq, " ");
61 add_stats(seq, "5", &dev->stats.aal5);
62 seq_printf(seq, "\t[%d]", atomic_read(&dev->refcnt));
63 seq_putc(seq, '\n');
66 struct vcc_state {
67 int bucket;
68 struct sock *sk;
69 int family;
72 static inline int compare_family(struct sock *sk, int family)
74 return !family || (sk->sk_family == family);
77 static int __vcc_walk(struct sock **sock, int family, int *bucket, loff_t l)
79 struct sock *sk = *sock;
81 if (sk == SEQ_START_TOKEN) {
82 for (*bucket = 0; *bucket < VCC_HTABLE_SIZE; ++*bucket) {
83 struct hlist_head *head = &vcc_hash[*bucket];
85 sk = hlist_empty(head) ? NULL : __sk_head(head);
86 if (sk)
87 break;
89 l--;
91 try_again:
92 for (; sk; sk = sk_next(sk)) {
93 l -= compare_family(sk, family);
94 if (l < 0)
95 goto out;
97 if (!sk && ++*bucket < VCC_HTABLE_SIZE) {
98 sk = sk_head(&vcc_hash[*bucket]);
99 goto try_again;
101 sk = SEQ_START_TOKEN;
102 out:
103 *sock = sk;
104 return (l < 0);
107 static inline void *vcc_walk(struct vcc_state *state, loff_t l)
109 return __vcc_walk(&state->sk, state->family, &state->bucket, l) ?
110 state : NULL;
113 static int __vcc_seq_open(struct inode *inode, struct file *file,
114 int family, const struct seq_operations *ops)
116 struct vcc_state *state;
118 state = __seq_open_private(file, ops, sizeof(*state));
119 if (state == NULL)
120 return -ENOMEM;
122 state->family = family;
123 return 0;
126 static void *vcc_seq_start(struct seq_file *seq, loff_t *pos)
127 __acquires(vcc_sklist_lock)
129 struct vcc_state *state = seq->private;
130 loff_t left = *pos;
132 read_lock(&vcc_sklist_lock);
133 state->sk = SEQ_START_TOKEN;
134 return left ? vcc_walk(state, left) : SEQ_START_TOKEN;
137 static void vcc_seq_stop(struct seq_file *seq, void *v)
138 __releases(vcc_sklist_lock)
140 read_unlock(&vcc_sklist_lock);
143 static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
145 struct vcc_state *state = seq->private;
147 v = vcc_walk(state, 1);
148 *pos += !!PTR_ERR(v);
149 return v;
152 static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc)
154 static const char *const class_name[] = {
155 "off", "UBR", "CBR", "VBR", "ABR"};
156 static const char *const aal_name[] = {
157 "---", "1", "2", "3/4", /* 0- 3 */
158 "???", "5", "???", "???", /* 4- 7 */
159 "???", "???", "???", "???", /* 8-11 */
160 "???", "0", "???", "???"}; /* 12-15 */
162 seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s",
163 vcc->dev->number, vcc->vpi, vcc->vci,
164 vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" :
165 aal_name[vcc->qos.aal], vcc->qos.rxtp.min_pcr,
166 class_name[vcc->qos.rxtp.traffic_class],
167 vcc->qos.txtp.min_pcr,
168 class_name[vcc->qos.txtp.traffic_class]);
169 if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) {
170 struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
171 struct net_device *dev;
173 dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
174 seq_printf(seq, "CLIP, Itf:%s, Encap:",
175 dev ? dev->name : "none?");
176 seq_printf(seq, "%s", clip_vcc->encap ? "LLC/SNAP" : "None");
178 seq_putc(seq, '\n');
181 static const char *vcc_state(struct atm_vcc *vcc)
183 static const char *const map[] = { ATM_VS2TXT_MAP };
185 return map[ATM_VF2VS(vcc->flags)];
188 static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
190 struct sock *sk = sk_atm(vcc);
192 seq_printf(seq, "%p ", vcc);
193 if (!vcc->dev)
194 seq_printf(seq, "Unassigned ");
195 else
196 seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi,
197 vcc->vci);
198 switch (sk->sk_family) {
199 case AF_ATMPVC:
200 seq_printf(seq, "PVC");
201 break;
202 case AF_ATMSVC:
203 seq_printf(seq, "SVC");
204 break;
205 default:
206 seq_printf(seq, "%3d", sk->sk_family);
208 seq_printf(seq, " %04lx %5d %7d/%7d %7d/%7d [%d]\n",
209 vcc->flags, sk->sk_err,
210 sk_wmem_alloc_get(sk), sk->sk_sndbuf,
211 sk_rmem_alloc_get(sk), sk->sk_rcvbuf,
212 atomic_read(&sk->sk_refcnt));
215 static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
217 if (!vcc->dev)
218 seq_printf(seq, sizeof(void *) == 4 ?
219 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
220 else
221 seq_printf(seq, "%3d %3d %5d ",
222 vcc->dev->number, vcc->vpi, vcc->vci);
223 seq_printf(seq, "%-10s ", vcc_state(vcc));
224 seq_printf(seq, "%s%s", vcc->remote.sas_addr.pub,
225 *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : "");
226 if (*vcc->remote.sas_addr.prv) {
227 int i;
229 for (i = 0; i < ATM_ESA_LEN; i++)
230 seq_printf(seq, "%02x", vcc->remote.sas_addr.prv[i]);
232 seq_putc(seq, '\n');
235 static int atm_dev_seq_show(struct seq_file *seq, void *v)
237 static char atm_dev_banner[] =
238 "Itf Type ESI/\"MAC\"addr "
239 "AAL(TX,err,RX,err,drop) ... [refcnt]\n";
241 if (v == &atm_devs)
242 seq_puts(seq, atm_dev_banner);
243 else {
244 struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list);
246 atm_dev_info(seq, dev);
248 return 0;
251 static const struct seq_operations atm_dev_seq_ops = {
252 .start = atm_dev_seq_start,
253 .next = atm_dev_seq_next,
254 .stop = atm_dev_seq_stop,
255 .show = atm_dev_seq_show,
258 static int atm_dev_seq_open(struct inode *inode, struct file *file)
260 return seq_open(file, &atm_dev_seq_ops);
263 static const struct file_operations devices_seq_fops = {
264 .open = atm_dev_seq_open,
265 .read = seq_read,
266 .llseek = seq_lseek,
267 .release = seq_release,
270 static int pvc_seq_show(struct seq_file *seq, void *v)
272 static char atm_pvc_banner[] =
273 "Itf VPI VCI AAL RX(PCR,Class) TX(PCR,Class)\n";
275 if (v == SEQ_START_TOKEN)
276 seq_puts(seq, atm_pvc_banner);
277 else {
278 struct vcc_state *state = seq->private;
279 struct atm_vcc *vcc = atm_sk(state->sk);
281 pvc_info(seq, vcc);
283 return 0;
286 static const struct seq_operations pvc_seq_ops = {
287 .start = vcc_seq_start,
288 .next = vcc_seq_next,
289 .stop = vcc_seq_stop,
290 .show = pvc_seq_show,
293 static int pvc_seq_open(struct inode *inode, struct file *file)
295 return __vcc_seq_open(inode, file, PF_ATMPVC, &pvc_seq_ops);
298 static const struct file_operations pvc_seq_fops = {
299 .open = pvc_seq_open,
300 .read = seq_read,
301 .llseek = seq_lseek,
302 .release = seq_release_private,
305 static int vcc_seq_show(struct seq_file *seq, void *v)
307 if (v == SEQ_START_TOKEN) {
308 seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s",
309 "Address ", "Itf VPI VCI Fam Flags Reply "
310 "Send buffer Recv buffer [refcnt]\n");
311 } else {
312 struct vcc_state *state = seq->private;
313 struct atm_vcc *vcc = atm_sk(state->sk);
315 vcc_info(seq, vcc);
317 return 0;
320 static const struct seq_operations vcc_seq_ops = {
321 .start = vcc_seq_start,
322 .next = vcc_seq_next,
323 .stop = vcc_seq_stop,
324 .show = vcc_seq_show,
327 static int vcc_seq_open(struct inode *inode, struct file *file)
329 return __vcc_seq_open(inode, file, 0, &vcc_seq_ops);
332 static const struct file_operations vcc_seq_fops = {
333 .open = vcc_seq_open,
334 .read = seq_read,
335 .llseek = seq_lseek,
336 .release = seq_release_private,
339 static int svc_seq_show(struct seq_file *seq, void *v)
341 static const char atm_svc_banner[] =
342 "Itf VPI VCI State Remote\n";
344 if (v == SEQ_START_TOKEN)
345 seq_puts(seq, atm_svc_banner);
346 else {
347 struct vcc_state *state = seq->private;
348 struct atm_vcc *vcc = atm_sk(state->sk);
350 svc_info(seq, vcc);
352 return 0;
355 static const struct seq_operations svc_seq_ops = {
356 .start = vcc_seq_start,
357 .next = vcc_seq_next,
358 .stop = vcc_seq_stop,
359 .show = svc_seq_show,
362 static int svc_seq_open(struct inode *inode, struct file *file)
364 return __vcc_seq_open(inode, file, PF_ATMSVC, &svc_seq_ops);
367 static const struct file_operations svc_seq_fops = {
368 .open = svc_seq_open,
369 .read = seq_read,
370 .llseek = seq_lseek,
371 .release = seq_release_private,
374 static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
375 size_t count, loff_t *pos)
377 struct atm_dev *dev;
378 unsigned long page;
379 int length;
381 if (count == 0)
382 return 0;
383 page = get_zeroed_page(GFP_KERNEL);
384 if (!page)
385 return -ENOMEM;
386 dev = PDE(file->f_path.dentry->d_inode)->data;
387 if (!dev->ops->proc_read)
388 length = -EINVAL;
389 else {
390 length = dev->ops->proc_read(dev, pos, (char *)page);
391 if (length > count)
392 length = -EINVAL;
394 if (length >= 0) {
395 if (copy_to_user(buf, (char *)page, length))
396 length = -EFAULT;
397 (*pos)++;
399 free_page(page);
400 return length;
403 struct proc_dir_entry *atm_proc_root;
404 EXPORT_SYMBOL(atm_proc_root);
407 int atm_proc_dev_register(struct atm_dev *dev)
409 int digits, num;
410 int error;
412 /* No proc info */
413 if (!dev->ops->proc_read)
414 return 0;
416 error = -ENOMEM;
417 digits = 0;
418 for (num = dev->number; num; num /= 10)
419 digits++;
420 if (!digits)
421 digits++;
423 dev->proc_name = kmalloc(strlen(dev->type) + digits + 2, GFP_KERNEL);
424 if (!dev->proc_name)
425 goto err_out;
426 sprintf(dev->proc_name, "%s:%d", dev->type, dev->number);
428 dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root,
429 &proc_atm_dev_ops, dev);
430 if (!dev->proc_entry)
431 goto err_free_name;
432 return 0;
434 err_free_name:
435 kfree(dev->proc_name);
436 err_out:
437 return error;
440 void atm_proc_dev_deregister(struct atm_dev *dev)
442 if (!dev->ops->proc_read)
443 return;
445 remove_proc_entry(dev->proc_name, atm_proc_root);
446 kfree(dev->proc_name);
449 static struct atm_proc_entry {
450 char *name;
451 const struct file_operations *proc_fops;
452 struct proc_dir_entry *dirent;
453 } atm_proc_ents[] = {
454 { .name = "devices", .proc_fops = &devices_seq_fops },
455 { .name = "pvc", .proc_fops = &pvc_seq_fops },
456 { .name = "svc", .proc_fops = &svc_seq_fops },
457 { .name = "vc", .proc_fops = &vcc_seq_fops },
458 { .name = NULL, .proc_fops = NULL }
461 static void atm_proc_dirs_remove(void)
463 static struct atm_proc_entry *e;
465 for (e = atm_proc_ents; e->name; e++) {
466 if (e->dirent)
467 remove_proc_entry(e->name, atm_proc_root);
469 proc_net_remove(&init_net, "atm");
472 int __init atm_proc_init(void)
474 static struct atm_proc_entry *e;
475 int ret;
477 atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net);
478 if (!atm_proc_root)
479 goto err_out;
480 for (e = atm_proc_ents; e->name; e++) {
481 struct proc_dir_entry *dirent;
483 dirent = proc_create(e->name, S_IRUGO,
484 atm_proc_root, e->proc_fops);
485 if (!dirent)
486 goto err_out_remove;
487 e->dirent = dirent;
489 ret = 0;
490 out:
491 return ret;
493 err_out_remove:
494 atm_proc_dirs_remove();
495 err_out:
496 ret = -ENOMEM;
497 goto out;
500 void atm_proc_exit(void)
502 atm_proc_dirs_remove();