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 hash list */
32 struct list_head list
; /* node in ordinary list */
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
];
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
,
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
);
78 enum team_option_type
{
80 TEAM_OPTION_TYPE_STRING
,
81 TEAM_OPTION_TYPE_BINARY
,
82 TEAM_OPTION_TYPE_BOOL
,
85 struct team_gsetter_ctx
{
95 struct team_port
*port
;
99 struct list_head list
;
102 enum team_option_type type
;
103 int (*getter
)(struct team
*team
, struct team_gsetter_ctx
*ctx
);
104 int (*setter
)(struct team
*team
, struct team_gsetter_ctx
*ctx
);
108 struct list_head list
;
110 struct module
*owner
;
112 const struct team_mode_ops
*ops
;
115 #define TEAM_PORT_HASHBITS 4
116 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
118 #define TEAM_MODE_PRIV_LONGS 4
119 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
122 struct net_device
*dev
; /* associated netdevice */
123 struct team_pcpu_stats __percpu
*pcpu_stats
;
125 struct mutex lock
; /* used for overall locking, e.g. port lists write */
128 * port lists with port count
131 struct hlist_head port_hlist
[TEAM_PORT_HASHENTRIES
];
132 struct list_head port_list
;
134 struct list_head option_list
;
135 struct list_head option_inst_list
; /* list of option instances */
137 const struct team_mode
*mode
;
138 struct team_mode_ops ops
;
139 long mode_priv
[TEAM_MODE_PRIV_LONGS
];
142 static inline struct hlist_head
*team_port_index_hash(struct team
*team
,
145 return &team
->port_hlist
[port_index
& (TEAM_PORT_HASHENTRIES
- 1)];
148 static inline struct team_port
*team_get_port_by_index(struct team
*team
,
151 struct hlist_node
*p
;
152 struct team_port
*port
;
153 struct hlist_head
*head
= team_port_index_hash(team
, port_index
);
155 hlist_for_each_entry(port
, p
, head
, hlist
)
156 if (port
->index
== port_index
)
160 static inline struct team_port
*team_get_port_by_index_rcu(struct team
*team
,
163 struct hlist_node
*p
;
164 struct team_port
*port
;
165 struct hlist_head
*head
= team_port_index_hash(team
, port_index
);
167 hlist_for_each_entry_rcu(port
, p
, head
, hlist
)
168 if (port
->index
== port_index
)
173 extern int team_port_set_team_mac(struct team_port
*port
);
174 extern int team_options_register(struct team
*team
,
175 const struct team_option
*option
,
176 size_t option_count
);
177 extern void team_options_unregister(struct team
*team
,
178 const struct team_option
*option
,
179 size_t option_count
);
180 extern int team_mode_register(struct team_mode
*mode
);
181 extern int team_mode_unregister(struct team_mode
*mode
);
183 #endif /* __KERNEL__ */
185 #define TEAM_STRING_MAX_LEN 32
187 /**********************************
188 * NETLINK_GENERIC netlink family.
189 **********************************/
193 TEAM_CMD_OPTIONS_SET
,
194 TEAM_CMD_OPTIONS_GET
,
195 TEAM_CMD_PORT_LIST_GET
,
198 TEAM_CMD_MAX
= (__TEAM_CMD_MAX
- 1),
203 TEAM_ATTR_TEAM_IFINDEX
, /* u32 */
204 TEAM_ATTR_LIST_OPTION
, /* nest */
205 TEAM_ATTR_LIST_PORT
, /* nest */
208 TEAM_ATTR_MAX
= __TEAM_ATTR_MAX
- 1,
211 /* Nested layout of get/set msg:
213 * [TEAM_ATTR_LIST_OPTION]
214 * [TEAM_ATTR_ITEM_OPTION]
215 * [TEAM_ATTR_OPTION_*], ...
216 * [TEAM_ATTR_ITEM_OPTION]
217 * [TEAM_ATTR_OPTION_*], ...
219 * [TEAM_ATTR_LIST_PORT]
220 * [TEAM_ATTR_ITEM_PORT]
221 * [TEAM_ATTR_PORT_*], ...
222 * [TEAM_ATTR_ITEM_PORT]
223 * [TEAM_ATTR_PORT_*], ...
228 TEAM_ATTR_ITEM_OPTION_UNSPEC
,
229 TEAM_ATTR_ITEM_OPTION
, /* nest */
231 __TEAM_ATTR_ITEM_OPTION_MAX
,
232 TEAM_ATTR_ITEM_OPTION_MAX
= __TEAM_ATTR_ITEM_OPTION_MAX
- 1,
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 */
241 TEAM_ATTR_OPTION_REMOVED
, /* flag */
242 TEAM_ATTR_OPTION_PORT_IFINDEX
, /* u32 */ /* for per-port options */
244 __TEAM_ATTR_OPTION_MAX
,
245 TEAM_ATTR_OPTION_MAX
= __TEAM_ATTR_OPTION_MAX
- 1,
249 TEAM_ATTR_ITEM_PORT_UNSPEC
,
250 TEAM_ATTR_ITEM_PORT
, /* nest */
252 __TEAM_ATTR_ITEM_PORT_MAX
,
253 TEAM_ATTR_ITEM_PORT_MAX
= __TEAM_ATTR_ITEM_PORT_MAX
- 1,
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 */
263 TEAM_ATTR_PORT_REMOVED
, /* flag */
265 __TEAM_ATTR_PORT_MAX
,
266 TEAM_ATTR_PORT_MAX
= __TEAM_ATTR_PORT_MAX
- 1,
270 * NETLINK_GENERIC related info
272 #define TEAM_GENL_NAME "team"
273 #define TEAM_GENL_VERSION 0x1
274 #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
276 #endif /* _LINUX_IF_TEAM_H_ */