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 | |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 39 | static const struct proc_ops atm_dev_proc_ops = { |
| 40 | .proc_read = proc_dev_atm_read, |
| 41 | .proc_lseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | static void add_stats(struct seq_file *seq, const char *aal, |
| 45 | const struct k_atm_aal_stats *stats) |
| 46 | { |
| 47 | seq_printf(seq, "%s ( %d %d %d %d %d )", aal, |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 48 | atomic_read(&stats->tx), atomic_read(&stats->tx_err), |
| 49 | atomic_read(&stats->rx), atomic_read(&stats->rx_err), |
| 50 | atomic_read(&stats->rx_drop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev) |
| 54 | { |
| 55 | int i; |
| 56 | |
| 57 | seq_printf(seq, "%3d %-8s", dev->number, dev->type); |
| 58 | for (i = 0; i < ESI_LEN; i++) |
| 59 | seq_printf(seq, "%02x", dev->esi[i]); |
| 60 | seq_puts(seq, " "); |
| 61 | add_stats(seq, "0", &dev->stats.aal0); |
| 62 | seq_puts(seq, " "); |
| 63 | add_stats(seq, "5", &dev->stats.aal5); |
Reshetova, Elena | 458bc30 | 2017-07-04 15:53:01 +0300 | [diff] [blame] | 64 | seq_printf(seq, "\t[%d]", refcount_read(&dev->refcnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | seq_putc(seq, '\n'); |
| 66 | } |
| 67 | |
| 68 | struct vcc_state { |
| 69 | int bucket; |
| 70 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static inline int compare_family(struct sock *sk, int family) |
| 74 | { |
| 75 | return !family || (sk->sk_family == family); |
| 76 | } |
| 77 | |
| 78 | static int __vcc_walk(struct sock **sock, int family, int *bucket, loff_t l) |
| 79 | { |
| 80 | struct sock *sk = *sock; |
| 81 | |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 82 | if (sk == SEQ_START_TOKEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | for (*bucket = 0; *bucket < VCC_HTABLE_SIZE; ++*bucket) { |
| 84 | struct hlist_head *head = &vcc_hash[*bucket]; |
| 85 | |
| 86 | sk = hlist_empty(head) ? NULL : __sk_head(head); |
| 87 | if (sk) |
| 88 | break; |
| 89 | } |
| 90 | l--; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 91 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | try_again: |
| 93 | for (; sk; sk = sk_next(sk)) { |
| 94 | l -= compare_family(sk, family); |
| 95 | if (l < 0) |
| 96 | goto out; |
| 97 | } |
| 98 | if (!sk && ++*bucket < VCC_HTABLE_SIZE) { |
| 99 | sk = sk_head(&vcc_hash[*bucket]); |
| 100 | goto try_again; |
| 101 | } |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 102 | sk = SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | out: |
| 104 | *sock = sk; |
| 105 | return (l < 0); |
| 106 | } |
| 107 | |
Christoph Hellwig | a2d03aa | 2018-04-18 06:09:21 +0200 | [diff] [blame] | 108 | static inline void *vcc_walk(struct seq_file *seq, loff_t l) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Christoph Hellwig | a2d03aa | 2018-04-18 06:09:21 +0200 | [diff] [blame] | 110 | struct vcc_state *state = seq->private; |
| 111 | int family = (uintptr_t)(PDE_DATA(file_inode(seq->file))); |
| 112 | |
| 113 | return __vcc_walk(&state->sk, family, &state->bucket, l) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | state : NULL; |
| 115 | } |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static void *vcc_seq_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | 5c17d5f | 2008-01-15 03:29:50 -0800 | [diff] [blame] | 118 | __acquires(vcc_sklist_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
| 120 | struct vcc_state *state = seq->private; |
| 121 | loff_t left = *pos; |
| 122 | |
| 123 | read_lock(&vcc_sklist_lock); |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 124 | state->sk = SEQ_START_TOKEN; |
Christoph Hellwig | a2d03aa | 2018-04-18 06:09:21 +0200 | [diff] [blame] | 125 | return left ? vcc_walk(seq, left) : SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void vcc_seq_stop(struct seq_file *seq, void *v) |
Eric Dumazet | 5c17d5f | 2008-01-15 03:29:50 -0800 | [diff] [blame] | 129 | __releases(vcc_sklist_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | read_unlock(&vcc_sklist_lock); |
| 132 | } |
| 133 | |
| 134 | static void *vcc_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 135 | { |
Christoph Hellwig | a2d03aa | 2018-04-18 06:09:21 +0200 | [diff] [blame] | 136 | v = vcc_walk(seq, 1); |
Vasily Averin | 8bf7092 | 2020-01-23 10:11:20 +0300 | [diff] [blame] | 137 | (*pos)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return v; |
| 139 | } |
| 140 | |
| 141 | static void pvc_info(struct seq_file *seq, struct atm_vcc *vcc) |
| 142 | { |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 143 | static const char *const class_name[] = { |
| 144 | "off", "UBR", "CBR", "VBR", "ABR"}; |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 145 | static const char *const aal_name[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | "---", "1", "2", "3/4", /* 0- 3 */ |
| 147 | "???", "5", "???", "???", /* 4- 7 */ |
| 148 | "???", "???", "???", "???", /* 8-11 */ |
| 149 | "???", "0", "???", "???"}; /* 12-15 */ |
| 150 | |
| 151 | seq_printf(seq, "%3d %3d %5d %-3s %7d %-5s %7d %-6s", |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 152 | vcc->dev->number, vcc->vpi, vcc->vci, |
| 153 | vcc->qos.aal >= ARRAY_SIZE(aal_name) ? "err" : |
| 154 | aal_name[vcc->qos.aal], vcc->qos.rxtp.min_pcr, |
| 155 | class_name[vcc->qos.rxtp.traffic_class], |
| 156 | vcc->qos.txtp.min_pcr, |
| 157 | class_name[vcc->qos.txtp.traffic_class]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | if (test_bit(ATM_VF_IS_CLIP, &vcc->flags)) { |
| 159 | struct clip_vcc *clip_vcc = CLIP_VCC(vcc); |
| 160 | struct net_device *dev; |
| 161 | |
| 162 | dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL; |
| 163 | seq_printf(seq, "CLIP, Itf:%s, Encap:", |
| 164 | dev ? dev->name : "none?"); |
| 165 | seq_printf(seq, "%s", clip_vcc->encap ? "LLC/SNAP" : "None"); |
| 166 | } |
| 167 | seq_putc(seq, '\n'); |
| 168 | } |
| 169 | |
| 170 | static const char *vcc_state(struct atm_vcc *vcc) |
| 171 | { |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 172 | static const char *const map[] = { ATM_VS2TXT_MAP }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | return map[ATM_VF2VS(vcc->flags)]; |
| 175 | } |
| 176 | |
| 177 | static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc) |
| 178 | { |
| 179 | struct sock *sk = sk_atm(vcc); |
| 180 | |
Dan Rosenberg | 71338aa | 2011-05-23 12:17:35 +0000 | [diff] [blame] | 181 | seq_printf(seq, "%pK ", vcc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | if (!vcc->dev) |
| 183 | seq_printf(seq, "Unassigned "); |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 184 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | seq_printf(seq, "%3d %3d %5d ", vcc->dev->number, vcc->vpi, |
| 186 | vcc->vci); |
| 187 | switch (sk->sk_family) { |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 188 | case AF_ATMPVC: |
| 189 | seq_printf(seq, "PVC"); |
| 190 | break; |
| 191 | case AF_ATMSVC: |
| 192 | seq_printf(seq, "SVC"); |
| 193 | break; |
| 194 | default: |
| 195 | seq_printf(seq, "%3d", sk->sk_family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 197 | seq_printf(seq, " %04lx %5d %7d/%7d %7d/%7d [%d]\n", |
| 198 | vcc->flags, sk->sk_err, |
| 199 | sk_wmem_alloc_get(sk), sk->sk_sndbuf, |
| 200 | sk_rmem_alloc_get(sk), sk->sk_rcvbuf, |
Reshetova, Elena | 41c6d65 | 2017-06-30 13:08:01 +0300 | [diff] [blame] | 201 | refcount_read(&sk->sk_refcnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void svc_info(struct seq_file *seq, struct atm_vcc *vcc) |
| 205 | { |
| 206 | if (!vcc->dev) |
| 207 | seq_printf(seq, sizeof(void *) == 4 ? |
Dan Rosenberg | 71338aa | 2011-05-23 12:17:35 +0000 | [diff] [blame] | 208 | "N/A@%pK%10s" : "N/A@%pK%2s", vcc, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | else |
| 210 | seq_printf(seq, "%3d %3d %5d ", |
| 211 | vcc->dev->number, vcc->vpi, vcc->vci); |
| 212 | seq_printf(seq, "%-10s ", vcc_state(vcc)); |
| 213 | seq_printf(seq, "%s%s", vcc->remote.sas_addr.pub, |
| 214 | *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : ""); |
| 215 | if (*vcc->remote.sas_addr.prv) { |
| 216 | int i; |
| 217 | |
| 218 | for (i = 0; i < ATM_ESA_LEN; i++) |
| 219 | seq_printf(seq, "%02x", vcc->remote.sas_addr.prv[i]); |
| 220 | } |
| 221 | seq_putc(seq, '\n'); |
| 222 | } |
| 223 | |
| 224 | static int atm_dev_seq_show(struct seq_file *seq, void *v) |
| 225 | { |
| 226 | static char atm_dev_banner[] = |
| 227 | "Itf Type ESI/\"MAC\"addr " |
| 228 | "AAL(TX,err,RX,err,drop) ... [refcnt]\n"; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 229 | |
Li Zefan | 67de792 | 2010-02-08 23:21:51 +0000 | [diff] [blame] | 230 | if (v == &atm_devs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | seq_puts(seq, atm_dev_banner); |
| 232 | else { |
| 233 | struct atm_dev *dev = list_entry(v, struct atm_dev, dev_list); |
| 234 | |
| 235 | atm_dev_info(seq, dev); |
| 236 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 237 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 239 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 240 | static const struct seq_operations atm_dev_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | .start = atm_dev_seq_start, |
| 242 | .next = atm_dev_seq_next, |
| 243 | .stop = atm_dev_seq_stop, |
| 244 | .show = atm_dev_seq_show, |
| 245 | }; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | static int pvc_seq_show(struct seq_file *seq, void *v) |
| 248 | { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 249 | static char atm_pvc_banner[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | "Itf VPI VCI AAL RX(PCR,Class) TX(PCR,Class)\n"; |
| 251 | |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 252 | if (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | seq_puts(seq, atm_pvc_banner); |
| 254 | else { |
| 255 | struct vcc_state *state = seq->private; |
| 256 | struct atm_vcc *vcc = atm_sk(state->sk); |
| 257 | |
| 258 | pvc_info(seq, vcc); |
| 259 | } |
| 260 | return 0; |
| 261 | } |
| 262 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 263 | static const struct seq_operations pvc_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .start = vcc_seq_start, |
| 265 | .next = vcc_seq_next, |
| 266 | .stop = vcc_seq_stop, |
| 267 | .show = pvc_seq_show, |
| 268 | }; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | static int vcc_seq_show(struct seq_file *seq, void *v) |
| 271 | { |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 272 | if (v == SEQ_START_TOKEN) { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 273 | seq_printf(seq, sizeof(void *) == 4 ? "%-8s%s" : "%-16s%s", |
| 274 | "Address ", "Itf VPI VCI Fam Flags Reply " |
| 275 | "Send buffer Recv buffer [refcnt]\n"); |
| 276 | } else { |
| 277 | struct vcc_state *state = seq->private; |
| 278 | struct atm_vcc *vcc = atm_sk(state->sk); |
| 279 | |
| 280 | vcc_info(seq, vcc); |
| 281 | } |
| 282 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 284 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 285 | static const struct seq_operations vcc_seq_ops = { |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 286 | .start = vcc_seq_start, |
| 287 | .next = vcc_seq_next, |
| 288 | .stop = vcc_seq_stop, |
| 289 | .show = vcc_seq_show, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | }; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | static int svc_seq_show(struct seq_file *seq, void *v) |
| 293 | { |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 294 | static const char atm_svc_banner[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | "Itf VPI VCI State Remote\n"; |
| 296 | |
Joe Perches | 2e1e984 | 2008-04-10 03:33:03 -0700 | [diff] [blame] | 297 | if (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | seq_puts(seq, atm_svc_banner); |
| 299 | else { |
| 300 | struct vcc_state *state = seq->private; |
| 301 | struct atm_vcc *vcc = atm_sk(state->sk); |
| 302 | |
| 303 | svc_info(seq, vcc); |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 308 | static const struct seq_operations svc_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | .start = vcc_seq_start, |
| 310 | .next = vcc_seq_next, |
| 311 | .stop = vcc_seq_stop, |
| 312 | .show = svc_seq_show, |
| 313 | }; |
| 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | static ssize_t proc_dev_atm_read(struct file *file, char __user *buf, |
| 316 | size_t count, loff_t *pos) |
| 317 | { |
| 318 | struct atm_dev *dev; |
| 319 | unsigned long page; |
| 320 | int length; |
| 321 | |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 322 | if (count == 0) |
| 323 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | page = get_zeroed_page(GFP_KERNEL); |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 325 | if (!page) |
| 326 | return -ENOMEM; |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 327 | dev = PDE_DATA(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (!dev->ops->proc_read) |
| 329 | length = -EINVAL; |
| 330 | else { |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 331 | length = dev->ops->proc_read(dev, pos, (char *)page); |
| 332 | if (length > count) |
| 333 | length = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | if (length >= 0) { |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 336 | if (copy_to_user(buf, (char *)page, length)) |
| 337 | length = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | (*pos)++; |
| 339 | } |
| 340 | free_page(page); |
| 341 | return length; |
| 342 | } |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | struct proc_dir_entry *atm_proc_root; |
| 345 | EXPORT_SYMBOL(atm_proc_root); |
| 346 | |
| 347 | |
| 348 | int atm_proc_dev_register(struct atm_dev *dev) |
| 349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | int error; |
| 351 | |
| 352 | /* No proc info */ |
| 353 | if (!dev->ops->proc_read) |
| 354 | return 0; |
| 355 | |
| 356 | error = -ENOMEM; |
Eric Dumazet | 62c97ac | 2010-03-18 13:48:26 +0000 | [diff] [blame] | 357 | dev->proc_name = kasprintf(GFP_KERNEL, "%s:%d", dev->type, dev->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (!dev->proc_name) |
| 359 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Denis V. Lunev | 0c89652 | 2008-05-02 04:08:30 -0700 | [diff] [blame] | 361 | dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root, |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 362 | &atm_dev_proc_ops, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (!dev->proc_entry) |
| 364 | goto err_free_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return 0; |
Joe Perches | 07367ad | 2010-01-26 11:40:13 +0000 | [diff] [blame] | 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | err_free_name: |
| 368 | kfree(dev->proc_name); |
| 369 | err_out: |
| 370 | return error; |
| 371 | } |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | void atm_proc_dev_deregister(struct atm_dev *dev) |
| 374 | { |
| 375 | if (!dev->ops->proc_read) |
| 376 | return; |
| 377 | |
| 378 | remove_proc_entry(dev->proc_name, atm_proc_root); |
| 379 | kfree(dev->proc_name); |
| 380 | } |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | int __init atm_proc_init(void) |
| 383 | { |
Denis V. Lunev | e5d69b9 | 2008-01-10 03:51:41 -0800 | [diff] [blame] | 384 | 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] | 385 | if (!atm_proc_root) |
Christoph Hellwig | ce9fe43 | 2018-04-15 10:53:36 +0200 | [diff] [blame] | 386 | return -ENOMEM; |
| 387 | proc_create_seq("devices", 0444, atm_proc_root, &atm_dev_seq_ops); |
Christoph Hellwig | a2d03aa | 2018-04-18 06:09:21 +0200 | [diff] [blame] | 388 | proc_create_seq_private("pvc", 0444, atm_proc_root, &pvc_seq_ops, |
| 389 | sizeof(struct vcc_state), (void *)(uintptr_t)PF_ATMPVC); |
| 390 | proc_create_seq_private("svc", 0444, atm_proc_root, &svc_seq_ops, |
| 391 | sizeof(struct vcc_state), (void *)(uintptr_t)PF_ATMSVC); |
| 392 | proc_create_seq_private("vc", 0444, atm_proc_root, &vcc_seq_ops, |
| 393 | sizeof(struct vcc_state), NULL); |
Christoph Hellwig | ce9fe43 | 2018-04-15 10:53:36 +0200 | [diff] [blame] | 394 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Kevin Hilman | b9c6e3e | 2006-08-15 02:02:33 -0700 | [diff] [blame] | 397 | void atm_proc_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Christoph Hellwig | ce9fe43 | 2018-04-15 10:53:36 +0200 | [diff] [blame] | 399 | remove_proc_subtree("atm", init_net.proc_net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |