netpoll: move np->dev and np->dev_name init into __netpoll_setup()
[deliverable/linux.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
68c45042
JP
66static inline bool team_port_enabled(struct team_port *port)
67{
68 return port->index != -1;
69}
70
71static inline bool team_port_txable(struct team_port *port)
72{
73 return port->linkup && team_port_enabled(port);
74}
52a4fd77 75
3d249d4c
JP
76struct team_mode_ops {
77 int (*init)(struct team *team);
78 void (*exit)(struct team *team);
79 rx_handler_result_t (*receive)(struct team *team,
80 struct team_port *port,
81 struct sk_buff *skb);
82 bool (*transmit)(struct team *team, struct sk_buff *skb);
83 int (*port_enter)(struct team *team, struct team_port *port);
84 void (*port_leave)(struct team *team, struct team_port *port);
85 void (*port_change_mac)(struct team *team, struct team_port *port);
4bccfd17
JP
86 void (*port_enabled)(struct team *team, struct team_port *port);
87 void (*port_disabled)(struct team *team, struct team_port *port);
3d249d4c
JP
88};
89
90enum team_option_type {
91 TEAM_OPTION_TYPE_U32,
92 TEAM_OPTION_TYPE_STRING,
2615598f 93 TEAM_OPTION_TYPE_BINARY,
14f066ba 94 TEAM_OPTION_TYPE_BOOL,
3d249d4c
JP
95};
96
85d59a87
JP
97struct team_option_inst_info {
98 u32 array_index;
99 struct team_port *port; /* != NULL if per-port */
100};
101
80f7c668
JP
102struct team_gsetter_ctx {
103 union {
104 u32 u32_val;
105 const char *str_val;
106 struct {
107 const void *ptr;
108 u32 len;
109 } bin_val;
14f066ba 110 bool bool_val;
80f7c668 111 } data;
85d59a87 112 struct team_option_inst_info *info;
80f7c668
JP
113};
114
3d249d4c
JP
115struct team_option {
116 struct list_head list;
117 const char *name;
80f7c668 118 bool per_port;
b1303326 119 unsigned int array_size; /* != 0 means the option is array */
3d249d4c 120 enum team_option_type type;
85d59a87 121 int (*init)(struct team *team, struct team_option_inst_info *info);
80f7c668
JP
122 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
123 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
3d249d4c
JP
124};
125
0f1aad2b
JP
126extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info);
127extern void team_options_change_check(struct team *team);
128
3d249d4c 129struct team_mode {
3d249d4c
JP
130 const char *kind;
131 struct module *owner;
132 size_t priv_size;
5149ee58 133 size_t port_priv_size;
3d249d4c
JP
134 const struct team_mode_ops *ops;
135};
136
137#define TEAM_PORT_HASHBITS 4
138#define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
139
140#define TEAM_MODE_PRIV_LONGS 4
141#define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
142
143struct team {
144 struct net_device *dev; /* associated netdevice */
145 struct team_pcpu_stats __percpu *pcpu_stats;
146
61dc3461 147 struct mutex lock; /* used for overall locking, e.g. port lists write */
3d249d4c
JP
148
149 /*
19a0b58e 150 * List of enabled ports and their count
3d249d4c 151 */
19a0b58e
JP
152 int en_port_count;
153 struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
154
155 struct list_head port_list; /* list of all ports */
3d249d4c
JP
156
157 struct list_head option_list;
80f7c668 158 struct list_head option_inst_list; /* list of option instances */
3d249d4c
JP
159
160 const struct team_mode *mode;
161 struct team_mode_ops ops;
162 long mode_priv[TEAM_MODE_PRIV_LONGS];
163};
164
165static inline struct hlist_head *team_port_index_hash(struct team *team,
166 int port_index)
167{
19a0b58e 168 return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
3d249d4c
JP
169}
170
171static inline struct team_port *team_get_port_by_index(struct team *team,
172 int port_index)
173{
174 struct hlist_node *p;
175 struct team_port *port;
176 struct hlist_head *head = team_port_index_hash(team, port_index);
177
178 hlist_for_each_entry(port, p, head, hlist)
179 if (port->index == port_index)
180 return port;
181 return NULL;
182}
183static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
184 int port_index)
185{
186 struct hlist_node *p;
187 struct team_port *port;
188 struct hlist_head *head = team_port_index_hash(team, port_index);
189
190 hlist_for_each_entry_rcu(port, p, head, hlist)
191 if (port->index == port_index)
192 return port;
193 return NULL;
194}
195
196extern int team_port_set_team_mac(struct team_port *port);
358b8382
JP
197extern int team_options_register(struct team *team,
198 const struct team_option *option,
199 size_t option_count);
3d249d4c 200extern void team_options_unregister(struct team *team,
358b8382 201 const struct team_option *option,
3d249d4c 202 size_t option_count);
0402788a
JP
203extern int team_mode_register(const struct team_mode *mode);
204extern void team_mode_unregister(const struct team_mode *mode);
3d249d4c
JP
205
206#endif /* __KERNEL__ */
207
208#define TEAM_STRING_MAX_LEN 32
209
210/**********************************
211 * NETLINK_GENERIC netlink family.
212 **********************************/
213
214enum {
215 TEAM_CMD_NOOP,
216 TEAM_CMD_OPTIONS_SET,
217 TEAM_CMD_OPTIONS_GET,
218 TEAM_CMD_PORT_LIST_GET,
219
220 __TEAM_CMD_MAX,
221 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
222};
223
224enum {
225 TEAM_ATTR_UNSPEC,
226 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
227 TEAM_ATTR_LIST_OPTION, /* nest */
228 TEAM_ATTR_LIST_PORT, /* nest */
229
230 __TEAM_ATTR_MAX,
231 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
232};
233
234/* Nested layout of get/set msg:
235 *
236 * [TEAM_ATTR_LIST_OPTION]
237 * [TEAM_ATTR_ITEM_OPTION]
238 * [TEAM_ATTR_OPTION_*], ...
239 * [TEAM_ATTR_ITEM_OPTION]
240 * [TEAM_ATTR_OPTION_*], ...
241 * ...
242 * [TEAM_ATTR_LIST_PORT]
243 * [TEAM_ATTR_ITEM_PORT]
244 * [TEAM_ATTR_PORT_*], ...
245 * [TEAM_ATTR_ITEM_PORT]
246 * [TEAM_ATTR_PORT_*], ...
247 * ...
248 */
249
250enum {
251 TEAM_ATTR_ITEM_OPTION_UNSPEC,
252 TEAM_ATTR_ITEM_OPTION, /* nest */
253
254 __TEAM_ATTR_ITEM_OPTION_MAX,
255 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
256};
257
258enum {
259 TEAM_ATTR_OPTION_UNSPEC,
260 TEAM_ATTR_OPTION_NAME, /* string */
261 TEAM_ATTR_OPTION_CHANGED, /* flag */
262 TEAM_ATTR_OPTION_TYPE, /* u8 */
263 TEAM_ATTR_OPTION_DATA, /* dynamic */
b82b9183 264 TEAM_ATTR_OPTION_REMOVED, /* flag */
80f7c668 265 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
b1303326 266 TEAM_ATTR_OPTION_ARRAY_INDEX, /* u32 */ /* for array options */
3d249d4c
JP
267
268 __TEAM_ATTR_OPTION_MAX,
269 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
270};
271
272enum {
273 TEAM_ATTR_ITEM_PORT_UNSPEC,
274 TEAM_ATTR_ITEM_PORT, /* nest */
275
276 __TEAM_ATTR_ITEM_PORT_MAX,
277 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
278};
279
280enum {
281 TEAM_ATTR_PORT_UNSPEC,
282 TEAM_ATTR_PORT_IFINDEX, /* u32 */
283 TEAM_ATTR_PORT_CHANGED, /* flag */
284 TEAM_ATTR_PORT_LINKUP, /* flag */
285 TEAM_ATTR_PORT_SPEED, /* u32 */
286 TEAM_ATTR_PORT_DUPLEX, /* u8 */
b82b9183 287 TEAM_ATTR_PORT_REMOVED, /* flag */
3d249d4c
JP
288
289 __TEAM_ATTR_PORT_MAX,
290 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
291};
292
293/*
294 * NETLINK_GENERIC related info
295 */
296#define TEAM_GENL_NAME "team"
297#define TEAM_GENL_VERSION 0x1
298#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
299
300#endif /* _LINUX_IF_TEAM_H_ */
This page took 0.102201 seconds and 5 git commands to generate.