team: remove unused rcu_head field from team_port struct
[platform/adaptation/renesas_rcar/renesas_kernel.git] / include / linux / if_team.h
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
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;
25 };
26
27 struct team;
28
29 struct team_port {
30         struct net_device *dev;
31         struct hlist_node hlist; /* node in enabled ports hash list */
32         struct list_head list; /* node in ordinary list */
33         struct team *team;
34         int index; /* index of enabled port. If disabled, it's set to -1 */
35
36         bool linkup; /* either state.linkup or user.linkup */
37
38         struct {
39                 bool linkup;
40                 u32 speed;
41                 u8 duplex;
42         } state;
43
44         /* Values set by userspace */
45         struct {
46                 bool linkup;
47                 bool linkup_enabled;
48         } user;
49
50         /* Custom gennetlink interface related flags */
51         bool changed;
52         bool removed;
53
54         /*
55          * A place for storing original values of the device before it
56          * become a port.
57          */
58         struct {
59                 unsigned char dev_addr[MAX_ADDR_LEN];
60                 unsigned int mtu;
61         } orig;
62
63         long mode_priv[0];
64 };
65
66 extern bool team_port_enabled(struct team_port *port);
67
68 struct team_mode_ops {
69         int (*init)(struct team *team);
70         void (*exit)(struct team *team);
71         rx_handler_result_t (*receive)(struct team *team,
72                                        struct team_port *port,
73                                        struct sk_buff *skb);
74         bool (*transmit)(struct team *team, struct sk_buff *skb);
75         int (*port_enter)(struct team *team, struct team_port *port);
76         void (*port_leave)(struct team *team, struct team_port *port);
77         void (*port_change_mac)(struct team *team, struct team_port *port);
78         void (*port_enabled)(struct team *team, struct team_port *port);
79         void (*port_disabled)(struct team *team, struct team_port *port);
80 };
81
82 enum team_option_type {
83         TEAM_OPTION_TYPE_U32,
84         TEAM_OPTION_TYPE_STRING,
85         TEAM_OPTION_TYPE_BINARY,
86         TEAM_OPTION_TYPE_BOOL,
87 };
88
89 struct team_option_inst_info {
90         u32 array_index;
91         struct team_port *port; /* != NULL if per-port */
92 };
93
94 struct team_gsetter_ctx {
95         union {
96                 u32 u32_val;
97                 const char *str_val;
98                 struct {
99                         const void *ptr;
100                         u32 len;
101                 } bin_val;
102                 bool bool_val;
103         } data;
104         struct team_option_inst_info *info;
105 };
106
107 struct team_option {
108         struct list_head list;
109         const char *name;
110         bool per_port;
111         unsigned int array_size; /* != 0 means the option is array */
112         enum team_option_type type;
113         int (*init)(struct team *team, struct team_option_inst_info *info);
114         int (*getter)(struct team *team, struct team_gsetter_ctx *ctx);
115         int (*setter)(struct team *team, struct team_gsetter_ctx *ctx);
116 };
117
118 extern void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info);
119 extern void team_options_change_check(struct team *team);
120
121 struct team_mode {
122         const char *kind;
123         struct module *owner;
124         size_t priv_size;
125         size_t port_priv_size;
126         const struct team_mode_ops *ops;
127 };
128
129 #define TEAM_PORT_HASHBITS 4
130 #define TEAM_PORT_HASHENTRIES (1 << TEAM_PORT_HASHBITS)
131
132 #define TEAM_MODE_PRIV_LONGS 4
133 #define TEAM_MODE_PRIV_SIZE (sizeof(long) * TEAM_MODE_PRIV_LONGS)
134
135 struct team {
136         struct net_device *dev; /* associated netdevice */
137         struct team_pcpu_stats __percpu *pcpu_stats;
138
139         struct mutex lock; /* used for overall locking, e.g. port lists write */
140
141         /*
142          * List of enabled ports and their count
143          */
144         int en_port_count;
145         struct hlist_head en_port_hlist[TEAM_PORT_HASHENTRIES];
146
147         struct list_head port_list; /* list of all ports */
148
149         struct list_head option_list;
150         struct list_head option_inst_list; /* list of option instances */
151
152         const struct team_mode *mode;
153         struct team_mode_ops ops;
154         long mode_priv[TEAM_MODE_PRIV_LONGS];
155 };
156
157 static inline struct hlist_head *team_port_index_hash(struct team *team,
158                                                       int port_index)
159 {
160         return &team->en_port_hlist[port_index & (TEAM_PORT_HASHENTRIES - 1)];
161 }
162
163 static inline struct team_port *team_get_port_by_index(struct team *team,
164                                                        int port_index)
165 {
166         struct hlist_node *p;
167         struct team_port *port;
168         struct hlist_head *head = team_port_index_hash(team, port_index);
169
170         hlist_for_each_entry(port, p, head, hlist)
171                 if (port->index == port_index)
172                         return port;
173         return NULL;
174 }
175 static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
176                                                            int port_index)
177 {
178         struct hlist_node *p;
179         struct team_port *port;
180         struct hlist_head *head = team_port_index_hash(team, port_index);
181
182         hlist_for_each_entry_rcu(port, p, head, hlist)
183                 if (port->index == port_index)
184                         return port;
185         return NULL;
186 }
187
188 extern int team_port_set_team_mac(struct team_port *port);
189 extern int team_options_register(struct team *team,
190                                  const struct team_option *option,
191                                  size_t option_count);
192 extern void team_options_unregister(struct team *team,
193                                     const struct team_option *option,
194                                     size_t option_count);
195 extern int team_mode_register(const struct team_mode *mode);
196 extern void team_mode_unregister(const struct team_mode *mode);
197
198 #endif /* __KERNEL__ */
199
200 #define TEAM_STRING_MAX_LEN 32
201
202 /**********************************
203  * NETLINK_GENERIC netlink family.
204  **********************************/
205
206 enum {
207         TEAM_CMD_NOOP,
208         TEAM_CMD_OPTIONS_SET,
209         TEAM_CMD_OPTIONS_GET,
210         TEAM_CMD_PORT_LIST_GET,
211
212         __TEAM_CMD_MAX,
213         TEAM_CMD_MAX = (__TEAM_CMD_MAX - 1),
214 };
215
216 enum {
217         TEAM_ATTR_UNSPEC,
218         TEAM_ATTR_TEAM_IFINDEX,         /* u32 */
219         TEAM_ATTR_LIST_OPTION,          /* nest */
220         TEAM_ATTR_LIST_PORT,            /* nest */
221
222         __TEAM_ATTR_MAX,
223         TEAM_ATTR_MAX = __TEAM_ATTR_MAX - 1,
224 };
225
226 /* Nested layout of get/set msg:
227  *
228  *      [TEAM_ATTR_LIST_OPTION]
229  *              [TEAM_ATTR_ITEM_OPTION]
230  *                      [TEAM_ATTR_OPTION_*], ...
231  *              [TEAM_ATTR_ITEM_OPTION]
232  *                      [TEAM_ATTR_OPTION_*], ...
233  *              ...
234  *      [TEAM_ATTR_LIST_PORT]
235  *              [TEAM_ATTR_ITEM_PORT]
236  *                      [TEAM_ATTR_PORT_*], ...
237  *              [TEAM_ATTR_ITEM_PORT]
238  *                      [TEAM_ATTR_PORT_*], ...
239  *              ...
240  */
241
242 enum {
243         TEAM_ATTR_ITEM_OPTION_UNSPEC,
244         TEAM_ATTR_ITEM_OPTION,          /* nest */
245
246         __TEAM_ATTR_ITEM_OPTION_MAX,
247         TEAM_ATTR_ITEM_OPTION_MAX = __TEAM_ATTR_ITEM_OPTION_MAX - 1,
248 };
249
250 enum {
251         TEAM_ATTR_OPTION_UNSPEC,
252         TEAM_ATTR_OPTION_NAME,          /* string */
253         TEAM_ATTR_OPTION_CHANGED,       /* flag */
254         TEAM_ATTR_OPTION_TYPE,          /* u8 */
255         TEAM_ATTR_OPTION_DATA,          /* dynamic */
256         TEAM_ATTR_OPTION_REMOVED,       /* flag */
257         TEAM_ATTR_OPTION_PORT_IFINDEX,  /* u32 */ /* for per-port options */
258         TEAM_ATTR_OPTION_ARRAY_INDEX,   /* u32 */ /* for array options */
259
260         __TEAM_ATTR_OPTION_MAX,
261         TEAM_ATTR_OPTION_MAX = __TEAM_ATTR_OPTION_MAX - 1,
262 };
263
264 enum {
265         TEAM_ATTR_ITEM_PORT_UNSPEC,
266         TEAM_ATTR_ITEM_PORT,            /* nest */
267
268         __TEAM_ATTR_ITEM_PORT_MAX,
269         TEAM_ATTR_ITEM_PORT_MAX = __TEAM_ATTR_ITEM_PORT_MAX - 1,
270 };
271
272 enum {
273         TEAM_ATTR_PORT_UNSPEC,
274         TEAM_ATTR_PORT_IFINDEX,         /* u32 */
275         TEAM_ATTR_PORT_CHANGED,         /* flag */
276         TEAM_ATTR_PORT_LINKUP,          /* flag */
277         TEAM_ATTR_PORT_SPEED,           /* u32 */
278         TEAM_ATTR_PORT_DUPLEX,          /* u8 */
279         TEAM_ATTR_PORT_REMOVED,         /* flag */
280
281         __TEAM_ATTR_PORT_MAX,
282         TEAM_ATTR_PORT_MAX = __TEAM_ATTR_PORT_MAX - 1,
283 };
284
285 /*
286  * NETLINK_GENERIC related info
287  */
288 #define TEAM_GENL_NAME "team"
289 #define TEAM_GENL_VERSION 0x1
290 #define TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME "change_event"
291
292 #endif /* _LINUX_IF_TEAM_H_ */