2 * include/linux/if_team.h - Network team device driver header
3 * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
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.
11 #ifndef _LINUX_IF_TEAM_H_
12 #define _LINUX_IF_TEAM_H_
16 struct team_pcpu_stats {
22 struct u64_stats_sync syncp;
30 struct net_device *dev;
31 struct hlist_node hlist; /* node in enabled ports hash list */
32 struct list_head list; /* node in ordinary list */
34 int index; /* index of enabled port. If disabled, it's set to -1 */
36 bool linkup; /* either state.linkup or user.linkup */
44 /* Values set by userspace */
50 /* Custom gennetlink interface related flags */
55 * A place for storing original values of the device before it
59 unsigned char dev_addr[MAX_ADDR_LEN];
67 struct team_mode_ops {
68 int (*init)(struct team *team);
69 void (*exit)(struct team *team);
70 rx_handler_result_t (*receive)(struct team *team,
71 struct team_port *port,
73 bool (*transmit)(struct team *team, struct sk_buff *skb);
74 int (*port_enter)(struct team *team, struct team_port *port);
75 void (*port_leave)(struct team *team, struct team_port *port);
76 void (*port_change_mac)(struct team *team, struct team_port *port);
79 enum team_option_type {
81 TEAM_OPTION_TYPE_STRING,
82 TEAM_OPTION_TYPE_BINARY,
83 TEAM_OPTION_TYPE_BOOL,
86 struct team_gsetter_ctx {
96 struct team_port *port;
100 struct list_head list;
103 enum team_option_type type;
104 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
105 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
110 struct module *owner;
112 size_t port_priv_size;
113 const struct team_mode_ops *ops;
116 #define TEAM_PORT_HASHBITS 4
117 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
119 #define TEAM_MODE_PRIV_LONGS 4
120 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
123 struct net_device *dev; /* associated netdevice */
124 struct team_pcpu_stats __percpu *pcpu_stats;
126 struct mutex lock; /* used for overall locking, e.g. port lists write */
129 * List of enabled ports and their count
132 struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
134 struct list_head port_list; /* list of all ports */
136 struct list_head option_list;
137 struct list_head option_inst_list; /* list of option instances */
139 const struct team_mode *mode;
140 struct team_mode_ops ops;
141 long mode_priv[TEAM_MODE_PRIV_LONGS];
144 static inline struct hlist_head *team_port_index_hash(struct team *team,
147 return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
150 static inline struct team_port *team_get_port_by_index(struct team *team,
153 struct hlist_node *p;
154 struct team_port *port;
155 struct hlist_head *head = team_port_index_hash(team, port_index);
157 hlist_for_each_entry(port, p, head, hlist)
158 if (port->index == port_index)
162 static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
165 struct hlist_node *p;
166 struct team_port *port;
167 struct hlist_head *head = team_port_index_hash(team, port_index);
169 hlist_for_each_entry_rcu(port, p, head, hlist)
170 if (port->index == port_index)
175 extern int team_port_set_team_mac(struct team_port *port);
176 extern int team_options_register(struct team *team,
177 const struct team_option *option,
178 size_t option_count);
179 extern void team_options_unregister(struct team *team,
180 const struct team_option *option,
181 size_t option_count);
182 extern int team_mode_register(const struct team_mode *mode);
183 extern void team_mode_unregister(const struct team_mode *mode);
185 #endif /* __KERNEL__ */
187 #define TEAM_STRING_MAX_LEN 32
189 /**********************************
190 * NETLINK_GENERIC netlink family.
191 **********************************/
195 TEAM_CMD_OPTIONS_SET,
196 TEAM_CMD_OPTIONS_GET,
197 TEAM_CMD_PORT_LIST_GET,
200 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
205 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
206 TEAM_ATTR_LIST_OPTION, /* nest */
207 TEAM_ATTR_LIST_PORT, /* nest */
210 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
213 /* Nested layout of get/set msg:
215 * [TEAM_ATTR_LIST_OPTION]
216 * [TEAM_ATTR_ITEM_OPTION]
217 * [TEAM_ATTR_OPTION_*], ...
218 * [TEAM_ATTR_ITEM_OPTION]
219 * [TEAM_ATTR_OPTION_*], ...
221 * [TEAM_ATTR_LIST_PORT]
222 * [TEAM_ATTR_ITEM_PORT]
223 * [TEAM_ATTR_PORT_*], ...
224 * [TEAM_ATTR_ITEM_PORT]
225 * [TEAM_ATTR_PORT_*], ...
230 TEAM_ATTR_ITEM_OPTION_UNSPEC,
231 TEAM_ATTR_ITEM_OPTION, /* nest */
233 __TEAM_ATTR_ITEM_OPTION_MAX,
234 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
238 TEAM_ATTR_OPTION_UNSPEC,
239 TEAM_ATTR_OPTION_NAME, /* string */
240 TEAM_ATTR_OPTION_CHANGED, /* flag */
241 TEAM_ATTR_OPTION_TYPE, /* u8 */
242 TEAM_ATTR_OPTION_DATA, /* dynamic */
243 TEAM_ATTR_OPTION_REMOVED, /* flag */
244 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
246 __TEAM_ATTR_OPTION_MAX,
247 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
251 TEAM_ATTR_ITEM_PORT_UNSPEC,
252 TEAM_ATTR_ITEM_PORT, /* nest */
254 __TEAM_ATTR_ITEM_PORT_MAX,
255 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
259 TEAM_ATTR_PORT_UNSPEC,
260 TEAM_ATTR_PORT_IFINDEX, /* u32 */
261 TEAM_ATTR_PORT_CHANGED, /* flag */
262 TEAM_ATTR_PORT_LINKUP, /* flag */
263 TEAM_ATTR_PORT_SPEED, /* u32 */
264 TEAM_ATTR_PORT_DUPLEX, /* u8 */
265 TEAM_ATTR_PORT_REMOVED, /* flag */
267 __TEAM_ATTR_PORT_MAX,
268 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
272 * NETLINK_GENERIC related info
274 #define TEAM_GENL_NAME "team"
275 #define TEAM_GENL_VERSION 0x1
276 #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
278 #endif /* _LINUX_IF_TEAM_H_ */