tipc: rename struct subscription to struct tipc_subscription
[linux-2.6.git] / include / linux / if_team.h
blob828181fbad5d709db91797e359b617efdd606a40
1 /*
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.
9 */
11 #ifndef _LINUX_IF_TEAM_H_
12 #define _LINUX_IF_TEAM_H_
14 #ifdef __KERNEL__
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;
27 struct team;
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;
37 * A place for storing original values of the device before it
38 * become a port.
40 struct {
41 unsigned char dev_addr[MAX_ADDR_LEN];
42 unsigned int mtu;
43 } orig;
45 bool linkup;
46 u32 speed;
47 u8 duplex;
49 struct rcu_head rcu;
52 struct team_mode_ops {
53 int (*init)(struct team *team);
54 void (*exit)(struct team *team);
55 rx_handler_result_t (*receive)(struct team *team,
56 struct team_port *port,
57 struct sk_buff *skb);
58 bool (*transmit)(struct team *team, struct sk_buff *skb);
59 int (*port_enter)(struct team *team, struct team_port *port);
60 void (*port_leave)(struct team *team, struct team_port *port);
61 void (*port_change_mac)(struct team *team, struct team_port *port);
64 enum team_option_type {
65 TEAM_OPTION_TYPE_U32,
66 TEAM_OPTION_TYPE_STRING,
69 struct team_option {
70 struct list_head list;
71 const char *name;
72 enum team_option_type type;
73 int (*getter)(struct team *team, void *arg);
74 int (*setter)(struct team *team, void *arg);
77 struct team_mode {
78 struct list_head list;
79 const char *kind;
80 struct module *owner;
81 size_t priv_size;
82 const struct team_mode_ops *ops;
85 #define TEAM_PORT_HASHBITS 4
86 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
88 #define TEAM_MODE_PRIV_LONGS 4
89 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
91 struct team {
92 struct net_device *dev; /* associated netdevice */
93 struct team_pcpu_stats __percpu *pcpu_stats;
95 struct mutex lock; /* used for overall locking, e.g. port lists write */
98 * port lists with port count
100 int port_count;
101 struct hlist_head port_hlist[TEAM_PORT_HASHENTRIES];
102 struct list_head port_list;
104 struct list_head option_list;
106 const struct team_mode *mode;
107 struct team_mode_ops ops;
108 long mode_priv[TEAM_MODE_PRIV_LONGS];
111 static inline struct hlist_head *team_port_index_hash(struct team *team,
112 int port_index)
114 return &team->port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
117 static inline struct team_port *team_get_port_by_index(struct team *team,
118 int port_index)
120 struct hlist_node *p;
121 struct team_port *port;
122 struct hlist_head *head = team_port_index_hash(team, port_index);
124 hlist_for_each_entry(port, p, head, hlist)
125 if (port->index == port_index)
126 return port;
127 return NULL;
129 static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
130 int port_index)
132 struct hlist_node *p;
133 struct team_port *port;
134 struct hlist_head *head = team_port_index_hash(team, port_index);
136 hlist_for_each_entry_rcu(port, p, head, hlist)
137 if (port->index == port_index)
138 return port;
139 return NULL;
142 extern int team_port_set_team_mac(struct team_port *port);
143 extern int team_options_register(struct team *team,
144 const struct team_option *option,
145 size_t option_count);
146 extern void team_options_unregister(struct team *team,
147 const struct team_option *option,
148 size_t option_count);
149 extern int team_mode_register(struct team_mode *mode);
150 extern int team_mode_unregister(struct team_mode *mode);
152 #endif /* __KERNEL__ */
154 #define TEAM_STRING_MAX_LEN 32
156 /**********************************
157 * NETLINK_GENERIC netlink family.
158 **********************************/
160 enum {
161 TEAM_CMD_NOOP,
162 TEAM_CMD_OPTIONS_SET,
163 TEAM_CMD_OPTIONS_GET,
164 TEAM_CMD_PORT_LIST_GET,
166 __TEAM_CMD_MAX,
167 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
170 enum {
171 TEAM_ATTR_UNSPEC,
172 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
173 TEAM_ATTR_LIST_OPTION, /* nest */
174 TEAM_ATTR_LIST_PORT, /* nest */
176 __TEAM_ATTR_MAX,
177 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
180 /* Nested layout of get/set msg:
182 * [TEAM_ATTR_LIST_OPTION]
183 * [TEAM_ATTR_ITEM_OPTION]
184 * [TEAM_ATTR_OPTION_*], ...
185 * [TEAM_ATTR_ITEM_OPTION]
186 * [TEAM_ATTR_OPTION_*], ...
187 * ...
188 * [TEAM_ATTR_LIST_PORT]
189 * [TEAM_ATTR_ITEM_PORT]
190 * [TEAM_ATTR_PORT_*], ...
191 * [TEAM_ATTR_ITEM_PORT]
192 * [TEAM_ATTR_PORT_*], ...
193 * ...
196 enum {
197 TEAM_ATTR_ITEM_OPTION_UNSPEC,
198 TEAM_ATTR_ITEM_OPTION, /* nest */
200 __TEAM_ATTR_ITEM_OPTION_MAX,
201 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
204 enum {
205 TEAM_ATTR_OPTION_UNSPEC,
206 TEAM_ATTR_OPTION_NAME, /* string */
207 TEAM_ATTR_OPTION_CHANGED, /* flag */
208 TEAM_ATTR_OPTION_TYPE, /* u8 */
209 TEAM_ATTR_OPTION_DATA, /* dynamic */
211 __TEAM_ATTR_OPTION_MAX,
212 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
215 enum {
216 TEAM_ATTR_ITEM_PORT_UNSPEC,
217 TEAM_ATTR_ITEM_PORT, /* nest */
219 __TEAM_ATTR_ITEM_PORT_MAX,
220 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
223 enum {
224 TEAM_ATTR_PORT_UNSPEC,
225 TEAM_ATTR_PORT_IFINDEX, /* u32 */
226 TEAM_ATTR_PORT_CHANGED, /* flag */
227 TEAM_ATTR_PORT_LINKUP, /* flag */
228 TEAM_ATTR_PORT_SPEED, /* u32 */
229 TEAM_ATTR_PORT_DUPLEX, /* u8 */
231 __TEAM_ATTR_PORT_MAX,
232 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
236 * NETLINK_GENERIC related info
238 #define TEAM_GENL_NAME "team"
239 #define TEAM_GENL_VERSION 0x1
240 #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
242 #endif /* _LINUX_IF_TEAM_H_ */