usb: free DMA mappings if enqueue fails
[linux-2.6/kmemtrace.git] / net / 8021q / vlanproc.c
blobc0040c9064a144a0f7afb3e47411eaed6ce13576
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 const 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 const 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 const 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 static inline int is_vlan_dev(struct net_device *dev)
242 return dev->priv_flags & IFF_802_1Q_VLAN;
245 /* start read of /proc/net/vlan/config */
246 static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
248 struct net_device *dev;
249 loff_t i = 1;
251 read_lock(&dev_base_lock);
253 if (*pos == 0)
254 return SEQ_START_TOKEN;
256 for_each_netdev(dev) {
257 if (!is_vlan_dev(dev))
258 continue;
260 if (i++ == *pos)
261 return dev;
264 return NULL;
267 static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
269 struct net_device *dev;
271 ++*pos;
273 dev = (struct net_device *)v;
274 if (v == SEQ_START_TOKEN)
275 dev = net_device_entry(&dev_base_head);
277 for_each_netdev_continue(dev) {
278 if (!is_vlan_dev(dev))
279 continue;
281 return dev;
284 return NULL;
287 static void vlan_seq_stop(struct seq_file *seq, void *v)
289 read_unlock(&dev_base_lock);
292 static int vlan_seq_show(struct seq_file *seq, void *v)
294 if (v == SEQ_START_TOKEN) {
295 const char *nmtype = NULL;
297 seq_puts(seq, "VLAN Dev name | VLAN ID\n");
299 if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str))
300 nmtype = vlan_name_type_str[vlan_name_type];
302 seq_printf(seq, "Name-Type: %s\n",
303 nmtype ? nmtype : "UNKNOWN" );
304 } else {
305 const struct net_device *vlandev = v;
306 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
308 seq_printf(seq, "%-15s| %d | %s\n", vlandev->name,
309 dev_info->vlan_id, dev_info->real_dev->name);
311 return 0;
314 static int vlandev_seq_show(struct seq_file *seq, void *offset)
316 struct net_device *vlandev = (struct net_device *) seq->private;
317 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
318 struct net_device_stats *stats;
319 static const char fmt[] = "%30s %12lu\n";
320 int i;
322 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
323 return 0;
325 seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
326 vlandev->name, dev_info->vlan_id,
327 (int)(dev_info->flags & 1), vlandev->priv_flags);
330 stats = vlan_dev_get_stats(vlandev);
332 seq_printf(seq, fmt, "total frames received", stats->rx_packets);
333 seq_printf(seq, fmt, "total bytes received", stats->rx_bytes);
334 seq_printf(seq, fmt, "Broadcast/Multicast Rcvd", stats->multicast);
335 seq_puts(seq, "\n");
336 seq_printf(seq, fmt, "total frames transmitted", stats->tx_packets);
337 seq_printf(seq, fmt, "total bytes transmitted", stats->tx_bytes);
338 seq_printf(seq, fmt, "total headroom inc",
339 dev_info->cnt_inc_headroom_on_tx);
340 seq_printf(seq, fmt, "total encap on xmit",
341 dev_info->cnt_encap_on_xmit);
342 seq_printf(seq, "Device: %s", dev_info->real_dev->name);
343 /* now show all PRIORITY mappings relating to this VLAN */
344 seq_printf(seq,
345 "\nINGRESS priority mappings: 0:%u 1:%u 2:%u 3:%u 4:%u 5:%u 6:%u 7:%u\n",
346 dev_info->ingress_priority_map[0],
347 dev_info->ingress_priority_map[1],
348 dev_info->ingress_priority_map[2],
349 dev_info->ingress_priority_map[3],
350 dev_info->ingress_priority_map[4],
351 dev_info->ingress_priority_map[5],
352 dev_info->ingress_priority_map[6],
353 dev_info->ingress_priority_map[7]);
355 seq_printf(seq, "EGRESSS priority Mappings: ");
356 for (i = 0; i < 16; i++) {
357 const struct vlan_priority_tci_mapping *mp
358 = dev_info->egress_priority_map[i];
359 while (mp) {
360 seq_printf(seq, "%u:%hu ",
361 mp->priority, ((mp->vlan_qos >> 13) & 0x7));
362 mp = mp->next;
365 seq_puts(seq, "\n");
367 return 0;