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