team: add support for per-port options
[deliverable/linux.git] / include / linux / if_team.h
CommitLineData
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
16struct 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
27struct team;
28
29struct 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
56struct 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
68enum team_option_type {
69 TEAM_OPTION_TYPE_U32,
70 TEAM_OPTION_TYPE_STRING,
2615598f 71 TEAM_OPTION_TYPE_BINARY,
3d249d4c
JP
72};
73
80f7c668
JP
74struct team_gsetter_ctx {
75 union {
76 u32 u32_val;
77 const char *str_val;
78 struct {
79 const void *ptr;
80 u32 len;
81 } bin_val;
82 } data;
83 struct team_port *port;
84};
85
3d249d4c
JP
86struct team_option {
87 struct list_head list;
88 const char *name;
80f7c668 89 bool per_port;
3d249d4c 90 enum team_option_type type;
80f7c668
JP
91 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
92 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
3d249d4c
JP
93};
94
95struct team_mode {
96 struct list_head list;
97 const char *kind;
98 struct module *owner;
99 size_t priv_size;
100 const struct team_mode_ops *ops;
101};
102
103#define TEAM_PORT_HASHBITS 4
104#define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
105
106#define TEAM_MODE_PRIV_LONGS 4
107#define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
108
109struct team {
110 struct net_device *dev; /* associated netdevice */
111 struct team_pcpu_stats __percpu *pcpu_stats;
112
61dc3461 113 struct mutex lock; /* used for overall locking, e.g. port lists write */
3d249d4c
JP
114
115 /*
116 * port lists with port count
117 */
118 int port_count;
119 struct hlist_head port_hlist[TEAM_PORT_HASHENTRIES];
120 struct list_head port_list;
121
122 struct list_head option_list;
80f7c668 123 struct list_head option_inst_list; /* list of option instances */
3d249d4c
JP
124
125 const struct team_mode *mode;
126 struct team_mode_ops ops;
127 long mode_priv[TEAM_MODE_PRIV_LONGS];
128};
129
130static inline struct hlist_head *team_port_index_hash(struct team *team,
131 int port_index)
132{
133 return &team->port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
134}
135
136static inline struct team_port *team_get_port_by_index(struct team *team,
137 int port_index)
138{
139 struct hlist_node *p;
140 struct team_port *port;
141 struct hlist_head *head = team_port_index_hash(team, port_index);
142
143 hlist_for_each_entry(port, p, head, hlist)
144 if (port->index == port_index)
145 return port;
146 return NULL;
147}
148static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
149 int port_index)
150{
151 struct hlist_node *p;
152 struct team_port *port;
153 struct hlist_head *head = team_port_index_hash(team, port_index);
154
155 hlist_for_each_entry_rcu(port, p, head, hlist)
156 if (port->index == port_index)
157 return port;
158 return NULL;
159}
160
161extern int team_port_set_team_mac(struct team_port *port);
358b8382
JP
162extern int team_options_register(struct team *team,
163 const struct team_option *option,
164 size_t option_count);
3d249d4c 165extern void team_options_unregister(struct team *team,
358b8382 166 const struct team_option *option,
3d249d4c
JP
167 size_t option_count);
168extern int team_mode_register(struct team_mode *mode);
169extern int team_mode_unregister(struct team_mode *mode);
170
171#endif /* __KERNEL__ */
172
173#define TEAM_STRING_MAX_LEN 32
174
175/**********************************
176 * NETLINK_GENERIC netlink family.
177 **********************************/
178
179enum {
180 TEAM_CMD_NOOP,
181 TEAM_CMD_OPTIONS_SET,
182 TEAM_CMD_OPTIONS_GET,
183 TEAM_CMD_PORT_LIST_GET,
184
185 __TEAM_CMD_MAX,
186 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
187};
188
189enum {
190 TEAM_ATTR_UNSPEC,
191 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
192 TEAM_ATTR_LIST_OPTION, /* nest */
193 TEAM_ATTR_LIST_PORT, /* nest */
194
195 __TEAM_ATTR_MAX,
196 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
197};
198
199/* Nested layout of get/set msg:
200 *
201 * [TEAM_ATTR_LIST_OPTION]
202 * [TEAM_ATTR_ITEM_OPTION]
203 * [TEAM_ATTR_OPTION_*], ...
204 * [TEAM_ATTR_ITEM_OPTION]
205 * [TEAM_ATTR_OPTION_*], ...
206 * ...
207 * [TEAM_ATTR_LIST_PORT]
208 * [TEAM_ATTR_ITEM_PORT]
209 * [TEAM_ATTR_PORT_*], ...
210 * [TEAM_ATTR_ITEM_PORT]
211 * [TEAM_ATTR_PORT_*], ...
212 * ...
213 */
214
215enum {
216 TEAM_ATTR_ITEM_OPTION_UNSPEC,
217 TEAM_ATTR_ITEM_OPTION, /* nest */
218
219 __TEAM_ATTR_ITEM_OPTION_MAX,
220 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
221};
222
223enum {
224 TEAM_ATTR_OPTION_UNSPEC,
225 TEAM_ATTR_OPTION_NAME, /* string */
226 TEAM_ATTR_OPTION_CHANGED, /* flag */
227 TEAM_ATTR_OPTION_TYPE, /* u8 */
228 TEAM_ATTR_OPTION_DATA, /* dynamic */
b82b9183 229 TEAM_ATTR_OPTION_REMOVED, /* flag */
80f7c668 230 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
3d249d4c
JP
231
232 __TEAM_ATTR_OPTION_MAX,
233 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
234};
235
236enum {
237 TEAM_ATTR_ITEM_PORT_UNSPEC,
238 TEAM_ATTR_ITEM_PORT, /* nest */
239
240 __TEAM_ATTR_ITEM_PORT_MAX,
241 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
242};
243
244enum {
245 TEAM_ATTR_PORT_UNSPEC,
246 TEAM_ATTR_PORT_IFINDEX, /* u32 */
247 TEAM_ATTR_PORT_CHANGED, /* flag */
248 TEAM_ATTR_PORT_LINKUP, /* flag */
249 TEAM_ATTR_PORT_SPEED, /* u32 */
250 TEAM_ATTR_PORT_DUPLEX, /* u8 */
b82b9183 251 TEAM_ATTR_PORT_REMOVED, /* flag */
3d249d4c
JP
252
253 __TEAM_ATTR_PORT_MAX,
254 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
255};
256
257/*
258 * NETLINK_GENERIC related info
259 */
260#define TEAM_GENL_NAME "team"
261#define TEAM_GENL_VERSION 0x1
262#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
263
264#endif /* _LINUX_IF_TEAM_H_ */
This page took 0.074661 seconds and 5 git commands to generate.