[PATCH] firmware/efivars: handle error
[linux-2.6.22.y-op.git] / net / 8021q / vlanproc.c
bloba8fc0de1f969a89e15382c54fd675e53f3eccd72
1 /******************************************************************************
2 * vlanproc.c VLAN Module. /proc filesystem interface.
4 * This module is completely hardware-independent and provides
5 * access to the router using Linux /proc filesystem.
7 * Author: Ben Greear, <greearb@candelatech.com> coppied from wanproc.c
8 * by: Gene Kozin <genek@compuserve.com>
10 * Copyright: (c) 1998 Ben Greear
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 * ============================================================================
17 * Jan 20, 1998 Ben Greear Initial Version
18 *****************************************************************************/
20 #include <linux/module.h>
21 #include <linux/stddef.h> /* offsetof(), etc. */
22 #include <linux/errno.h> /* return codes */
23 #include <linux/kernel.h>
24 #include <linux/slab.h> /* kmalloc(), kfree() */
25 #include <linux/mm.h>
26 #include <linux/string.h> /* inline mem*, str* functions */
27 #include <linux/init.h> /* __initfunc et al. */
28 #include <asm/byteorder.h> /* htons(), etc. */
29 #include <asm/uaccess.h> /* copy_to_user */
30 #include <asm/io.h>
31 #include <linux/proc_fs.h>
32 #include <linux/seq_file.h>
33 #include <linux/fs.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_vlan.h>
36 #include "vlanproc.h"
37 #include "vlan.h"
39 /****** Function Prototypes *************************************************/
41 /* Methods for preparing data for reading proc entries */
42 static int vlan_seq_show(struct seq_file *seq, void *v);
43 static void *vlan_seq_start(struct seq_file *seq, loff_t *pos);
44 static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos);
45 static void vlan_seq_stop(struct seq_file *seq, void *);
46 static int vlandev_seq_show(struct seq_file *seq, void *v);
49 * Global Data
54 * Names of the proc directory entries
57 static const char name_root[] = "vlan";
58 static const char name_conf[] = "config";
61 * Structures for interfacing with the /proc filesystem.
62 * VLAN creates its own directory /proc/net/vlan with the folowing
63 * entries:
64 * config device status/configuration
65 * <device> entry for each device
69 * Generic /proc/net/vlan/<file> file and inode operations
72 static struct seq_operations vlan_seq_ops = {
73 .start = vlan_seq_start,
74 .next = vlan_seq_next,
75 .stop = vlan_seq_stop,
76 .show = vlan_seq_show,
79 static int vlan_seq_open(struct inode *inode, struct file *file)
81 return seq_open(file, &vlan_seq_ops);
84 static struct file_operations vlan_fops = {
85 .owner = THIS_MODULE,
86 .open = vlan_seq_open,
87 .read = seq_read,
88 .llseek = seq_lseek,
89 .release = seq_release,
93 * /proc/net/vlan/<device> file and inode operations
96 static int vlandev_seq_open(struct inode *inode, struct file *file)
98 return single_open(file, vlandev_seq_show, PDE(inode)->data);
101 static struct file_operations vlandev_fops = {
102 .owner = THIS_MODULE,
103 .open = vlandev_seq_open,
104 .read = seq_read,
105 .llseek = seq_lseek,
106 .release = single_release,
110 * Proc filesystem derectory entries.
114 * /proc/net/vlan
117 static struct proc_dir_entry *proc_vlan_dir;
120 * /proc/net/vlan/config
123 static struct proc_dir_entry *proc_vlan_conf;
125 /* Strings */
126 static const char *vlan_name_type_str[VLAN_NAME_TYPE_HIGHEST] = {
127 [VLAN_NAME_TYPE_RAW_PLUS_VID] = "VLAN_NAME_TYPE_RAW_PLUS_VID",
128 [VLAN_NAME_TYPE_PLUS_VID_NO_PAD] = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD",
129 [VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD]= "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD",
130 [VLAN_NAME_TYPE_PLUS_VID] = "VLAN_NAME_TYPE_PLUS_VID",
133 * Interface functions
137 * Clean up /proc/net/vlan entries
140 void vlan_proc_cleanup(void)
142 if (proc_vlan_conf)
143 remove_proc_entry(name_conf, proc_vlan_dir);
145 if (proc_vlan_dir)
146 proc_net_remove(name_root);
148 /* Dynamically added entries should be cleaned up as their vlan_device
149 * is removed, so we should not have to take care of it here...
154 * Create /proc/net/vlan entries
157 int __init vlan_proc_init(void)
159 proc_vlan_dir = proc_mkdir(name_root, proc_net);
160 if (proc_vlan_dir) {
161 proc_vlan_conf = create_proc_entry(name_conf,
162 S_IFREG|S_IRUSR|S_IWUSR,
163 proc_vlan_dir);
164 if (proc_vlan_conf) {
165 proc_vlan_conf->proc_fops = &vlan_fops;
166 return 0;
169 vlan_proc_cleanup();
170 return -ENOBUFS;
174 * Add directory entry for VLAN device.
177 int vlan_proc_add_dev (struct net_device *vlandev)
179 struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
181 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
182 printk(KERN_ERR
183 "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n",
184 vlandev->name);
185 return -EINVAL;
188 dev_info->dent = create_proc_entry(vlandev->name,
189 S_IFREG|S_IRUSR|S_IWUSR,
190 proc_vlan_dir);
191 if (!dev_info->dent)
192 return -ENOBUFS;
194 dev_info->dent->proc_fops = &vlandev_fops;
195 dev_info->dent->data = vlandev;
197 #ifdef VLAN_DEBUG
198 printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n",
199 vlandev->name);
200 #endif
201 return 0;
205 * Delete directory entry for VLAN device.
207 int vlan_proc_rem_dev(struct net_device *vlandev)
209 if (!vlandev) {
210 printk(VLAN_ERR "%s: invalid argument: %p\n",
211 __FUNCTION__, vlandev);
212 return -EINVAL;
215 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
216 printk(VLAN_DBG "%s: invalid argument, device: %s is not a VLAN device, priv_flags: 0x%4hX.\n",
217 __FUNCTION__, vlandev->name, vlandev->priv_flags);
218 return -EINVAL;
221 #ifdef VLAN_DEBUG
222 printk(VLAN_DBG "%s: dev: %p\n", __FUNCTION__, vlandev);
223 #endif
225 /** NOTE: This will consume the memory pointed to by dent, it seems. */
226 if (VLAN_DEV_INFO(vlandev)->dent) {
227 remove_proc_entry(VLAN_DEV_INFO(vlandev)->dent->name, proc_vlan_dir);
228 VLAN_DEV_INFO(vlandev)->dent = NULL;
231 return 0;
234 /****** Proc filesystem entry points ****************************************/
237 * The following few functions build the content of /proc/net/vlan/config
240 /* starting at dev, find a VLAN device */
241 static struct net_device *vlan_skip(struct net_device *dev)
243 while (dev && !(dev->priv_flags & IFF_802_1Q_VLAN))
244 dev = dev->next;
246 return dev;
249 /* start read of /proc/net/vlan/config */
250 static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
252 struct net_device *dev;
253 loff_t i = 1;
255 read_lock(&dev_base_lock);
257 if (*pos == 0)
258 return SEQ_START_TOKEN;
260 for (dev = vlan_skip(dev_base); dev && i < *pos;
261 dev = vlan_skip(dev->next), ++i);
263 return (i == *pos) ? dev : NULL;
266 static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
268 ++*pos;
270 return vlan_skip((v == SEQ_START_TOKEN)
271 ? dev_base
272 : ((struct net_device *)v)->next);
275 static void vlan_seq_stop(struct seq_file *seq, void *v)
277 read_unlock(&dev_base_lock);
280 static int vlan_seq_show(struct seq_file *seq, void *v)
282 if (v == SEQ_START_TOKEN) {
283 const char *nmtype = NULL;
285 seq_puts(seq, "VLAN Dev name | VLAN ID\n");
287 if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str))
288 nmtype = vlan_name_type_str[vlan_name_type];
290 seq_printf(seq, "Name-Type: %s\n",
291 nmtype ? nmtype : "UNKNOWN" );
292 } else {
293 const struct net_device *vlandev = v;
294 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
296 seq_printf(seq, "%-15s| %d | %s\n", vlandev->name,
297 dev_info->vlan_id, dev_info->real_dev->name);
299 return 0;
302 static int vlandev_seq_show(struct seq_file *seq, void *offset)
304 struct net_device *vlandev = (struct net_device *) seq->private;
305 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
306 struct net_device_stats *stats;
307 static const char fmt[] = "%30s %12lu\n";
308 int i;
310 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
311 return 0;
313 seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
314 vlandev->name, dev_info->vlan_id,
315 (int)(dev_info->flags & 1), vlandev->priv_flags);
318 stats = vlan_dev_get_stats(vlandev);
320 seq_printf(seq, fmt, "total frames received", stats->rx_packets);
321 seq_printf(seq, fmt, "total bytes received", stats->rx_bytes);
322 seq_printf(seq, fmt, "Broadcast/Multicast Rcvd", stats->multicast);
323 seq_puts(seq, "\n");
324 seq_printf(seq, fmt, "total frames transmitted", stats->tx_packets);
325 seq_printf(seq, fmt, "total bytes transmitted", stats->tx_bytes);
326 seq_printf(seq, fmt, "total headroom inc",
327 dev_info->cnt_inc_headroom_on_tx);
328 seq_printf(seq, fmt, "total encap on xmit",
329 dev_info->cnt_encap_on_xmit);
330 seq_printf(seq, "Device: %s", dev_info->real_dev->name);
331 /* now show all PRIORITY mappings relating to this VLAN */
332 seq_printf(seq,
333 "\nINGRESS priority mappings: 0:%lu 1:%lu 2:%lu 3:%lu 4:%lu 5:%lu 6:%lu 7:%lu\n",
334 dev_info->ingress_priority_map[0],
335 dev_info->ingress_priority_map[1],
336 dev_info->ingress_priority_map[2],
337 dev_info->ingress_priority_map[3],
338 dev_info->ingress_priority_map[4],
339 dev_info->ingress_priority_map[5],
340 dev_info->ingress_priority_map[6],
341 dev_info->ingress_priority_map[7]);
343 seq_printf(seq, "EGRESSS priority Mappings: ");
344 for (i = 0; i < 16; i++) {
345 const struct vlan_priority_tci_mapping *mp
346 = dev_info->egress_priority_map[i];
347 while (mp) {
348 seq_printf(seq, "%lu:%hu ",
349 mp->priority, ((mp->vlan_qos >> 13) & 0x7));
350 mp = mp->next;
353 seq_puts(seq, "\n");
355 return 0;