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