Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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