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 #include <linux/netpoll.h>
18 struct team_pcpu_stats {
24 struct u64_stats_sync syncp;
32 struct net_device *dev;
33 struct hlist_node hlist; /* node in enabled ports hash list */
34 struct list_head list; /* node in ordinary list */
36 int index; /* index of enabled port. If disabled, it's set to -1 */
38 bool linkup; /* either state.linkup or user.linkup */
46 /* Values set by userspace */
52 /* Custom gennetlink interface related flags */
57 * A place for storing original values of the device before it
61 unsigned char dev_addr[MAX_ADDR_LEN];
65 #ifdef CONFIG_NET_POLL_CONTROLLER
72 static inline bool team_port_enabled(struct team_port *port)
74 return port->index != -1;
77 static inline bool team_port_txable(struct team_port *port)
79 return port->linkup && team_port_enabled(port);
82 #ifdef CONFIG_NET_POLL_CONTROLLER
83 static inline void team_netpoll_send_skb(struct team_port *port,
86 struct netpoll *np = port->np;
89 netpoll_send_skb(np, skb);
92 static inline void team_netpoll_send_skb(struct team_port *port,
98 static inline int team_dev_queue_xmit(struct team *team, struct team_port *port,
101 skb->dev = port->dev;
102 if (unlikely(netpoll_tx_running(port->dev))) {
103 team_netpoll_send_skb(port, skb);
106 return dev_queue_xmit(skb);
109 struct team_mode_ops {
110 int (*init)(struct team *team);
111 void (*exit)(struct team *team);
112 rx_handler_result_t (*receive)(struct team *team,
113 struct team_port *port,
114 struct sk_buff *skb);
115 bool (*transmit)(struct team *team, struct sk_buff *skb);
116 int (*port_enter)(struct team *team, struct team_port *port);
117 void (*port_leave)(struct team *team, struct team_port *port);
118 void (*port_change_mac)(struct team *team, struct team_port *port);
119 void (*port_enabled)(struct team *team, struct team_port *port);
120 void (*port_disabled)(struct team *team, struct team_port *port);
123 enum team_option_type {
124 TEAM_OPTION_TYPE_U32,
125 TEAM_OPTION_TYPE_STRING,
126 TEAM_OPTION_TYPE_BINARY,
127 TEAM_OPTION_TYPE_BOOL,
130 struct team_option_inst_info {
132 struct team_port *port; /* != NULL if per-port */
135 struct team_gsetter_ctx {
145 struct team_option_inst_info *info;
149 struct list_head list;
152 unsigned int array_size; /* != 0 means the option is array */
153 enum team_option_type type;
154 int (*init)(struct team *team, struct team_option_inst_info *info);
155 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
156 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
159 extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info);
160 extern void team_options_change_check(struct team *team);
164 struct module *owner;
166 size_t port_priv_size;
167 const struct team_mode_ops *ops;
170 #define TEAM_PORT_HASHBITS 4
171 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
173 #define TEAM_MODE_PRIV_LONGS 4
174 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
177 struct net_device *dev; /* associated netdevice */
178 struct team_pcpu_stats __percpu *pcpu_stats;
180 struct mutex lock; /* used for overall locking, e.g. port lists write */
183 * List of enabled ports and their count
186 struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
188 struct list_head port_list; /* list of all ports */
190 struct list_head option_list;
191 struct list_head option_inst_list; /* list of option instances */
193 const struct team_mode *mode;
194 struct team_mode_ops ops;
195 long mode_priv[TEAM_MODE_PRIV_LONGS];
198 static inline struct hlist_head *team_port_index_hash(struct team *team,
201 return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
204 static inline struct team_port *team_get_port_by_index(struct team *team,
207 struct hlist_node *p;
208 struct team_port *port;
209 struct hlist_head *head = team_port_index_hash(team, port_index);
211 hlist_for_each_entry(port, p, head, hlist)
212 if (port->index == port_index)
216 static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
219 struct hlist_node *p;
220 struct team_port *port;
221 struct hlist_head *head = team_port_index_hash(team, port_index);
223 hlist_for_each_entry_rcu(port, p, head, hlist)
224 if (port->index == port_index)
229 extern int team_port_set_team_mac(struct team_port *port);
230 extern int team_options_register(struct team *team,
231 const struct team_option *option,
232 size_t option_count);
233 extern void team_options_unregister(struct team *team,
234 const struct team_option *option,
235 size_t option_count);
236 extern int team_mode_register(const struct team_mode *mode);
237 extern void team_mode_unregister(const struct team_mode *mode);
239 #endif /* __KERNEL__ */
241 #define TEAM_STRING_MAX_LEN 32
243 /**********************************
244 * NETLINK_GENERIC netlink family.
245 **********************************/
249 TEAM_CMD_OPTIONS_SET,
250 TEAM_CMD_OPTIONS_GET,
251 TEAM_CMD_PORT_LIST_GET,
254 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
259 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
260 TEAM_ATTR_LIST_OPTION, /* nest */
261 TEAM_ATTR_LIST_PORT, /* nest */
264 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
267 /* Nested layout of get/set msg:
269 * [TEAM_ATTR_LIST_OPTION]
270 * [TEAM_ATTR_ITEM_OPTION]
271 * [TEAM_ATTR_OPTION_*], ...
272 * [TEAM_ATTR_ITEM_OPTION]
273 * [TEAM_ATTR_OPTION_*], ...
275 * [TEAM_ATTR_LIST_PORT]
276 * [TEAM_ATTR_ITEM_PORT]
277 * [TEAM_ATTR_PORT_*], ...
278 * [TEAM_ATTR_ITEM_PORT]
279 * [TEAM_ATTR_PORT_*], ...
284 TEAM_ATTR_ITEM_OPTION_UNSPEC,
285 TEAM_ATTR_ITEM_OPTION, /* nest */
287 __TEAM_ATTR_ITEM_OPTION_MAX,
288 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
292 TEAM_ATTR_OPTION_UNSPEC,
293 TEAM_ATTR_OPTION_NAME, /* string */
294 TEAM_ATTR_OPTION_CHANGED, /* flag */
295 TEAM_ATTR_OPTION_TYPE, /* u8 */
296 TEAM_ATTR_OPTION_DATA, /* dynamic */
297 TEAM_ATTR_OPTION_REMOVED, /* flag */
298 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
299 TEAM_ATTR_OPTION_ARRAY_INDEX, /* u32 */ /* for array options */
301 __TEAM_ATTR_OPTION_MAX,
302 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
306 TEAM_ATTR_ITEM_PORT_UNSPEC,
307 TEAM_ATTR_ITEM_PORT, /* nest */
309 __TEAM_ATTR_ITEM_PORT_MAX,
310 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
314 TEAM_ATTR_PORT_UNSPEC,
315 TEAM_ATTR_PORT_IFINDEX, /* u32 */
316 TEAM_ATTR_PORT_CHANGED, /* flag */
317 TEAM_ATTR_PORT_LINKUP, /* flag */
318 TEAM_ATTR_PORT_SPEED, /* u32 */
319 TEAM_ATTR_PORT_DUPLEX, /* u8 */
320 TEAM_ATTR_PORT_REMOVED, /* flag */
322 __TEAM_ATTR_PORT_MAX,
323 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
327 * NETLINK_GENERIC related info
329 #define TEAM_GENL_NAME "team"
330 #define TEAM_GENL_VERSION 0x1
331 #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
333 #endif /* _LINUX_IF_TEAM_H_ */