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