]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/if_team.h
bond_sysfs: use real_num_tx_queues rather than params.tx_queue
[mirror_ubuntu-bionic-kernel.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
bd2d0837
JP
16#include <linux/netpoll.h>
17
3d249d4c
JP
18struct team_pcpu_stats {
19 u64 rx_packets;
20 u64 rx_bytes;
21 u64 rx_multicast;
22 u64 tx_packets;
23 u64 tx_bytes;
24 struct u64_stats_sync syncp;
25 u32 rx_dropped;
26 u32 tx_dropped;
27};
28
29struct team;
30
31struct team_port {
32 struct net_device *dev;
19a0b58e 33 struct hlist_node hlist; /* node in enabled ports hash list */
3d249d4c
JP
34 struct list_head list; /* node in ordinary list */
35 struct team *team;
19a0b58e 36 int index; /* index of enabled port. If disabled, it's set to -1 */
3d249d4c 37
71472ec1
JP
38 bool linkup; /* either state.linkup or user.linkup */
39
40 struct {
41 bool linkup;
42 u32 speed;
43 u8 duplex;
44 } state;
45
46 /* Values set by userspace */
47 struct {
48 bool linkup;
49 bool linkup_enabled;
50 } user;
51
52 /* Custom gennetlink interface related flags */
53 bool changed;
54 bool removed;
55
3d249d4c
JP
56 /*
57 * A place for storing original values of the device before it
58 * become a port.
59 */
60 struct {
61 unsigned char dev_addr[MAX_ADDR_LEN];
62 unsigned int mtu;
63 } orig;
64
bd2d0837
JP
65#ifdef CONFIG_NET_POLL_CONTROLLER
66 struct netpoll *np;
67#endif
68
5149ee58 69 long mode_priv[0];
3d249d4c
JP
70};
71
68c45042
JP
72static inline bool team_port_enabled(struct team_port *port)
73{
74 return port->index != -1;
75}
76
77static inline bool team_port_txable(struct team_port *port)
78{
79 return port->linkup && team_port_enabled(port);
80}
52a4fd77 81
bd2d0837
JP
82#ifdef CONFIG_NET_POLL_CONTROLLER
83static inline void team_netpoll_send_skb(struct team_port *port,
84 struct sk_buff *skb)
85{
86 struct netpoll *np = port->np;
87
88 if (np)
89 netpoll_send_skb(np, skb);
90}
91#else
92static inline void team_netpoll_send_skb(struct team_port *port,
93 struct sk_buff *skb)
94{
95}
96#endif
97
98static inline int team_dev_queue_xmit(struct team *team, struct team_port *port,
99 struct sk_buff *skb)
100{
101 skb->dev = port->dev;
102 if (unlikely(netpoll_tx_running(port->dev))) {
103 team_netpoll_send_skb(port, skb);
104 return 0;
105 }
106 return dev_queue_xmit(skb);
107}
108
3d249d4c
JP
109struct 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);
4bccfd17
JP
119 void (*port_enabled)(struct team *team, struct team_port *port);
120 void (*port_disabled)(struct team *team, struct team_port *port);
3d249d4c
JP
121};
122
123enum team_option_type {
124 TEAM_OPTION_TYPE_U32,
125 TEAM_OPTION_TYPE_STRING,
2615598f 126 TEAM_OPTION_TYPE_BINARY,
14f066ba 127 TEAM_OPTION_TYPE_BOOL,
3d249d4c
JP
128};
129
85d59a87
JP
130struct team_option_inst_info {
131 u32 array_index;
132 struct team_port *port; /* != NULL if per-port */
133};
134
80f7c668
JP
135struct team_gsetter_ctx {
136 union {
137 u32 u32_val;
138 const char *str_val;
139 struct {
140 const void *ptr;
141 u32 len;
142 } bin_val;
14f066ba 143 bool bool_val;
80f7c668 144 } data;
85d59a87 145 struct team_option_inst_info *info;
80f7c668
JP
146};
147
3d249d4c
JP
148struct team_option {
149 struct list_head list;
150 const char *name;
80f7c668 151 bool per_port;
b1303326 152 unsigned int array_size; /* != 0 means the option is array */
3d249d4c 153 enum team_option_type type;
85d59a87 154 int (*init)(struct team *team, struct team_option_inst_info *info);
80f7c668
JP
155 int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
156 int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
3d249d4c
JP
157};
158
0f1aad2b
JP
159extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info);
160extern void team_options_change_check(struct team *team);
161
3d249d4c 162struct team_mode {
3d249d4c
JP
163 const char *kind;
164 struct module *owner;
165 size_t priv_size;
5149ee58 166 size_t port_priv_size;
3d249d4c
JP
167 const struct team_mode_ops *ops;
168};
169
170#define TEAM_PORT_HASHBITS 4
171#define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
172
173#define TEAM_MODE_PRIV_LONGS 4
174#define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
175
176struct team {
177 struct net_device *dev; /* associated netdevice */
178 struct team_pcpu_stats __percpu *pcpu_stats;
179
61dc3461 180 struct mutex lock; /* used for overall locking, e.g. port lists write */
3d249d4c
JP
181
182 /*
19a0b58e 183 * List of enabled ports and their count
3d249d4c 184 */
19a0b58e
JP
185 int en_port_count;
186 struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
187
188 struct list_head port_list; /* list of all ports */
3d249d4c
JP
189
190 struct list_head option_list;
80f7c668 191 struct list_head option_inst_list; /* list of option instances */
3d249d4c
JP
192
193 const struct team_mode *mode;
194 struct team_mode_ops ops;
195 long mode_priv[TEAM_MODE_PRIV_LONGS];
196};
197
198static inline struct hlist_head *team_port_index_hash(struct team *team,
199 int port_index)
200{
19a0b58e 201 return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
3d249d4c
JP
202}
203
204static inline struct team_port *team_get_port_by_index(struct team *team,
205 int port_index)
206{
207 struct hlist_node *p;
208 struct team_port *port;
209 struct hlist_head *head = team_port_index_hash(team, port_index);
210
211 hlist_for_each_entry(port, p, head, hlist)
212 if (port->index == port_index)
213 return port;
214 return NULL;
215}
216static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
217 int port_index)
218{
219 struct hlist_node *p;
220 struct team_port *port;
221 struct hlist_head *head = team_port_index_hash(team, port_index);
222
223 hlist_for_each_entry_rcu(port, p, head, hlist)
224 if (port->index == port_index)
225 return port;
226 return NULL;
227}
228
229extern int team_port_set_team_mac(struct team_port *port);
358b8382
JP
230extern int team_options_register(struct team *team,
231 const struct team_option *option,
232 size_t option_count);
3d249d4c 233extern void team_options_unregister(struct team *team,
358b8382 234 const struct team_option *option,
3d249d4c 235 size_t option_count);
0402788a
JP
236extern int team_mode_register(const struct team_mode *mode);
237extern void team_mode_unregister(const struct team_mode *mode);
3d249d4c
JP
238
239#endif /* __KERNEL__ */
240
241#define TEAM_STRING_MAX_LEN 32
242
243/**********************************
244 * NETLINK_GENERIC netlink family.
245 **********************************/
246
247enum {
248 TEAM_CMD_NOOP,
249 TEAM_CMD_OPTIONS_SET,
250 TEAM_CMD_OPTIONS_GET,
251 TEAM_CMD_PORT_LIST_GET,
252
253 __TEAM_CMD_MAX,
254 TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
255};
256
257enum {
258 TEAM_ATTR_UNSPEC,
259 TEAM_ATTR_TEAM_IFINDEX, /* u32 */
260 TEAM_ATTR_LIST_OPTION, /* nest */
261 TEAM_ATTR_LIST_PORT, /* nest */
262
263 __TEAM_ATTR_MAX,
264 TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
265};
266
267/* Nested layout of get/set msg:
268 *
269 * [TEAM_ATTR_LIST_OPTION]
270 * [TEAM_ATTR_ITEM_OPTION]
271 * [TEAM_ATTR_OPTION_*], ...
272 * [TEAM_ATTR_ITEM_OPTION]
273 * [TEAM_ATTR_OPTION_*], ...
274 * ...
275 * [TEAM_ATTR_LIST_PORT]
276 * [TEAM_ATTR_ITEM_PORT]
277 * [TEAM_ATTR_PORT_*], ...
278 * [TEAM_ATTR_ITEM_PORT]
279 * [TEAM_ATTR_PORT_*], ...
280 * ...
281 */
282
283enum {
284 TEAM_ATTR_ITEM_OPTION_UNSPEC,
285 TEAM_ATTR_ITEM_OPTION, /* nest */
286
287 __TEAM_ATTR_ITEM_OPTION_MAX,
288 TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
289};
290
291enum {
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 */
b82b9183 297 TEAM_ATTR_OPTION_REMOVED, /* flag */
80f7c668 298 TEAM_ATTR_OPTION_PORT_IFINDEX, /* u32 */ /* for per-port options */
b1303326 299 TEAM_ATTR_OPTION_ARRAY_INDEX, /* u32 */ /* for array options */
3d249d4c
JP
300
301 __TEAM_ATTR_OPTION_MAX,
302 TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
303};
304
305enum {
306 TEAM_ATTR_ITEM_PORT_UNSPEC,
307 TEAM_ATTR_ITEM_PORT, /* nest */
308
309 __TEAM_ATTR_ITEM_PORT_MAX,
310 TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
311};
312
313enum {
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 */
b82b9183 320 TEAM_ATTR_PORT_REMOVED, /* flag */
3d249d4c
JP
321
322 __TEAM_ATTR_PORT_MAX,
323 TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
324};
325
326/*
327 * NETLINK_GENERIC related info
328 */
329#define TEAM_GENL_NAME "team"
330#define TEAM_GENL_VERSION 0x1
331#define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
332
333#endif /* _LINUX_IF_TEAM_H_ */