team: add broadcast mode
[linux-2.6-block.git] / include / linux / if_team.h
CommitLineData
3d249d4c
JP
1/*
2 * include/linux/if_team.h - Network team device driver header
3 * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#ifndef _LINUX_IF_TEAM_H_
12#define _LINUX_IF_TEAM_H_
13
14#ifdef __KERNEL__
15
16struct team_pcpu_stats {
17 u64 rx_packets;
18 u64 rx_bytes;
19 u64 rx_multicast;
20 u64 tx_packets;
21 u64 tx_bytes;
22 struct u64_stats_sync syncp;
23 u32 rx_dropped;
24 u32 tx_dropped;
25};
26
27struct team;
28
29struct team_port {
30 struct net_device *dev;
19a0b58e 31 struct hlist_node hlist; /* node in enabled ports hash list */
3d249d4c
JP
32 struct list_head list; /* node in ordinary list */
33 struct team *team;
19a0b58e 34 int index; /* index of enabled port. If disabled, it's set to -1 */
3d249d4c 35
71472ec1
JP
36 bool linkup; /* either state.linkup or user.linkup */
37
38 struct {
39 bool linkup;
40 u32 speed;
41 u8 duplex;
42 } state;
43
44 /* Values set by userspace */
45 struct {
46 bool linkup;
47 bool linkup_enabled;
48 } user;
49
50 /* Custom gennetlink interface related flags */
51 bool changed;
52 bool removed;
53
3d249d4c
JP
54 /*
55 * A place for storing original values of the device before it
56 * become a port.
57 */
58 struct {
59 unsigned char dev_addr[MAX_ADDR_LEN];
60 unsigned int mtu;
61 } orig;
62
5149ee58 63 long mode_priv[0];
3d249d4c
JP
64};
65
52a4fd77 66extern bool team_port_enabled(struct team_port *port);
6e88e135 67extern bool team_port_txable(struct team_port *port);
52a4fd77 68
3d249d4c
JP
69struct team_mode_ops {
70 int (*init)(struct team *team);
71 void (*exit)(struct team *team);
72 rx_handler_result_t (*receive)(struct team *team,
73 struct team_port *port,
74 struct sk_buff *skb);
75 bool (*transmit)(struct team *team, struct sk_buff *skb);
76 int (*port_enter)(struct team *team, struct team_port *port);
77 void (*port_leave)(struct team *team, struct team_port *port);
78 void (*port_change_mac)(struct team *team, struct team_port *port);
4bccfd17
JP
79 void (*port_enabled)(struct team *team, struct team_port *port);
80 void (*port_disabled)(struct team *team, struct team_port *port);
3d249d4c
JP
81};
82
83enum team_option_type {
84 TEAM_OPTION_TYPE_U32,
85 TEAM_OPTION_TYPE_STRING,
2615598f 86 TEAM_OPTION_TYPE_BINARY,
14f066ba 87 TEAM_OPTION_TYPE_BOOL,
3d249d4c
JP
88};
89
85d59a87
JP
90struct team_option_inst_info {
91 u32 array_index;
92 struct team_port *port; /* != NULL if per-port */
93};
94
80f7c668
JP
95struct team_gsetter_ctx {
96 union {
97 u32 u32_val;
98 const char *str_val;
99 struct {
100 const void *ptr;
101 u32 len;
102 } bin_val;
14f066ba 103 bool bool_val;
80f7c668 104 } data;
85d59a87 105 struct team_option_inst_info *info;
80f7c668
JP
106};
107
3d249d4c
JP
108struct team_option {
109 struct list_head list;
110 const char *name;
80f7c668 111 bool per_port;
b1303326 112 unsigned int array_size; /* != 0 means the option is array */
3d249d4c 113 enum team_option_type type;
85d59a87 114 int (*init)(struct team *team, struct team_option_inst_info *info);
80f7c668
JP
115 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
116 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
3d249d4c
JP
117};
118
0f1aad2b
JP
119extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info);
120extern void team_options_change_check(struct team *team);
121
3d249d4c 122struct team_mode {
3d249d4c
JP
123 const char *kind;
124 struct module *owner;
125 size_t priv_size;
5149ee58 126 size_t port_priv_size;
3d249d4c
JP
127 const struct team_mode_ops *ops;
128};
129
130#define TEAM_PORT_HASHBITS 4
131#define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
132
133#define TEAM_MODE_PRIV_LONGS 4
134#define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
135
136struct team {
137 struct net_device *dev; /* associated netdevice */
138 struct team_pcpu_stats __percpu *pcpu_stats;
139
61dc3461 140 struct mutex lock; /* used for overall locking, e.g. port lists write */
3d249d4c
JP
141
142 /*
19a0b58e 143 * List of enabled ports and their count
3d249d4c 144 */
19a0b58e
JP
145 int en_port_count;
146 struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
147
148 struct list_head port_list; /* list of all ports */
3d249d4c
JP
149
150 struct list_head option_list;
80f7c668 151 struct list_head option_inst_list; /* list of option instances */
3d249d4c
JP
152
153 const struct team_mode *mode;
154 struct team_mode_ops ops;
155 long mode_priv[TEAM_MODE_PRIV_LONGS];
156};
157
158static inline struct hlist_head *team_port_index_hash(struct team *team,
159 int port_index)
160{
19a0b58e 161 return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
3d249d4c
JP
162}
163
164static inline struct team_port *team_get_port_by_index(struct team *team,
165 int port_index)
166{
167 struct hlist_node *p;
168 struct team_port *port;
169 struct hlist_head *head = team_port_index_hash(team, port_index);
170
171 hlist_for_each_entry(port, p, head, hlist)
172 if (port->index == port_index)
173 return port;
174 return NULL;
175}
176static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
177 int port_index)
178{
179 struct hlist_node *p;
180 struct team_port *port;
181 struct hlist_head *head = team_port_index_hash(team, port_index);
182
183 hlist_for_each_entry_rcu(port, p, head, hlist)
184 if (port->index == port_index)
185 return port;
186 return NULL;
187}
188
189extern int team_port_set_team_mac(struct team_port *port);
358b8382
JP
190extern int team_options_register(struct team *team,
191 const struct team_option *option,
192 size_t option_count);
3d249d4c 193extern void team_options_unregister(struct team *team,
358b8382 194 const struct team_option *option,
3d249d4c 195 size_t option_count);
0402788a
JP
196extern int team_mode_register(const struct team_mode *mode);
197extern void team_mode_unregister(const struct team_mode *mode);
3d249d4c
JP
198
199#endif /* __KERNEL__ */
200
201#define TEAM_STRING_MAX_LEN 32
202
203/**********************************
204 * NETLINK_GENERIC netlink family.
205 **********************************/
206
207enum {
208 TEAM_CMD_NOOP,
209 TEAM_CMD_OPTIONS_SET,
210 TEAM_CMD_OPTIONS_GET,
211 TEAM_CMD_PORT_LIST_GET,
212
213 __TEAM_CMD_MAX,
214 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
215};
216
217enum {
218 TEAM_ATTR_UNSPEC,
219 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
220 TEAM_ATTR_LIST_OPTION, /* nest */
221 TEAM_ATTR_LIST_PORT, /* nest */
222
223 __TEAM_ATTR_MAX,
224 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
225};
226
227/* Nested layout of get/set msg:
228 *
229 * [TEAM_ATTR_LIST_OPTION]
230 * [TEAM_ATTR_ITEM_OPTION]
231 * [TEAM_ATTR_OPTION_*], ...
232 * [TEAM_ATTR_ITEM_OPTION]
233 * [TEAM_ATTR_OPTION_*], ...
234 * ...
235 * [TEAM_ATTR_LIST_PORT]
236 * [TEAM_ATTR_ITEM_PORT]
237 * [TEAM_ATTR_PORT_*], ...
238 * [TEAM_ATTR_ITEM_PORT]
239 * [TEAM_ATTR_PORT_*], ...
240 * ...
241 */
242
243enum {
244 TEAM_ATTR_ITEM_OPTION_UNSPEC,
245 TEAM_ATTR_ITEM_OPTION, /* nest */
246
247 __TEAM_ATTR_ITEM_OPTION_MAX,
248 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
249};
250
251enum {
252 TEAM_ATTR_OPTION_UNSPEC,
253 TEAM_ATTR_OPTION_NAME, /* string */
254 TEAM_ATTR_OPTION_CHANGED, /* flag */
255 TEAM_ATTR_OPTION_TYPE, /* u8 */
256 TEAM_ATTR_OPTION_DATA, /* dynamic */
b82b9183 257 TEAM_ATTR_OPTION_REMOVED, /* flag */
80f7c668 258 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
b1303326 259 TEAM_ATTR_OPTION_ARRAY_INDEX, /* u32 */ /* for array options */
3d249d4c
JP
260
261 __TEAM_ATTR_OPTION_MAX,
262 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
263};
264
265enum {
266 TEAM_ATTR_ITEM_PORT_UNSPEC,
267 TEAM_ATTR_ITEM_PORT, /* nest */
268
269 __TEAM_ATTR_ITEM_PORT_MAX,
270 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
271};
272
273enum {
274 TEAM_ATTR_PORT_UNSPEC,
275 TEAM_ATTR_PORT_IFINDEX, /* u32 */
276 TEAM_ATTR_PORT_CHANGED, /* flag */
277 TEAM_ATTR_PORT_LINKUP, /* flag */
278 TEAM_ATTR_PORT_SPEED, /* u32 */
279 TEAM_ATTR_PORT_DUPLEX, /* u8 */
b82b9183 280 TEAM_ATTR_PORT_REMOVED, /* flag */
3d249d4c
JP
281
282 __TEAM_ATTR_PORT_MAX,
283 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
284};
285
286/*
287 * NETLINK_GENERIC related info
288 */
289#define TEAM_GENL_NAME "team"
290#define TEAM_GENL_VERSION 0x1
291#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
292
293#endif /* _LINUX_IF_TEAM_H_ */