| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* net/atm/proc.c - ATM /proc interface | 
|  | 2 | * | 
|  | 3 | * Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA | 
|  | 4 | * | 
|  | 5 | * seq_file api usage by romieu@fr.zoreil.com | 
|  | 6 | * | 
|  | 7 | * Evaluating the efficiency of the whole thing if left as an exercise to | 
|  | 8 | * the reader. | 
|  | 9 | */ | 
|  | 10 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ | 
| Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 25 | #include <net/net_namespace.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <net/atmclip.h> | 
|  | 27 | #include <asm/uaccess.h> | 
|  | 28 | #include <asm/atomic.h> | 
|  | 29 | #include <asm/param.h> /* for HZ */ | 
|  | 30 | #include "resources.h" | 
|  | 31 | #include "common.h" /* atm_proc_init prototype */ | 
|  | 32 | #include "signaling.h" /* to get sigd - ugly too */ | 
|  | 33 |  | 
|  | 34 | static ssize_t proc_dev_atm_read(struct file *file,char __user *buf,size_t count, | 
|  | 35 | loff_t *pos); | 
|  | 36 |  | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 37 | static const struct file_operations proc_atm_dev_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | .owner =	THIS_MODULE, | 
|  | 39 | .read =		proc_dev_atm_read, | 
|  | 40 | }; | 
|  | 41 |  | 
|  | 42 | static void add_stats(struct seq_file *seq, const char *aal, | 
|  | 43 | const struct k_atm_aal_stats *stats) | 
|  | 44 | { | 
|  | 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)); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev) | 
|  | 52 | { | 
|  | 53 | int i; | 
|  | 54 |  | 
|  | 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'); | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | struct vcc_state { | 
|  | 67 | int bucket; | 
|  | 68 | struct sock *sk; | 
|  | 69 | int family; | 
|  | 70 | }; | 
|  | 71 |  | 
|  | 72 | static inline int compare_family(struct sock *sk, int family) | 
|  | 73 | { | 
|  | 74 | return !family || (sk->sk_family == family); | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | static int __vcc_walk(struct sock **sock, int family, int *bucket, loff_t l) | 
|  | 78 | { | 
|  | 79 | struct sock *sk = *sock; | 
|  | 80 |  | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 81 | if (sk == SEQ_START_TOKEN) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | for (*bucket = 0; *bucket < VCC_HTABLE_SIZE; ++*bucket) { | 
|  | 83 | struct hlist_head *head = &vcc_hash[*bucket]; | 
|  | 84 |  | 
|  | 85 | sk = hlist_empty(head) ? NULL : __sk_head(head); | 
|  | 86 | if (sk) | 
|  | 87 | break; | 
|  | 88 | } | 
|  | 89 | l--; | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 90 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | try_again: | 
|  | 92 | for (; sk; sk = sk_next(sk)) { | 
|  | 93 | l -= compare_family(sk, family); | 
|  | 94 | if (l < 0) | 
|  | 95 | goto out; | 
|  | 96 | } | 
|  | 97 | if (!sk && ++*bucket < VCC_HTABLE_SIZE) { | 
|  | 98 | sk = sk_head(&vcc_hash[*bucket]); | 
|  | 99 | goto try_again; | 
|  | 100 | } | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 101 | sk = SEQ_START_TOKEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | out: | 
|  | 103 | *sock = sk; | 
|  | 104 | return (l < 0); | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | static inline void *vcc_walk(struct vcc_state *state, loff_t l) | 
|  | 108 | { | 
|  | 109 | return __vcc_walk(&state->sk, state->family, &state->bucket, l) ? | 
|  | 110 | state : NULL; | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | static int __vcc_seq_open(struct inode *inode, struct file *file, | 
| Al Viro | ececfde | 2007-07-15 21:01:12 +0100 | [diff] [blame] | 114 | int family, const struct seq_operations *ops) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { | 
|  | 116 | struct vcc_state *state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 |  | 
| Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 118 | state = __seq_open_private(file, ops, sizeof(*state)); | 
|  | 119 | if (state == NULL) | 
|  | 120 | return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 |  | 
|  | 122 | state->family = family; | 
| Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 123 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
|  | 126 | static void *vcc_seq_start(struct seq_file *seq, loff_t *pos) | 
| Eric Dumazet | 5c17d5f | 2008-01-15 03:29:50 -0800 | [diff] [blame] | 127 | __acquires(vcc_sklist_lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { | 
|  | 129 | struct vcc_state *state = seq->private; | 
|  | 130 | loff_t left = *pos; | 
|  | 131 |  | 
|  | 132 | read_lock(&vcc_sklist_lock); | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 133 | state->sk = SEQ_START_TOKEN; | 
|  | 134 | return left ? vcc_walk(state, left) : SEQ_START_TOKEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
|  | 137 | static void vcc_seq_stop(struct seq_file *seq, void *v) | 
| Eric Dumazet | 5c17d5f | 2008-01-15 03:29:50 -0800 | [diff] [blame] | 138 | __releases(vcc_sklist_lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { | 
|  | 140 | read_unlock(&vcc_sklist_lock); | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 
|  | 144 | { | 
|  | 145 | struct vcc_state *state = seq->private; | 
|  | 146 |  | 
|  | 147 | v = vcc_walk(state, 1); | 
|  | 148 | *pos += !!PTR_ERR(v); | 
|  | 149 | return v; | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc) | 
|  | 153 | { | 
| Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 154 | static const char *const class_name[] = | 
|  | 155 | {"off","UBR","CBR","VBR","ABR"}; | 
|  | 156 | static const char *const aal_name[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | "---",	"1",	"2",	"3/4",	/*  0- 3 */ | 
|  | 158 | "???",	"5",	"???",	"???",	/*  4- 7 */ | 
|  | 159 | "???",	"???",	"???",	"???",	/*  8-11 */ | 
|  | 160 | "???",	"0",	"???",	"???"};	/* 12-15 */ | 
|  | 161 |  | 
|  | 162 | seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s", | 
|  | 163 | vcc->dev->number,vcc->vpi,vcc->vci, | 
| Denis Cheng | 8b14a53 | 2007-09-16 16:41:29 -0700 | [diff] [blame] | 164 | vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" : | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | aal_name[vcc->qos.aal],vcc->qos.rxtp.min_pcr, | 
|  | 166 | class_name[vcc->qos.rxtp.traffic_class],vcc->qos.txtp.min_pcr, | 
|  | 167 | class_name[vcc->qos.txtp.traffic_class]); | 
|  | 168 | if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) { | 
|  | 169 | struct clip_vcc *clip_vcc = CLIP_VCC(vcc); | 
|  | 170 | struct net_device *dev; | 
|  | 171 |  | 
|  | 172 | dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL; | 
|  | 173 | seq_printf(seq, "CLIP, Itf:%s, Encap:", | 
|  | 174 | dev ? dev->name : "none?"); | 
|  | 175 | seq_printf(seq, "%s", clip_vcc->encap ? "LLC/SNAP" : "None"); | 
|  | 176 | } | 
|  | 177 | seq_putc(seq, '\n'); | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | static const char *vcc_state(struct atm_vcc *vcc) | 
|  | 181 | { | 
| Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 182 | static const char *const map[] = { ATM_VS2TXT_MAP }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | return map[ATM_VF2VS(vcc->flags)]; | 
|  | 185 | } | 
|  | 186 |  | 
|  | 187 | static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc) | 
|  | 188 | { | 
|  | 189 | struct sock *sk = sk_atm(vcc); | 
|  | 190 |  | 
|  | 191 | seq_printf(seq, "%p ", vcc); | 
|  | 192 | if (!vcc->dev) | 
|  | 193 | seq_printf(seq, "Unassigned    "); | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 194 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi, | 
|  | 196 | vcc->vci); | 
|  | 197 | switch (sk->sk_family) { | 
|  | 198 | case AF_ATMPVC: | 
|  | 199 | seq_printf(seq, "PVC"); | 
|  | 200 | break; | 
|  | 201 | case AF_ATMSVC: | 
|  | 202 | seq_printf(seq, "SVC"); | 
|  | 203 | break; | 
|  | 204 | default: | 
|  | 205 | seq_printf(seq, "%3d", sk->sk_family); | 
|  | 206 | } | 
|  | 207 | seq_printf(seq, " %04lx  %5d %7d/%7d %7d/%7d [%d]\n", vcc->flags, sk->sk_err, | 
| Eric Dumazet | 81e2a3d | 2009-06-17 19:06:12 -0700 | [diff] [blame] | 208 | sk_wmem_alloc_get(sk), sk->sk_sndbuf, | 
|  | 209 | sk_rmem_alloc_get(sk), sk->sk_rcvbuf, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | atomic_read(&sk->sk_refcnt)); | 
|  | 211 | } | 
|  | 212 |  | 
|  | 213 | static void svc_info(struct seq_file *seq, struct atm_vcc *vcc) | 
|  | 214 | { | 
|  | 215 | if (!vcc->dev) | 
|  | 216 | seq_printf(seq, sizeof(void *) == 4 ? | 
|  | 217 | "N/A@%p%10s" : "N/A@%p%2s", vcc, ""); | 
|  | 218 | else | 
|  | 219 | seq_printf(seq, "%3d %3d %5d         ", | 
|  | 220 | vcc->dev->number, vcc->vpi, vcc->vci); | 
|  | 221 | seq_printf(seq, "%-10s ", vcc_state(vcc)); | 
|  | 222 | seq_printf(seq, "%s%s", vcc->remote.sas_addr.pub, | 
|  | 223 | *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : ""); | 
|  | 224 | if (*vcc->remote.sas_addr.prv) { | 
|  | 225 | int i; | 
|  | 226 |  | 
|  | 227 | for (i = 0; i < ATM_ESA_LEN; i++) | 
|  | 228 | seq_printf(seq, "%02x", vcc->remote.sas_addr.prv[i]); | 
|  | 229 | } | 
|  | 230 | seq_putc(seq, '\n'); | 
|  | 231 | } | 
|  | 232 |  | 
|  | 233 | static int atm_dev_seq_show(struct seq_file *seq, void *v) | 
|  | 234 | { | 
|  | 235 | static char atm_dev_banner[] = | 
|  | 236 | "Itf Type    ESI/\"MAC\"addr " | 
|  | 237 | "AAL(TX,err,RX,err,drop) ...               [refcnt]\n"; | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 238 |  | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 239 | if (v == SEQ_START_TOKEN) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | seq_puts(seq, atm_dev_banner); | 
|  | 241 | else { | 
|  | 242 | struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list); | 
|  | 243 |  | 
|  | 244 | atm_dev_info(seq, dev); | 
|  | 245 | } | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 246 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 248 |  | 
| Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 249 | static const struct seq_operations atm_dev_seq_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | .start	= atm_dev_seq_start, | 
|  | 251 | .next	= atm_dev_seq_next, | 
|  | 252 | .stop	= atm_dev_seq_stop, | 
|  | 253 | .show	= atm_dev_seq_show, | 
|  | 254 | }; | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 255 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | static int atm_dev_seq_open(struct inode *inode, struct file *file) | 
|  | 257 | { | 
|  | 258 | return seq_open(file, &atm_dev_seq_ops); | 
|  | 259 | } | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 260 |  | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 261 | static const struct file_operations devices_seq_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | .open		= atm_dev_seq_open, | 
|  | 263 | .read		= seq_read, | 
|  | 264 | .llseek		= seq_lseek, | 
|  | 265 | .release	= seq_release, | 
|  | 266 | }; | 
|  | 267 |  | 
|  | 268 | static int pvc_seq_show(struct seq_file *seq, void *v) | 
|  | 269 | { | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 270 | static char atm_pvc_banner[] = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | "Itf VPI VCI   AAL RX(PCR,Class) TX(PCR,Class)\n"; | 
|  | 272 |  | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 273 | if (v == SEQ_START_TOKEN) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | seq_puts(seq, atm_pvc_banner); | 
|  | 275 | else { | 
|  | 276 | struct vcc_state *state = seq->private; | 
|  | 277 | struct atm_vcc *vcc = atm_sk(state->sk); | 
|  | 278 |  | 
|  | 279 | pvc_info(seq, vcc); | 
|  | 280 | } | 
|  | 281 | return 0; | 
|  | 282 | } | 
|  | 283 |  | 
| Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 284 | static const struct seq_operations pvc_seq_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | .start	= vcc_seq_start, | 
|  | 286 | .next	= vcc_seq_next, | 
|  | 287 | .stop	= vcc_seq_stop, | 
|  | 288 | .show	= pvc_seq_show, | 
|  | 289 | }; | 
|  | 290 |  | 
|  | 291 | static int pvc_seq_open(struct inode *inode, struct file *file) | 
|  | 292 | { | 
|  | 293 | return __vcc_seq_open(inode, file, PF_ATMPVC, &pvc_seq_ops); | 
|  | 294 | } | 
|  | 295 |  | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 296 | static const struct file_operations pvc_seq_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | .open		= pvc_seq_open, | 
|  | 298 | .read		= seq_read, | 
|  | 299 | .llseek		= seq_lseek, | 
| Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 300 | .release	= seq_release_private, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | }; | 
|  | 302 |  | 
|  | 303 | static int vcc_seq_show(struct seq_file *seq, void *v) | 
|  | 304 | { | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 305 | if (v == SEQ_START_TOKEN) { | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 306 | seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s", | 
|  | 307 | "Address ", "Itf VPI VCI   Fam Flags Reply " | 
|  | 308 | "Send buffer     Recv buffer      [refcnt]\n"); | 
|  | 309 | } else { | 
|  | 310 | struct vcc_state *state = seq->private; | 
|  | 311 | struct atm_vcc *vcc = atm_sk(state->sk); | 
|  | 312 |  | 
|  | 313 | vcc_info(seq, vcc); | 
|  | 314 | } | 
|  | 315 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 317 |  | 
| Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 318 | static const struct seq_operations vcc_seq_ops = { | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 319 | .start	= vcc_seq_start, | 
|  | 320 | .next	= vcc_seq_next, | 
|  | 321 | .stop	= vcc_seq_stop, | 
|  | 322 | .show	= vcc_seq_show, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | }; | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 324 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | static int vcc_seq_open(struct inode *inode, struct file *file) | 
|  | 326 | { | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 327 | return __vcc_seq_open(inode, file, 0, &vcc_seq_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 329 |  | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 330 | static const struct file_operations vcc_seq_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | .open		= vcc_seq_open, | 
|  | 332 | .read		= seq_read, | 
|  | 333 | .llseek		= seq_lseek, | 
| Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 334 | .release	= seq_release_private, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | }; | 
|  | 336 |  | 
|  | 337 | static int svc_seq_show(struct seq_file *seq, void *v) | 
|  | 338 | { | 
| Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 339 | static const char atm_svc_banner[] = | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | "Itf VPI VCI           State      Remote\n"; | 
|  | 341 |  | 
| Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 342 | if (v == SEQ_START_TOKEN) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | seq_puts(seq, atm_svc_banner); | 
|  | 344 | else { | 
|  | 345 | struct vcc_state *state = seq->private; | 
|  | 346 | struct atm_vcc *vcc = atm_sk(state->sk); | 
|  | 347 |  | 
|  | 348 | svc_info(seq, vcc); | 
|  | 349 | } | 
|  | 350 | return 0; | 
|  | 351 | } | 
|  | 352 |  | 
| Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 353 | static const struct seq_operations svc_seq_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | .start	= vcc_seq_start, | 
|  | 355 | .next	= vcc_seq_next, | 
|  | 356 | .stop	= vcc_seq_stop, | 
|  | 357 | .show	= svc_seq_show, | 
|  | 358 | }; | 
|  | 359 |  | 
|  | 360 | static int svc_seq_open(struct inode *inode, struct file *file) | 
|  | 361 | { | 
|  | 362 | return __vcc_seq_open(inode, file, PF_ATMSVC, &svc_seq_ops); | 
|  | 363 | } | 
|  | 364 |  | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 365 | static const struct file_operations svc_seq_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | .open		= svc_seq_open, | 
|  | 367 | .read		= seq_read, | 
|  | 368 | .llseek		= seq_lseek, | 
| Pavel Emelyanov | 9a8c09e | 2008-02-29 11:37:02 -0800 | [diff] [blame] | 369 | .release	= seq_release_private, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | }; | 
|  | 371 |  | 
|  | 372 | static ssize_t proc_dev_atm_read(struct file *file, char __user *buf, | 
|  | 373 | size_t count, loff_t *pos) | 
|  | 374 | { | 
|  | 375 | struct atm_dev *dev; | 
|  | 376 | unsigned long page; | 
|  | 377 | int length; | 
|  | 378 |  | 
|  | 379 | if (count == 0) return 0; | 
|  | 380 | page = get_zeroed_page(GFP_KERNEL); | 
|  | 381 | if (!page) return -ENOMEM; | 
| Josef Sipek | 76a0f17 | 2006-12-08 02:36:52 -0800 | [diff] [blame] | 382 | dev = PDE(file->f_path.dentry->d_inode)->data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (!dev->ops->proc_read) | 
|  | 384 | length = -EINVAL; | 
|  | 385 | else { | 
|  | 386 | length = dev->ops->proc_read(dev,pos,(char *) page); | 
|  | 387 | if (length > count) length = -EINVAL; | 
|  | 388 | } | 
|  | 389 | if (length >= 0) { | 
|  | 390 | if (copy_to_user(buf,(char *) page,length)) length = -EFAULT; | 
|  | 391 | (*pos)++; | 
|  | 392 | } | 
|  | 393 | free_page(page); | 
|  | 394 | return length; | 
|  | 395 | } | 
|  | 396 |  | 
|  | 397 |  | 
|  | 398 | struct proc_dir_entry *atm_proc_root; | 
|  | 399 | EXPORT_SYMBOL(atm_proc_root); | 
|  | 400 |  | 
|  | 401 |  | 
|  | 402 | int atm_proc_dev_register(struct atm_dev *dev) | 
|  | 403 | { | 
|  | 404 | int digits,num; | 
|  | 405 | int error; | 
|  | 406 |  | 
|  | 407 | /* No proc info */ | 
|  | 408 | if (!dev->ops->proc_read) | 
|  | 409 | return 0; | 
|  | 410 |  | 
|  | 411 | error = -ENOMEM; | 
|  | 412 | digits = 0; | 
|  | 413 | for (num = dev->number; num; num /= 10) digits++; | 
|  | 414 | if (!digits) digits++; | 
|  | 415 |  | 
|  | 416 | dev->proc_name = kmalloc(strlen(dev->type) + digits + 2, GFP_KERNEL); | 
|  | 417 | if (!dev->proc_name) | 
|  | 418 | goto err_out; | 
|  | 419 | sprintf(dev->proc_name,"%s:%d",dev->type, dev->number); | 
|  | 420 |  | 
| Denis V. Lunev | 0c89652 | 2008-05-02 04:08:30 -0700 | [diff] [blame] | 421 | dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root, | 
|  | 422 | &proc_atm_dev_ops, dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (!dev->proc_entry) | 
|  | 424 | goto err_free_name; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return 0; | 
|  | 426 | err_free_name: | 
|  | 427 | kfree(dev->proc_name); | 
|  | 428 | err_out: | 
|  | 429 | return error; | 
|  | 430 | } | 
|  | 431 |  | 
|  | 432 |  | 
|  | 433 | void atm_proc_dev_deregister(struct atm_dev *dev) | 
|  | 434 | { | 
|  | 435 | if (!dev->ops->proc_read) | 
|  | 436 | return; | 
|  | 437 |  | 
|  | 438 | remove_proc_entry(dev->proc_name, atm_proc_root); | 
|  | 439 | kfree(dev->proc_name); | 
|  | 440 | } | 
|  | 441 |  | 
|  | 442 | static struct atm_proc_entry { | 
|  | 443 | char *name; | 
| Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 444 | const struct file_operations *proc_fops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | struct proc_dir_entry *dirent; | 
|  | 446 | } atm_proc_ents[] = { | 
|  | 447 | { .name = "devices",	.proc_fops = &devices_seq_fops }, | 
|  | 448 | { .name = "pvc",	.proc_fops = &pvc_seq_fops }, | 
|  | 449 | { .name = "svc",	.proc_fops = &svc_seq_fops }, | 
|  | 450 | { .name = "vc",		.proc_fops = &vcc_seq_fops }, | 
|  | 451 | { .name = NULL,		.proc_fops = NULL } | 
|  | 452 | }; | 
|  | 453 |  | 
|  | 454 | static void atm_proc_dirs_remove(void) | 
|  | 455 | { | 
|  | 456 | static struct atm_proc_entry *e; | 
|  | 457 |  | 
|  | 458 | for (e = atm_proc_ents; e->name; e++) { | 
| YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 459 | if (e->dirent) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | remove_proc_entry(e->name, atm_proc_root); | 
|  | 461 | } | 
| Denis V. Lunev | e5d69b9 | 2008-01-10 03:51:41 -0800 | [diff] [blame] | 462 | proc_net_remove(&init_net, "atm"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } | 
|  | 464 |  | 
|  | 465 | int __init atm_proc_init(void) | 
|  | 466 | { | 
|  | 467 | static struct atm_proc_entry *e; | 
|  | 468 | int ret; | 
|  | 469 |  | 
| Denis V. Lunev | e5d69b9 | 2008-01-10 03:51:41 -0800 | [diff] [blame] | 470 | atm_proc_root = proc_net_mkdir(&init_net, "atm", init_net.proc_net); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | if (!atm_proc_root) | 
|  | 472 | goto err_out; | 
|  | 473 | for (e = atm_proc_ents; e->name; e++) { | 
|  | 474 | struct proc_dir_entry *dirent; | 
|  | 475 |  | 
| Wang Chen | 16e297b | 2008-02-28 13:55:45 -0800 | [diff] [blame] | 476 | dirent = proc_create(e->name, S_IRUGO, | 
|  | 477 | atm_proc_root, e->proc_fops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | if (!dirent) | 
|  | 479 | goto err_out_remove; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | e->dirent = dirent; | 
|  | 481 | } | 
|  | 482 | ret = 0; | 
|  | 483 | out: | 
|  | 484 | return ret; | 
|  | 485 |  | 
|  | 486 | err_out_remove: | 
|  | 487 | atm_proc_dirs_remove(); | 
|  | 488 | err_out: | 
|  | 489 | ret = -ENOMEM; | 
|  | 490 | goto out; | 
|  | 491 | } | 
|  | 492 |  | 
| Kevin Hilman | b9c6e3e | 2006-08-15 02:02:33 -0700 | [diff] [blame] | 493 | void atm_proc_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { | 
|  | 495 | atm_proc_dirs_remove(); | 
|  | 496 | } |