datapath: Remove dead code.
[sliver-openvswitch.git] / datapath / dp_sysfs_if.c
1 /*
2  * Copyright (c) 2009, 2010 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 /*
10  *      Sysfs attributes of bridge ports for Open vSwitch
11  *
12  *  This has been shamelessly copied from the kernel sources.
13  */
14
15 #include <linux/capability.h>
16 #include <linux/kernel.h>
17 #include <linux/netdevice.h>
18 #include <linux/if_bridge.h>
19 #include <linux/rtnetlink.h>
20
21 #include "datapath.h"
22 #include "dp_sysfs.h"
23 #include "vport.h"
24
25 #ifdef CONFIG_SYSFS
26
27 struct brport_attribute {
28         struct attribute        attr;
29         ssize_t (*show)(struct dp_port *, char *);
30         ssize_t (*store)(struct dp_port *, unsigned long);
31 };
32
33 #define BRPORT_ATTR(_name,_mode,_show,_store)                   \
34 struct brport_attribute brport_attr_##_name = {                 \
35         .attr = {.name = __stringify(_name),                    \
36                  .mode = _mode,                                 \
37                  .owner = THIS_MODULE, },                       \
38         .show   = _show,                                        \
39         .store  = _store,                                       \
40 };
41
42 static ssize_t show_path_cost(struct dp_port *p, char *buf)
43 {
44         return sprintf(buf, "%d\n", 0);
45 }
46 static ssize_t store_path_cost(struct dp_port *p, unsigned long v)
47 {
48         return 0;
49 }
50 static BRPORT_ATTR(path_cost, S_IRUGO | S_IWUSR,
51                    show_path_cost, store_path_cost);
52
53 static ssize_t show_priority(struct dp_port *p, char *buf)
54 {
55         return sprintf(buf, "%d\n", 0);
56 }
57 static ssize_t store_priority(struct dp_port *p, unsigned long v)
58 {
59         return 0;
60 }
61 static BRPORT_ATTR(priority, S_IRUGO | S_IWUSR,
62                          show_priority, store_priority);
63
64 static ssize_t show_designated_root(struct dp_port *p, char *buf)
65 {
66         return sprintf(buf, "0000.010203040506\n");
67 }
68 static BRPORT_ATTR(designated_root, S_IRUGO, show_designated_root, NULL);
69
70 static ssize_t show_designated_bridge(struct dp_port *p, char *buf)
71 {
72         return sprintf(buf, "0000.060504030201\n");
73 }
74 static BRPORT_ATTR(designated_bridge, S_IRUGO, show_designated_bridge, NULL);
75
76 static ssize_t show_designated_port(struct dp_port *p, char *buf)
77 {
78         return sprintf(buf, "%d\n", 0);
79 }
80 static BRPORT_ATTR(designated_port, S_IRUGO, show_designated_port, NULL);
81
82 static ssize_t show_designated_cost(struct dp_port *p, char *buf)
83 {
84         return sprintf(buf, "%d\n", 0);
85 }
86 static BRPORT_ATTR(designated_cost, S_IRUGO, show_designated_cost, NULL);
87
88 static ssize_t show_port_id(struct dp_port *p, char *buf)
89 {
90         return sprintf(buf, "0x%x\n", 0);
91 }
92 static BRPORT_ATTR(port_id, S_IRUGO, show_port_id, NULL);
93
94 static ssize_t show_port_no(struct dp_port *p, char *buf)
95 {
96         return sprintf(buf, "0x%x\n", p->port_no);
97 }
98
99 static BRPORT_ATTR(port_no, S_IRUGO, show_port_no, NULL);
100
101 static ssize_t show_change_ack(struct dp_port *p, char *buf)
102 {
103         return sprintf(buf, "%d\n", 0);
104 }
105 static BRPORT_ATTR(change_ack, S_IRUGO, show_change_ack, NULL);
106
107 static ssize_t show_config_pending(struct dp_port *p, char *buf)
108 {
109         return sprintf(buf, "%d\n", 0);
110 }
111 static BRPORT_ATTR(config_pending, S_IRUGO, show_config_pending, NULL);
112
113 static ssize_t show_port_state(struct dp_port *p, char *buf)
114 {
115         return sprintf(buf, "%d\n", 0);
116 }
117 static BRPORT_ATTR(state, S_IRUGO, show_port_state, NULL);
118
119 static ssize_t show_message_age_timer(struct dp_port *p,
120                                             char *buf)
121 {
122         return sprintf(buf, "%d\n", 0);
123 }
124 static BRPORT_ATTR(message_age_timer, S_IRUGO, show_message_age_timer, NULL);
125
126 static ssize_t show_forward_delay_timer(struct dp_port *p,
127                                             char *buf)
128 {
129         return sprintf(buf, "%d\n", 0);
130 }
131 static BRPORT_ATTR(forward_delay_timer, S_IRUGO, show_forward_delay_timer, NULL);
132
133 static ssize_t show_hold_timer(struct dp_port *p,
134                                             char *buf)
135 {
136         return sprintf(buf, "%d\n", 0);
137 }
138 static BRPORT_ATTR(hold_timer, S_IRUGO, show_hold_timer, NULL);
139
140 static struct brport_attribute *brport_attrs[] = {
141         &brport_attr_path_cost,
142         &brport_attr_priority,
143         &brport_attr_port_id,
144         &brport_attr_port_no,
145         &brport_attr_designated_root,
146         &brport_attr_designated_bridge,
147         &brport_attr_designated_port,
148         &brport_attr_designated_cost,
149         &brport_attr_state,
150         &brport_attr_change_ack,
151         &brport_attr_config_pending,
152         &brport_attr_message_age_timer,
153         &brport_attr_forward_delay_timer,
154         &brport_attr_hold_timer,
155         NULL
156 };
157
158 #define to_brport_attr(_at) container_of(_at, struct brport_attribute, attr)
159 #define to_brport(obj)  container_of(obj, struct dp_port, kobj)
160
161 static ssize_t brport_show(struct kobject * kobj,
162                            struct attribute * attr, char * buf)
163 {
164         struct brport_attribute * brport_attr = to_brport_attr(attr);
165         struct dp_port * p = to_brport(kobj);
166
167         return brport_attr->show(p, buf);
168 }
169
170 static ssize_t brport_store(struct kobject * kobj,
171                             struct attribute * attr,
172                             const char * buf, size_t count)
173 {
174         struct dp_port * p = to_brport(kobj);
175         ssize_t ret = -EINVAL;
176
177         if (!capable(CAP_NET_ADMIN))
178                 return -EPERM;
179
180         printk("%s: xxx writing port parms not supported yet!\n", 
181                dp_name(p->dp));
182
183         return ret;
184 }
185
186 struct sysfs_ops brport_sysfs_ops = {
187         .show = brport_show,
188         .store = brport_store,
189 };
190
191 /*
192  * Add sysfs entries to ethernet device added to a bridge.
193  * Creates a brport subdirectory with bridge attributes.
194  * Puts symlink in bridge's brport subdirectory
195  */
196 int dp_sysfs_add_if(struct dp_port *p)
197 {
198         struct kobject *kobj = vport_get_kobj(p->vport);
199         struct datapath *dp = p->dp;
200         struct brport_attribute **a;
201         int err;
202
203         /* Create /sys/class/net/<devname>/brport directory. */
204         if (!kobj)
205                 return -ENOENT;
206
207         err = kobject_add(&p->kobj, kobj, SYSFS_BRIDGE_PORT_ATTR);
208         if (err)
209                 goto err;
210
211         /* Create symlink from /sys/class/net/<devname>/brport/bridge to
212          * /sys/class/net/<bridgename>. */
213         err = sysfs_create_link(&p->kobj, vport_get_kobj(dp->ports[ODPP_LOCAL]->vport),
214                                 SYSFS_BRIDGE_PORT_LINK); /* "bridge" */
215         if (err)
216                 goto err_del;
217
218         /* Populate /sys/class/net/<devname>/brport directory with files. */
219         for (a = brport_attrs; *a; ++a) {
220                 err = sysfs_create_file(&p->kobj, &((*a)->attr));
221                 if (err)
222                         goto err_del;
223         }
224
225         /* Create symlink from /sys/class/net/<bridgename>/brif/<devname> to
226          * /sys/class/net/<devname>/brport.  */
227         err = sysfs_create_link(&dp->ifobj, &p->kobj, vport_get_name(p->vport));
228         if (err)
229                 goto err_del;
230         strcpy(p->linkname, vport_get_name(p->vport));
231
232         kobject_uevent(&p->kobj, KOBJ_ADD);
233
234         return 0;
235
236 err_del:
237         kobject_del(&p->kobj);
238 err:
239         p->linkname[0] = 0;
240         return err;
241 }
242
243 int dp_sysfs_del_if(struct dp_port *p)
244 {
245         if (p->linkname[0]) {
246                 sysfs_remove_link(&p->dp->ifobj, p->linkname);
247                 kobject_uevent(&p->kobj, KOBJ_REMOVE);
248                 kobject_del(&p->kobj);
249                 p->linkname[0] = '\0';
250         }
251         return 0;
252 }
253 #endif /* CONFIG_SYSFS */