75c7dcfa912cc3b52a939cc997cc442adb1d3c29
[openwrt.git] / target / linux / generic-2.6 / files / include / linux / switch.h
1 /*
2 * switch.h: Switch configuration API
3 *
4 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17 #ifndef __LINUX_SWITCH_H
18 #define __LINUX_SWITCH_H
19
20 #include <linux/types.h>
21 #include <linux/netdevice.h>
22 #include <linux/netlink.h>
23 #include <linux/genetlink.h>
24 #ifndef __KERNEL__
25 #include <netlink/netlink.h>
26 #include <netlink/genl/genl.h>
27 #include <netlink/genl/ctrl.h>
28 #else
29 #include <net/genetlink.h>
30 #endif
31
32 /* main attributes */
33 enum {
34 SWITCH_ATTR_UNSPEC,
35 /* global */
36 SWITCH_ATTR_TYPE,
37 /* device */
38 SWITCH_ATTR_ID,
39 SWITCH_ATTR_NAME,
40 SWITCH_ATTR_DEV_NAME,
41 SWITCH_ATTR_VLANS,
42 SWITCH_ATTR_PORTS,
43 /* attributes */
44 SWITCH_ATTR_OP_ID,
45 SWITCH_ATTR_OP_TYPE,
46 SWITCH_ATTR_OP_NAME,
47 SWITCH_ATTR_OP_PORT,
48 SWITCH_ATTR_OP_VLAN,
49 SWITCH_ATTR_OP_VALUE_INT,
50 SWITCH_ATTR_OP_VALUE_STR,
51 SWITCH_ATTR_OP_VALUE_PORTS,
52 SWITCH_ATTR_OP_DESCRIPTION,
53 /* port lists */
54 SWITCH_ATTR_PORT,
55 SWITCH_ATTR_MAX
56 };
57
58 /* commands */
59 enum {
60 SWITCH_CMD_UNSPEC,
61 SWITCH_CMD_GET_SWITCH,
62 SWITCH_CMD_NEW_ATTR,
63 SWITCH_CMD_LIST_GLOBAL,
64 SWITCH_CMD_GET_GLOBAL,
65 SWITCH_CMD_SET_GLOBAL,
66 SWITCH_CMD_LIST_PORT,
67 SWITCH_CMD_GET_PORT,
68 SWITCH_CMD_SET_PORT,
69 SWITCH_CMD_LIST_VLAN,
70 SWITCH_CMD_GET_VLAN,
71 SWITCH_CMD_SET_VLAN
72 };
73
74 /* data types */
75 enum switch_val_type {
76 SWITCH_TYPE_UNSPEC,
77 SWITCH_TYPE_INT,
78 SWITCH_TYPE_STRING,
79 SWITCH_TYPE_PORTS,
80 SWITCH_TYPE_NOVAL,
81 };
82
83 /* port nested attributes */
84 enum {
85 SWITCH_PORT_UNSPEC,
86 SWITCH_PORT_ID,
87 SWITCH_PORT_FLAG_TAGGED,
88 SWITCH_PORT_ATTR_MAX
89 };
90
91 #define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000
92
93 #ifdef __KERNEL__
94
95 struct switch_dev;
96 struct switch_op;
97 struct switch_val;
98 struct switch_attr;
99 struct switch_attrlist;
100
101 int register_switch(struct switch_dev *dev, struct net_device *netdev);
102 void unregister_switch(struct switch_dev *dev);
103
104 struct switch_attrlist {
105 /* filled in by the driver */
106 int n_attr;
107 const struct switch_attr *attr;
108 };
109
110
111 struct switch_dev {
112 int id;
113 void *priv;
114 const char *name;
115
116 /* NB: either devname or netdev must be set */
117 const char *devname;
118 struct net_device *netdev;
119
120 int ports;
121 int vlans;
122 int cpu_port;
123 struct switch_attrlist attr_global, attr_port, attr_vlan;
124
125 spinlock_t lock;
126 struct switch_port *portbuf;
127 struct list_head dev_list;
128 unsigned long def_global, def_port, def_vlan;
129
130 int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
131 int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
132 int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
133 int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
134 int (*apply_config)(struct switch_dev *dev);
135 };
136
137 struct switch_port {
138 u32 id;
139 u32 flags;
140 };
141
142 struct switch_val {
143 const struct switch_attr *attr;
144 int port_vlan;
145 int len;
146 union {
147 const char *s;
148 u32 i;
149 struct switch_port *ports;
150 } value;
151 };
152
153 struct switch_attr {
154 int disabled;
155 int type;
156 const char *name;
157 const char *description;
158
159 int (*set)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
160 int (*get)(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val);
161
162 /* for driver internal use */
163 int id;
164 int ofs;
165 int max;
166 };
167
168 #endif
169
170 #endif
This page took 0.053398 seconds and 3 git commands to generate.