blob: a5926c8584aa58406698991c174e54d756dc820b [file] [log] [blame]
Jiri Pirko3d249d42011-11-11 22:16:48 +00001/*
Jiri Pirko0d572e42012-06-19 05:54:09 +00002 * drivers/net/team/team.c - Network team device driver
Jiri Pirko3d249d42011-11-11 22:16:48 +00003 * 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#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/rcupdate.h>
17#include <linux/errno.h>
18#include <linux/ctype.h>
19#include <linux/notifier.h>
20#include <linux/netdevice.h>
Jiri Pirkobd2d0832012-07-17 05:22:36 +000021#include <linux/netpoll.h>
Jiri Pirko87002b02011-12-08 04:11:17 +000022#include <linux/if_vlan.h>
Jiri Pirko3d249d42011-11-11 22:16:48 +000023#include <linux/if_arp.h>
24#include <linux/socket.h>
25#include <linux/etherdevice.h>
26#include <linux/rtnetlink.h>
27#include <net/rtnetlink.h>
28#include <net/genetlink.h>
29#include <net/netlink.h>
Jiri Pirko6c85f2b2012-07-20 02:28:51 +000030#include <net/sch_generic.h>
Jiri Pirko3d249d42011-11-11 22:16:48 +000031#include <linux/if_team.h>
32
33#define DRV_NAME "team"
34
35
36/**********
37 * Helpers
38 **********/
39
40#define team_port_exists(dev) (dev->priv_flags & IFF_TEAM_PORT)
41
42static struct team_port *team_port_get_rcu(const struct net_device *dev)
43{
44 struct team_port *port = rcu_dereference(dev->rx_handler_data);
45
46 return team_port_exists(dev) ? port : NULL;
47}
48
49static struct team_port *team_port_get_rtnl(const struct net_device *dev)
50{
51 struct team_port *port = rtnl_dereference(dev->rx_handler_data);
52
53 return team_port_exists(dev) ? port : NULL;
54}
55
56/*
Jiri Pirko1d76efe2012-08-17 04:00:48 +000057 * Since the ability to change device address for open port device is tested in
Jiri Pirko3d249d42011-11-11 22:16:48 +000058 * team_port_add, this function can be called without control of return value
59 */
Jiri Pirko1d76efe2012-08-17 04:00:48 +000060static int __set_port_dev_addr(struct net_device *port_dev,
61 const unsigned char *dev_addr)
Jiri Pirko3d249d42011-11-11 22:16:48 +000062{
63 struct sockaddr addr;
64
Jiri Pirko1d76efe2012-08-17 04:00:48 +000065 memcpy(addr.sa_data, dev_addr, port_dev->addr_len);
66 addr.sa_family = port_dev->type;
Jiri Pirko3d249d42011-11-11 22:16:48 +000067 return dev_set_mac_address(port_dev, &addr);
68}
69
Jiri Pirko1d76efe2012-08-17 04:00:48 +000070static int team_port_set_orig_dev_addr(struct team_port *port)
Jiri Pirko3d249d42011-11-11 22:16:48 +000071{
Jiri Pirko1d76efe2012-08-17 04:00:48 +000072 return __set_port_dev_addr(port->dev, port->orig.dev_addr);
Jiri Pirko3d249d42011-11-11 22:16:48 +000073}
74
Jiri Pirko1d76efe2012-08-17 04:00:48 +000075int team_port_set_team_dev_addr(struct team_port *port)
Jiri Pirko3d249d42011-11-11 22:16:48 +000076{
Jiri Pirko1d76efe2012-08-17 04:00:48 +000077 return __set_port_dev_addr(port->dev, port->team->dev->dev_addr);
Jiri Pirko3d249d42011-11-11 22:16:48 +000078}
Jiri Pirko1d76efe2012-08-17 04:00:48 +000079EXPORT_SYMBOL(team_port_set_team_dev_addr);
Jiri Pirko3d249d42011-11-11 22:16:48 +000080
Jiri Pirko71472ec2012-04-10 05:15:44 +000081static void team_refresh_port_linkup(struct team_port *port)
82{
83 port->linkup = port->user.linkup_enabled ? port->user.linkup :
84 port->state.linkup;
85}
Jiri Pirko3d249d42011-11-11 22:16:48 +000086
Jiri Pirko0f1aad22012-06-19 05:54:11 +000087
Jiri Pirko3d249d42011-11-11 22:16:48 +000088/*******************
89 * Options handling
90 *******************/
91
Jiri Pirko80f7c662012-04-10 05:15:42 +000092struct team_option_inst { /* One for each option instance */
93 struct list_head list;
Jiri Pirko01048d92012-06-19 05:54:14 +000094 struct list_head tmp_list;
Jiri Pirko80f7c662012-04-10 05:15:42 +000095 struct team_option *option;
Jiri Pirko85d59a82012-06-19 05:54:10 +000096 struct team_option_inst_info info;
Jiri Pirko80f7c662012-04-10 05:15:42 +000097 bool changed;
98 bool removed;
99};
100
101static struct team_option *__team_find_option(struct team *team,
102 const char *opt_name)
Jiri Pirko358b8382011-11-16 11:09:09 +0000103{
104 struct team_option *option;
105
106 list_for_each_entry(option, &team->option_list, list) {
107 if (strcmp(option->name, opt_name) == 0)
108 return option;
109 }
110 return NULL;
111}
112
Jiri Pirko80f7c662012-04-10 05:15:42 +0000113static void __team_option_inst_del(struct team_option_inst *opt_inst)
114{
115 list_del(&opt_inst->list);
116 kfree(opt_inst);
117}
118
119static void __team_option_inst_del_option(struct team *team,
120 struct team_option *option)
121{
122 struct team_option_inst *opt_inst, *tmp;
123
124 list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
125 if (opt_inst->option == option)
126 __team_option_inst_del(opt_inst);
127 }
128}
129
Jiri Pirkob1303322012-06-19 05:54:08 +0000130static int __team_option_inst_add(struct team *team, struct team_option *option,
131 struct team_port *port)
132{
133 struct team_option_inst *opt_inst;
134 unsigned int array_size;
135 unsigned int i;
Jiri Pirko85d59a82012-06-19 05:54:10 +0000136 int err;
Jiri Pirkob1303322012-06-19 05:54:08 +0000137
138 array_size = option->array_size;
139 if (!array_size)
140 array_size = 1; /* No array but still need one instance */
141
142 for (i = 0; i < array_size; i++) {
143 opt_inst = kmalloc(sizeof(*opt_inst), GFP_KERNEL);
144 if (!opt_inst)
145 return -ENOMEM;
146 opt_inst->option = option;
Jiri Pirko85d59a82012-06-19 05:54:10 +0000147 opt_inst->info.port = port;
148 opt_inst->info.array_index = i;
Jiri Pirkob1303322012-06-19 05:54:08 +0000149 opt_inst->changed = true;
150 opt_inst->removed = false;
151 list_add_tail(&opt_inst->list, &team->option_inst_list);
Jiri Pirko85d59a82012-06-19 05:54:10 +0000152 if (option->init) {
153 err = option->init(team, &opt_inst->info);
154 if (err)
155 return err;
156 }
157
Jiri Pirkob1303322012-06-19 05:54:08 +0000158 }
159 return 0;
160}
161
Jiri Pirko80f7c662012-04-10 05:15:42 +0000162static int __team_option_inst_add_option(struct team *team,
163 struct team_option *option)
164{
165 struct team_port *port;
166 int err;
167
Jiri Pirkob1303322012-06-19 05:54:08 +0000168 if (!option->per_port) {
Jiri Pirkof88725f2012-06-19 05:54:15 +0000169 err = __team_option_inst_add(team, option, NULL);
Jiri Pirkob1303322012-06-19 05:54:08 +0000170 if (err)
171 goto inst_del_option;
172 }
Jiri Pirko80f7c662012-04-10 05:15:42 +0000173
174 list_for_each_entry(port, &team->port_list, list) {
175 err = __team_option_inst_add(team, option, port);
176 if (err)
177 goto inst_del_option;
178 }
179 return 0;
180
181inst_del_option:
182 __team_option_inst_del_option(team, option);
183 return err;
184}
185
186static void __team_option_inst_mark_removed_option(struct team *team,
187 struct team_option *option)
188{
189 struct team_option_inst *opt_inst;
190
191 list_for_each_entry(opt_inst, &team->option_inst_list, list) {
192 if (opt_inst->option == option) {
193 opt_inst->changed = true;
194 opt_inst->removed = true;
195 }
196 }
197}
198
199static void __team_option_inst_del_port(struct team *team,
200 struct team_port *port)
201{
202 struct team_option_inst *opt_inst, *tmp;
203
204 list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
205 if (opt_inst->option->per_port &&
Jiri Pirko85d59a82012-06-19 05:54:10 +0000206 opt_inst->info.port == port)
Jiri Pirko80f7c662012-04-10 05:15:42 +0000207 __team_option_inst_del(opt_inst);
208 }
209}
210
211static int __team_option_inst_add_port(struct team *team,
212 struct team_port *port)
213{
214 struct team_option *option;
215 int err;
216
217 list_for_each_entry(option, &team->option_list, list) {
218 if (!option->per_port)
219 continue;
220 err = __team_option_inst_add(team, option, port);
221 if (err)
222 goto inst_del_port;
223 }
224 return 0;
225
226inst_del_port:
227 __team_option_inst_del_port(team, port);
228 return err;
229}
230
231static void __team_option_inst_mark_removed_port(struct team *team,
232 struct team_port *port)
233{
234 struct team_option_inst *opt_inst;
235
236 list_for_each_entry(opt_inst, &team->option_inst_list, list) {
Jiri Pirko85d59a82012-06-19 05:54:10 +0000237 if (opt_inst->info.port == port) {
Jiri Pirko80f7c662012-04-10 05:15:42 +0000238 opt_inst->changed = true;
239 opt_inst->removed = true;
240 }
241 }
242}
243
244static int __team_options_register(struct team *team,
245 const struct team_option *option,
246 size_t option_count)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000247{
248 int i;
Jiri Pirko2bba19f2011-11-17 04:16:05 +0000249 struct team_option **dst_opts;
Jiri Pirko358b8382011-11-16 11:09:09 +0000250 int err;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000251
Jiri Pirko2bba19f2011-11-17 04:16:05 +0000252 dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
253 GFP_KERNEL);
254 if (!dst_opts)
255 return -ENOMEM;
Jiri Pirko358b8382011-11-16 11:09:09 +0000256 for (i = 0; i < option_count; i++, option++) {
Jiri Pirko358b8382011-11-16 11:09:09 +0000257 if (__team_find_option(team, option->name)) {
258 err = -EEXIST;
Jiri Pirko80f7c662012-04-10 05:15:42 +0000259 goto alloc_rollback;
Jiri Pirko358b8382011-11-16 11:09:09 +0000260 }
Jiri Pirkof8a15af2011-11-17 06:32:37 +0000261 dst_opts[i] = kmemdup(option, sizeof(*option), GFP_KERNEL);
262 if (!dst_opts[i]) {
Jiri Pirko358b8382011-11-16 11:09:09 +0000263 err = -ENOMEM;
Jiri Pirko80f7c662012-04-10 05:15:42 +0000264 goto alloc_rollback;
Jiri Pirko358b8382011-11-16 11:09:09 +0000265 }
Jiri Pirko358b8382011-11-16 11:09:09 +0000266 }
267
Jiri Pirkob82b9182012-01-24 05:16:00 +0000268 for (i = 0; i < option_count; i++) {
Jiri Pirko80f7c662012-04-10 05:15:42 +0000269 err = __team_option_inst_add_option(team, dst_opts[i]);
270 if (err)
271 goto inst_rollback;
Jiri Pirko358b8382011-11-16 11:09:09 +0000272 list_add_tail(&dst_opts[i]->list, &team->option_list);
Jiri Pirkob82b9182012-01-24 05:16:00 +0000273 }
Jiri Pirko358b8382011-11-16 11:09:09 +0000274
Jiri Pirko2bba19f2011-11-17 04:16:05 +0000275 kfree(dst_opts);
Jiri Pirko358b8382011-11-16 11:09:09 +0000276 return 0;
277
Jiri Pirko80f7c662012-04-10 05:15:42 +0000278inst_rollback:
279 for (i--; i >= 0; i--)
280 __team_option_inst_del_option(team, dst_opts[i]);
281
282 i = option_count - 1;
283alloc_rollback:
284 for (i--; i >= 0; i--)
Jiri Pirko358b8382011-11-16 11:09:09 +0000285 kfree(dst_opts[i]);
286
Jiri Pirko2bba19f2011-11-17 04:16:05 +0000287 kfree(dst_opts);
Jiri Pirko358b8382011-11-16 11:09:09 +0000288 return err;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000289}
Jiri Pirko358b8382011-11-16 11:09:09 +0000290
Jiri Pirkob82b9182012-01-24 05:16:00 +0000291static void __team_options_mark_removed(struct team *team,
292 const struct team_option *option,
293 size_t option_count)
294{
295 int i;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000296
Jiri Pirkob82b9182012-01-24 05:16:00 +0000297 for (i = 0; i < option_count; i++, option++) {
298 struct team_option *del_opt;
299
300 del_opt = __team_find_option(team, option->name);
Jiri Pirko80f7c662012-04-10 05:15:42 +0000301 if (del_opt)
302 __team_option_inst_mark_removed_option(team, del_opt);
Jiri Pirkob82b9182012-01-24 05:16:00 +0000303 }
304}
Jiri Pirko3d249d42011-11-11 22:16:48 +0000305
306static void __team_options_unregister(struct team *team,
Jiri Pirko358b8382011-11-16 11:09:09 +0000307 const struct team_option *option,
Jiri Pirko3d249d42011-11-11 22:16:48 +0000308 size_t option_count)
309{
310 int i;
311
Jiri Pirko358b8382011-11-16 11:09:09 +0000312 for (i = 0; i < option_count; i++, option++) {
313 struct team_option *del_opt;
314
315 del_opt = __team_find_option(team, option->name);
316 if (del_opt) {
Jiri Pirko80f7c662012-04-10 05:15:42 +0000317 __team_option_inst_del_option(team, del_opt);
Jiri Pirko358b8382011-11-16 11:09:09 +0000318 list_del(&del_opt->list);
319 kfree(del_opt);
320 }
321 }
Jiri Pirko3d249d42011-11-11 22:16:48 +0000322}
323
Jiri Pirkob82b9182012-01-24 05:16:00 +0000324static void __team_options_change_check(struct team *team);
325
326int team_options_register(struct team *team,
327 const struct team_option *option,
328 size_t option_count)
329{
330 int err;
331
332 err = __team_options_register(team, option, option_count);
333 if (err)
334 return err;
335 __team_options_change_check(team);
336 return 0;
337}
338EXPORT_SYMBOL(team_options_register);
339
Jiri Pirko358b8382011-11-16 11:09:09 +0000340void team_options_unregister(struct team *team,
341 const struct team_option *option,
Jiri Pirko3d249d42011-11-11 22:16:48 +0000342 size_t option_count)
343{
Jiri Pirkob82b9182012-01-24 05:16:00 +0000344 __team_options_mark_removed(team, option, option_count);
345 __team_options_change_check(team);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000346 __team_options_unregister(team, option, option_count);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000347}
348EXPORT_SYMBOL(team_options_unregister);
349
Jiri Pirko80f7c662012-04-10 05:15:42 +0000350static int team_option_get(struct team *team,
351 struct team_option_inst *opt_inst,
352 struct team_gsetter_ctx *ctx)
353{
Jiri Pirkof82b9592012-06-19 05:54:07 +0000354 if (!opt_inst->option->getter)
355 return -EOPNOTSUPP;
Jiri Pirko80f7c662012-04-10 05:15:42 +0000356 return opt_inst->option->getter(team, ctx);
357}
358
359static int team_option_set(struct team *team,
360 struct team_option_inst *opt_inst,
361 struct team_gsetter_ctx *ctx)
362{
Jiri Pirkof82b9592012-06-19 05:54:07 +0000363 if (!opt_inst->option->setter)
364 return -EOPNOTSUPP;
Jiri Pirko2fcdb2c2012-06-19 05:54:20 +0000365 return opt_inst->option->setter(team, ctx);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000366}
367
Jiri Pirko0f1aad22012-06-19 05:54:11 +0000368void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info)
369{
370 struct team_option_inst *opt_inst;
371
372 opt_inst = container_of(opt_inst_info, struct team_option_inst, info);
373 opt_inst->changed = true;
374}
375EXPORT_SYMBOL(team_option_inst_set_change);
376
377void team_options_change_check(struct team *team)
378{
379 __team_options_change_check(team);
380}
381EXPORT_SYMBOL(team_options_change_check);
382
383
Jiri Pirko3d249d42011-11-11 22:16:48 +0000384/****************
385 * Mode handling
386 ****************/
387
388static LIST_HEAD(mode_list);
389static DEFINE_SPINLOCK(mode_list_lock);
390
Jiri Pirko04027882012-06-19 05:54:03 +0000391struct team_mode_item {
392 struct list_head list;
393 const struct team_mode *mode;
394};
Jiri Pirko3d249d42011-11-11 22:16:48 +0000395
Jiri Pirko04027882012-06-19 05:54:03 +0000396static struct team_mode_item *__find_mode(const char *kind)
397{
398 struct team_mode_item *mitem;
399
400 list_for_each_entry(mitem, &mode_list, list) {
401 if (strcmp(mitem->mode->kind, kind) == 0)
402 return mitem;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000403 }
404 return NULL;
405}
406
407static bool is_good_mode_name(const char *name)
408{
409 while (*name != '\0') {
410 if (!isalpha(*name) && !isdigit(*name) && *name != '_')
411 return false;
412 name++;
413 }
414 return true;
415}
416
Jiri Pirko04027882012-06-19 05:54:03 +0000417int team_mode_register(const struct team_mode *mode)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000418{
419 int err = 0;
Jiri Pirko04027882012-06-19 05:54:03 +0000420 struct team_mode_item *mitem;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000421
422 if (!is_good_mode_name(mode->kind) ||
423 mode->priv_size > TEAM_MODE_PRIV_SIZE)
424 return -EINVAL;
Jiri Pirko04027882012-06-19 05:54:03 +0000425
426 mitem = kmalloc(sizeof(*mitem), GFP_KERNEL);
427 if (!mitem)
428 return -ENOMEM;
429
Jiri Pirko3d249d42011-11-11 22:16:48 +0000430 spin_lock(&mode_list_lock);
431 if (__find_mode(mode->kind)) {
432 err = -EEXIST;
Jiri Pirko04027882012-06-19 05:54:03 +0000433 kfree(mitem);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000434 goto unlock;
435 }
Jiri Pirko04027882012-06-19 05:54:03 +0000436 mitem->mode = mode;
437 list_add_tail(&mitem->list, &mode_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000438unlock:
439 spin_unlock(&mode_list_lock);
440 return err;
441}
442EXPORT_SYMBOL(team_mode_register);
443
Jiri Pirko04027882012-06-19 05:54:03 +0000444void team_mode_unregister(const struct team_mode *mode)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000445{
Jiri Pirko04027882012-06-19 05:54:03 +0000446 struct team_mode_item *mitem;
447
Jiri Pirko3d249d42011-11-11 22:16:48 +0000448 spin_lock(&mode_list_lock);
Jiri Pirko04027882012-06-19 05:54:03 +0000449 mitem = __find_mode(mode->kind);
450 if (mitem) {
451 list_del_init(&mitem->list);
452 kfree(mitem);
453 }
Jiri Pirko3d249d42011-11-11 22:16:48 +0000454 spin_unlock(&mode_list_lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000455}
456EXPORT_SYMBOL(team_mode_unregister);
457
Jiri Pirko04027882012-06-19 05:54:03 +0000458static const struct team_mode *team_mode_get(const char *kind)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000459{
Jiri Pirko04027882012-06-19 05:54:03 +0000460 struct team_mode_item *mitem;
461 const struct team_mode *mode = NULL;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000462
463 spin_lock(&mode_list_lock);
Jiri Pirko04027882012-06-19 05:54:03 +0000464 mitem = __find_mode(kind);
465 if (!mitem) {
Jiri Pirko3d249d42011-11-11 22:16:48 +0000466 spin_unlock(&mode_list_lock);
467 request_module("team-mode-%s", kind);
468 spin_lock(&mode_list_lock);
Jiri Pirko04027882012-06-19 05:54:03 +0000469 mitem = __find_mode(kind);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000470 }
Jiri Pirko04027882012-06-19 05:54:03 +0000471 if (mitem) {
472 mode = mitem->mode;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000473 if (!try_module_get(mode->owner))
474 mode = NULL;
Jiri Pirko04027882012-06-19 05:54:03 +0000475 }
Jiri Pirko3d249d42011-11-11 22:16:48 +0000476
477 spin_unlock(&mode_list_lock);
478 return mode;
479}
480
481static void team_mode_put(const struct team_mode *mode)
482{
483 module_put(mode->owner);
484}
485
486static bool team_dummy_transmit(struct team *team, struct sk_buff *skb)
487{
488 dev_kfree_skb_any(skb);
489 return false;
490}
491
492rx_handler_result_t team_dummy_receive(struct team *team,
493 struct team_port *port,
494 struct sk_buff *skb)
495{
496 return RX_HANDLER_ANOTHER;
497}
498
Jiri Pirkod299cd52012-06-19 05:54:04 +0000499static const struct team_mode __team_no_mode = {
500 .kind = "*NOMODE*",
501};
502
503static bool team_is_mode_set(struct team *team)
504{
505 return team->mode != &__team_no_mode;
506}
507
508static void team_set_no_mode(struct team *team)
509{
510 team->mode = &__team_no_mode;
511}
512
Jiri Pirko122bb042012-06-26 06:52:45 +0000513static void __team_adjust_ops(struct team *team, int en_port_count)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000514{
515 /*
516 * To avoid checks in rx/tx skb paths, ensure here that non-null and
517 * correct ops are always set.
518 */
519
Jiri Pirko122bb042012-06-26 06:52:45 +0000520 if (!en_port_count || !team_is_mode_set(team) ||
521 !team->mode->ops->transmit)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000522 team->ops.transmit = team_dummy_transmit;
523 else
524 team->ops.transmit = team->mode->ops->transmit;
525
Jiri Pirko122bb042012-06-26 06:52:45 +0000526 if (!en_port_count || !team_is_mode_set(team) ||
527 !team->mode->ops->receive)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000528 team->ops.receive = team_dummy_receive;
529 else
530 team->ops.receive = team->mode->ops->receive;
531}
532
Jiri Pirko122bb042012-06-26 06:52:45 +0000533static void team_adjust_ops(struct team *team)
534{
535 __team_adjust_ops(team, team->en_port_count);
536}
537
Jiri Pirko3d249d42011-11-11 22:16:48 +0000538/*
539 * We can benefit from the fact that it's ensured no port is present
540 * at the time of mode change. Therefore no packets are in fly so there's no
541 * need to set mode operations in any special way.
542 */
543static int __team_change_mode(struct team *team,
544 const struct team_mode *new_mode)
545{
546 /* Check if mode was previously set and do cleanup if so */
Jiri Pirkod299cd52012-06-19 05:54:04 +0000547 if (team_is_mode_set(team)) {
Jiri Pirko3d249d42011-11-11 22:16:48 +0000548 void (*exit_op)(struct team *team) = team->ops.exit;
549
550 /* Clear ops area so no callback is called any longer */
551 memset(&team->ops, 0, sizeof(struct team_mode_ops));
552 team_adjust_ops(team);
553
554 if (exit_op)
555 exit_op(team);
556 team_mode_put(team->mode);
Jiri Pirkod299cd52012-06-19 05:54:04 +0000557 team_set_no_mode(team);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000558 /* zero private data area */
559 memset(&team->mode_priv, 0,
560 sizeof(struct team) - offsetof(struct team, mode_priv));
561 }
562
563 if (!new_mode)
564 return 0;
565
566 if (new_mode->ops->init) {
567 int err;
568
569 err = new_mode->ops->init(team);
570 if (err)
571 return err;
572 }
573
574 team->mode = new_mode;
575 memcpy(&team->ops, new_mode->ops, sizeof(struct team_mode_ops));
576 team_adjust_ops(team);
577
578 return 0;
579}
580
581static int team_change_mode(struct team *team, const char *kind)
582{
Jiri Pirko04027882012-06-19 05:54:03 +0000583 const struct team_mode *new_mode;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000584 struct net_device *dev = team->dev;
585 int err;
586
587 if (!list_empty(&team->port_list)) {
588 netdev_err(dev, "No ports can be present during mode change\n");
589 return -EBUSY;
590 }
591
Jiri Pirkod299cd52012-06-19 05:54:04 +0000592 if (team_is_mode_set(team) && strcmp(team->mode->kind, kind) == 0) {
Jiri Pirko3d249d42011-11-11 22:16:48 +0000593 netdev_err(dev, "Unable to change to the same mode the team is in\n");
594 return -EINVAL;
595 }
596
597 new_mode = team_mode_get(kind);
598 if (!new_mode) {
599 netdev_err(dev, "Mode \"%s\" not found\n", kind);
600 return -EINVAL;
601 }
602
603 err = __team_change_mode(team, new_mode);
604 if (err) {
605 netdev_err(dev, "Failed to change to mode \"%s\"\n", kind);
606 team_mode_put(new_mode);
607 return err;
608 }
609
610 netdev_info(dev, "Mode changed to \"%s\"\n", kind);
611 return 0;
612}
613
614
615/************************
616 * Rx path frame handler
617 ************************/
618
619/* note: already called with rcu_read_lock */
620static rx_handler_result_t team_handle_frame(struct sk_buff **pskb)
621{
622 struct sk_buff *skb = *pskb;
623 struct team_port *port;
624 struct team *team;
625 rx_handler_result_t res;
626
627 skb = skb_share_check(skb, GFP_ATOMIC);
628 if (!skb)
629 return RX_HANDLER_CONSUMED;
630
631 *pskb = skb;
632
633 port = team_port_get_rcu(skb->dev);
634 team = port->team;
Jiri Pirko19a0b582012-04-20 04:42:05 +0000635 if (!team_port_enabled(port)) {
636 /* allow exact match delivery for disabled ports */
637 res = RX_HANDLER_EXACT;
638 } else {
639 res = team->ops.receive(team, port, skb);
640 }
Jiri Pirko3d249d42011-11-11 22:16:48 +0000641 if (res == RX_HANDLER_ANOTHER) {
642 struct team_pcpu_stats *pcpu_stats;
643
644 pcpu_stats = this_cpu_ptr(team->pcpu_stats);
645 u64_stats_update_begin(&pcpu_stats->syncp);
646 pcpu_stats->rx_packets++;
647 pcpu_stats->rx_bytes += skb->len;
648 if (skb->pkt_type == PACKET_MULTICAST)
649 pcpu_stats->rx_multicast++;
650 u64_stats_update_end(&pcpu_stats->syncp);
651
652 skb->dev = team->dev;
653 } else {
654 this_cpu_inc(team->pcpu_stats->rx_dropped);
655 }
656
657 return res;
658}
659
660
Jiri Pirko8ff51052012-07-27 06:28:55 +0000661/*************************************
662 * Multiqueue Tx port select override
663 *************************************/
664
665static int team_queue_override_init(struct team *team)
666{
667 struct list_head *listarr;
668 unsigned int queue_cnt = team->dev->num_tx_queues - 1;
669 unsigned int i;
670
671 if (!queue_cnt)
672 return 0;
673 listarr = kmalloc(sizeof(struct list_head) * queue_cnt, GFP_KERNEL);
674 if (!listarr)
675 return -ENOMEM;
676 team->qom_lists = listarr;
677 for (i = 0; i < queue_cnt; i++)
678 INIT_LIST_HEAD(listarr++);
679 return 0;
680}
681
682static void team_queue_override_fini(struct team *team)
683{
684 kfree(team->qom_lists);
685}
686
687static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id)
688{
689 return &team->qom_lists[queue_id - 1];
690}
691
692/*
693 * note: already called with rcu_read_lock
694 */
695static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb)
696{
697 struct list_head *qom_list;
698 struct team_port *port;
699
700 if (!team->queue_override_enabled || !skb->queue_mapping)
701 return false;
702 qom_list = __team_get_qom_list(team, skb->queue_mapping);
703 list_for_each_entry_rcu(port, qom_list, qom_list) {
704 if (!team_dev_queue_xmit(team, port, skb))
705 return true;
706 }
707 return false;
708}
709
710static void __team_queue_override_port_del(struct team *team,
711 struct team_port *port)
712{
713 list_del_rcu(&port->qom_list);
714 synchronize_rcu();
715 INIT_LIST_HEAD(&port->qom_list);
716}
717
718static bool team_queue_override_port_has_gt_prio_than(struct team_port *port,
719 struct team_port *cur)
720{
721 if (port->priority < cur->priority)
722 return true;
723 if (port->priority > cur->priority)
724 return false;
725 if (port->index < cur->index)
726 return true;
727 return false;
728}
729
730static void __team_queue_override_port_add(struct team *team,
731 struct team_port *port)
732{
733 struct team_port *cur;
734 struct list_head *qom_list;
735 struct list_head *node;
736
737 if (!port->queue_id || !team_port_enabled(port))
738 return;
739
740 qom_list = __team_get_qom_list(team, port->queue_id);
741 node = qom_list;
742 list_for_each_entry(cur, qom_list, qom_list) {
743 if (team_queue_override_port_has_gt_prio_than(port, cur))
744 break;
745 node = &cur->qom_list;
746 }
747 list_add_tail_rcu(&port->qom_list, node);
748}
749
750static void __team_queue_override_enabled_check(struct team *team)
751{
752 struct team_port *port;
753 bool enabled = false;
754
755 list_for_each_entry(port, &team->port_list, list) {
756 if (!list_empty(&port->qom_list)) {
757 enabled = true;
758 break;
759 }
760 }
761 if (enabled == team->queue_override_enabled)
762 return;
763 netdev_dbg(team->dev, "%s queue override\n",
764 enabled ? "Enabling" : "Disabling");
765 team->queue_override_enabled = enabled;
766}
767
768static void team_queue_override_port_refresh(struct team *team,
769 struct team_port *port)
770{
771 __team_queue_override_port_del(team, port);
772 __team_queue_override_port_add(team, port);
773 __team_queue_override_enabled_check(team);
774}
775
776
Jiri Pirko3d249d42011-11-11 22:16:48 +0000777/****************
778 * Port handling
779 ****************/
780
781static bool team_port_find(const struct team *team,
782 const struct team_port *port)
783{
784 struct team_port *cur;
785
786 list_for_each_entry(cur, &team->port_list, list)
787 if (cur == port)
788 return true;
789 return false;
790}
791
Jiri Pirko19a0b582012-04-20 04:42:05 +0000792/*
793 * Enable/disable port by adding to enabled port hashlist and setting
794 * port->index (Might be racy so reader could see incorrect ifindex when
795 * processing a flying packet, but that is not a problem). Write guarded
796 * by team->lock.
797 */
798static void team_port_enable(struct team *team,
799 struct team_port *port)
800{
801 if (team_port_enabled(port))
802 return;
803 port->index = team->en_port_count++;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000804 hlist_add_head_rcu(&port->hlist,
805 team_port_index_hash(team, port->index));
Jiri Pirko122bb042012-06-26 06:52:45 +0000806 team_adjust_ops(team);
Jiri Pirko8ff51052012-07-27 06:28:55 +0000807 team_queue_override_port_refresh(team, port);
Jiri Pirko4bccfd12012-06-19 05:54:16 +0000808 if (team->ops.port_enabled)
809 team->ops.port_enabled(team, port);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000810}
811
812static void __reconstruct_port_hlist(struct team *team, int rm_index)
813{
814 int i;
815 struct team_port *port;
816
Jiri Pirko19a0b582012-04-20 04:42:05 +0000817 for (i = rm_index + 1; i < team->en_port_count; i++) {
Jiri Pirko3d249d42011-11-11 22:16:48 +0000818 port = team_get_port_by_index(team, i);
819 hlist_del_rcu(&port->hlist);
820 port->index--;
821 hlist_add_head_rcu(&port->hlist,
822 team_port_index_hash(team, port->index));
823 }
824}
825
Jiri Pirko19a0b582012-04-20 04:42:05 +0000826static void team_port_disable(struct team *team,
827 struct team_port *port)
Jiri Pirko3d249d42011-11-11 22:16:48 +0000828{
Jiri Pirko19a0b582012-04-20 04:42:05 +0000829 if (!team_port_enabled(port))
830 return;
Jiri Pirko4bccfd12012-06-19 05:54:16 +0000831 if (team->ops.port_disabled)
832 team->ops.port_disabled(team, port);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000833 hlist_del_rcu(&port->hlist);
Jiri Pirko122bb042012-06-26 06:52:45 +0000834 __reconstruct_port_hlist(team, port->index);
Jiri Pirko19a0b582012-04-20 04:42:05 +0000835 port->index = -1;
Jiri Pirko8ff51052012-07-27 06:28:55 +0000836 team_queue_override_port_refresh(team, port);
Jiri Pirko122bb042012-06-26 06:52:45 +0000837 __team_adjust_ops(team, team->en_port_count - 1);
838 /*
839 * Wait until readers see adjusted ops. This ensures that
840 * readers never see team->en_port_count == 0
841 */
842 synchronize_rcu();
843 team->en_port_count--;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000844}
845
846#define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
847 NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
848 NETIF_F_HIGHDMA | NETIF_F_LRO)
849
850static void __team_compute_features(struct team *team)
851{
852 struct team_port *port;
853 u32 vlan_features = TEAM_VLAN_FEATURES;
854 unsigned short max_hard_header_len = ETH_HLEN;
Jiri Pirkodc905952012-07-18 07:39:38 +0000855 unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000856
857 list_for_each_entry(port, &team->port_list, list) {
858 vlan_features = netdev_increment_features(vlan_features,
859 port->dev->vlan_features,
860 TEAM_VLAN_FEATURES);
861
Jiri Pirkodc905952012-07-18 07:39:38 +0000862 dst_release_flag &= port->dev->priv_flags;
Jiri Pirko3d249d42011-11-11 22:16:48 +0000863 if (port->dev->hard_header_len > max_hard_header_len)
864 max_hard_header_len = port->dev->hard_header_len;
865 }
866
867 team->dev->vlan_features = vlan_features;
868 team->dev->hard_header_len = max_hard_header_len;
869
Jiri Pirkodc905952012-07-18 07:39:38 +0000870 flags = team->dev->priv_flags & ~IFF_XMIT_DST_RELEASE;
871 team->dev->priv_flags = flags | dst_release_flag;
872
Jiri Pirko3d249d42011-11-11 22:16:48 +0000873 netdev_change_features(team->dev);
874}
875
876static void team_compute_features(struct team *team)
877{
Jiri Pirko61dc3462011-11-16 11:09:08 +0000878 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000879 __team_compute_features(team);
Jiri Pirko61dc3462011-11-16 11:09:08 +0000880 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000881}
882
883static int team_port_enter(struct team *team, struct team_port *port)
884{
885 int err = 0;
886
887 dev_hold(team->dev);
888 port->dev->priv_flags |= IFF_TEAM_PORT;
889 if (team->ops.port_enter) {
890 err = team->ops.port_enter(team, port);
891 if (err) {
892 netdev_err(team->dev, "Device %s failed to enter team mode\n",
893 port->dev->name);
894 goto err_port_enter;
895 }
896 }
897
898 return 0;
899
900err_port_enter:
901 port->dev->priv_flags &= ~IFF_TEAM_PORT;
902 dev_put(team->dev);
903
904 return err;
905}
906
907static void team_port_leave(struct team *team, struct team_port *port)
908{
909 if (team->ops.port_leave)
910 team->ops.port_leave(team, port);
911 port->dev->priv_flags &= ~IFF_TEAM_PORT;
912 dev_put(team->dev);
913}
914
Jiri Pirkobd2d0832012-07-17 05:22:36 +0000915#ifdef CONFIG_NET_POLL_CONTROLLER
Amerigo Wang47be03a22012-08-10 01:24:37 +0000916static int team_port_enable_netpoll(struct team *team, struct team_port *port,
917 gfp_t gfp)
Jiri Pirkobd2d0832012-07-17 05:22:36 +0000918{
919 struct netpoll *np;
920 int err;
921
Amerigo Wang47be03a22012-08-10 01:24:37 +0000922 np = kzalloc(sizeof(*np), gfp);
Jiri Pirkobd2d0832012-07-17 05:22:36 +0000923 if (!np)
924 return -ENOMEM;
925
Amerigo Wang47be03a22012-08-10 01:24:37 +0000926 err = __netpoll_setup(np, port->dev, gfp);
Jiri Pirkobd2d0832012-07-17 05:22:36 +0000927 if (err) {
928 kfree(np);
929 return err;
930 }
931 port->np = np;
932 return err;
933}
934
935static void team_port_disable_netpoll(struct team_port *port)
936{
937 struct netpoll *np = port->np;
938
939 if (!np)
940 return;
941 port->np = NULL;
942
943 /* Wait for transmitting packets to finish before freeing. */
944 synchronize_rcu_bh();
945 __netpoll_cleanup(np);
946 kfree(np);
947}
948
949static struct netpoll_info *team_netpoll_info(struct team *team)
950{
951 return team->dev->npinfo;
952}
953
954#else
Amerigo Wang47be03a22012-08-10 01:24:37 +0000955static int team_port_enable_netpoll(struct team *team, struct team_port *port,
956 gfp_t gfp)
Jiri Pirkobd2d0832012-07-17 05:22:36 +0000957{
958 return 0;
959}
960static void team_port_disable_netpoll(struct team_port *port)
961{
962}
963static struct netpoll_info *team_netpoll_info(struct team *team)
964{
965 return NULL;
966}
967#endif
968
Jiri Pirko3d249d42011-11-11 22:16:48 +0000969static void __team_port_change_check(struct team_port *port, bool linkup);
Jiri Pirko1d76efe2012-08-17 04:00:48 +0000970static int team_dev_type_check_change(struct net_device *dev,
971 struct net_device *port_dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +0000972
973static int team_port_add(struct team *team, struct net_device *port_dev)
974{
975 struct net_device *dev = team->dev;
976 struct team_port *port;
977 char *portname = port_dev->name;
978 int err;
979
Jiri Pirko1d76efe2012-08-17 04:00:48 +0000980 if (port_dev->flags & IFF_LOOPBACK) {
981 netdev_err(dev, "Device %s is loopback device. Loopback devices can't be added as a team port\n",
Jiri Pirko3d249d42011-11-11 22:16:48 +0000982 portname);
983 return -EINVAL;
984 }
985
986 if (team_port_exists(port_dev)) {
987 netdev_err(dev, "Device %s is already a port "
988 "of a team device\n", portname);
989 return -EBUSY;
990 }
991
Jiri Pirko1d76efe2012-08-17 04:00:48 +0000992 err = team_dev_type_check_change(dev, port_dev);
993 if (err)
994 return err;
995
Jiri Pirko3d249d42011-11-11 22:16:48 +0000996 if (port_dev->flags & IFF_UP) {
997 netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
998 portname);
999 return -EBUSY;
1000 }
1001
Jiri Pirko5149ee52012-06-19 05:54:05 +00001002 port = kzalloc(sizeof(struct team_port) + team->mode->port_priv_size,
1003 GFP_KERNEL);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001004 if (!port)
1005 return -ENOMEM;
1006
1007 port->dev = port_dev;
1008 port->team = team;
Jiri Pirko8ff51052012-07-27 06:28:55 +00001009 INIT_LIST_HEAD(&port->qom_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001010
1011 port->orig.mtu = port_dev->mtu;
1012 err = dev_set_mtu(port_dev, dev->mtu);
1013 if (err) {
1014 netdev_dbg(dev, "Error %d calling dev_set_mtu\n", err);
1015 goto err_set_mtu;
1016 }
1017
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001018 memcpy(port->orig.dev_addr, port_dev->dev_addr, port_dev->addr_len);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001019
1020 err = team_port_enter(team, port);
1021 if (err) {
1022 netdev_err(dev, "Device %s failed to enter team mode\n",
1023 portname);
1024 goto err_port_enter;
1025 }
1026
1027 err = dev_open(port_dev);
1028 if (err) {
1029 netdev_dbg(dev, "Device %s opening failed\n",
1030 portname);
1031 goto err_dev_open;
1032 }
1033
Jiri Pirko57459182011-12-08 04:11:20 +00001034 err = vlan_vids_add_by_dev(port_dev, dev);
1035 if (err) {
1036 netdev_err(dev, "Failed to add vlan ids to device %s\n",
1037 portname);
1038 goto err_vids_add;
1039 }
1040
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001041 if (team_netpoll_info(team)) {
Amerigo Wang47be03a22012-08-10 01:24:37 +00001042 err = team_port_enable_netpoll(team, port, GFP_KERNEL);
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001043 if (err) {
1044 netdev_err(dev, "Failed to enable netpoll on device %s\n",
1045 portname);
1046 goto err_enable_netpoll;
1047 }
1048 }
1049
Jiri Pirko3d249d42011-11-11 22:16:48 +00001050 err = netdev_set_master(port_dev, dev);
1051 if (err) {
1052 netdev_err(dev, "Device %s failed to set master\n", portname);
1053 goto err_set_master;
1054 }
1055
1056 err = netdev_rx_handler_register(port_dev, team_handle_frame,
1057 port);
1058 if (err) {
1059 netdev_err(dev, "Device %s failed to register rx_handler\n",
1060 portname);
1061 goto err_handler_register;
1062 }
1063
Jiri Pirko35b384b2012-06-19 05:54:19 +00001064 err = __team_option_inst_add_port(team, port);
Jiri Pirko80f7c662012-04-10 05:15:42 +00001065 if (err) {
1066 netdev_err(dev, "Device %s failed to add per-port options\n",
1067 portname);
1068 goto err_option_port_add;
1069 }
1070
Jiri Pirko19a0b582012-04-20 04:42:05 +00001071 port->index = -1;
1072 team_port_enable(team, port);
1073 list_add_tail_rcu(&port->list, &team->port_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001074 __team_compute_features(team);
1075 __team_port_change_check(port, !!netif_carrier_ok(port_dev));
Jiri Pirko35b384b2012-06-19 05:54:19 +00001076 __team_options_change_check(team);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001077
1078 netdev_info(dev, "Port device %s added\n", portname);
1079
1080 return 0;
1081
Jiri Pirko80f7c662012-04-10 05:15:42 +00001082err_option_port_add:
1083 netdev_rx_handler_unregister(port_dev);
1084
Jiri Pirko3d249d42011-11-11 22:16:48 +00001085err_handler_register:
1086 netdev_set_master(port_dev, NULL);
1087
1088err_set_master:
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001089 team_port_disable_netpoll(port);
1090
1091err_enable_netpoll:
Jiri Pirko57459182011-12-08 04:11:20 +00001092 vlan_vids_del_by_dev(port_dev, dev);
1093
1094err_vids_add:
Jiri Pirko3d249d42011-11-11 22:16:48 +00001095 dev_close(port_dev);
1096
1097err_dev_open:
1098 team_port_leave(team, port);
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001099 team_port_set_orig_dev_addr(port);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001100
1101err_port_enter:
1102 dev_set_mtu(port_dev, port->orig.mtu);
1103
1104err_set_mtu:
1105 kfree(port);
1106
1107 return err;
1108}
1109
1110static int team_port_del(struct team *team, struct net_device *port_dev)
1111{
1112 struct net_device *dev = team->dev;
1113 struct team_port *port;
1114 char *portname = port_dev->name;
1115
1116 port = team_port_get_rtnl(port_dev);
1117 if (!port || !team_port_find(team, port)) {
1118 netdev_err(dev, "Device %s does not act as a port of this team\n",
1119 portname);
1120 return -ENOENT;
1121 }
1122
Jiri Pirko35b384b2012-06-19 05:54:19 +00001123 __team_option_inst_mark_removed_port(team, port);
1124 __team_options_change_check(team);
1125 __team_option_inst_del_port(team, port);
Jiri Pirkob82b9182012-01-24 05:16:00 +00001126 port->removed = true;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001127 __team_port_change_check(port, false);
Jiri Pirko19a0b582012-04-20 04:42:05 +00001128 team_port_disable(team, port);
1129 list_del_rcu(&port->list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001130 netdev_rx_handler_unregister(port_dev);
1131 netdev_set_master(port_dev, NULL);
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001132 team_port_disable_netpoll(port);
Jiri Pirko57459182011-12-08 04:11:20 +00001133 vlan_vids_del_by_dev(port_dev, dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001134 dev_close(port_dev);
1135 team_port_leave(team, port);
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001136 team_port_set_orig_dev_addr(port);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001137 dev_set_mtu(port_dev, port->orig.mtu);
1138 synchronize_rcu();
1139 kfree(port);
1140 netdev_info(dev, "Port device %s removed\n", portname);
1141 __team_compute_features(team);
1142
1143 return 0;
1144}
1145
1146
1147/*****************
1148 * Net device ops
1149 *****************/
1150
Jiri Pirko80f7c662012-04-10 05:15:42 +00001151static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx)
Jiri Pirko3d249d42011-11-11 22:16:48 +00001152{
Jiri Pirkod299cd52012-06-19 05:54:04 +00001153 ctx->data.str_val = team->mode->kind;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001154 return 0;
1155}
1156
Jiri Pirko80f7c662012-04-10 05:15:42 +00001157static int team_mode_option_set(struct team *team, struct team_gsetter_ctx *ctx)
Jiri Pirko3d249d42011-11-11 22:16:48 +00001158{
Jiri Pirko80f7c662012-04-10 05:15:42 +00001159 return team_change_mode(team, ctx->data.str_val);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001160}
1161
Jiri Pirkoacd69962012-04-20 04:42:06 +00001162static int team_port_en_option_get(struct team *team,
1163 struct team_gsetter_ctx *ctx)
1164{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001165 struct team_port *port = ctx->info->port;
1166
1167 ctx->data.bool_val = team_port_enabled(port);
Jiri Pirkoacd69962012-04-20 04:42:06 +00001168 return 0;
1169}
1170
1171static int team_port_en_option_set(struct team *team,
1172 struct team_gsetter_ctx *ctx)
1173{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001174 struct team_port *port = ctx->info->port;
1175
Jiri Pirkoacd69962012-04-20 04:42:06 +00001176 if (ctx->data.bool_val)
Jiri Pirko85d59a82012-06-19 05:54:10 +00001177 team_port_enable(team, port);
Jiri Pirkoacd69962012-04-20 04:42:06 +00001178 else
Jiri Pirko85d59a82012-06-19 05:54:10 +00001179 team_port_disable(team, port);
Jiri Pirkoacd69962012-04-20 04:42:06 +00001180 return 0;
1181}
1182
Jiri Pirko71472ec2012-04-10 05:15:44 +00001183static int team_user_linkup_option_get(struct team *team,
1184 struct team_gsetter_ctx *ctx)
1185{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001186 struct team_port *port = ctx->info->port;
1187
1188 ctx->data.bool_val = port->user.linkup;
Jiri Pirko71472ec2012-04-10 05:15:44 +00001189 return 0;
1190}
1191
1192static int team_user_linkup_option_set(struct team *team,
1193 struct team_gsetter_ctx *ctx)
1194{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001195 struct team_port *port = ctx->info->port;
1196
1197 port->user.linkup = ctx->data.bool_val;
1198 team_refresh_port_linkup(port);
Jiri Pirko71472ec2012-04-10 05:15:44 +00001199 return 0;
1200}
1201
1202static int team_user_linkup_en_option_get(struct team *team,
1203 struct team_gsetter_ctx *ctx)
1204{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001205 struct team_port *port = ctx->info->port;
Jiri Pirko71472ec2012-04-10 05:15:44 +00001206
1207 ctx->data.bool_val = port->user.linkup_enabled;
1208 return 0;
1209}
1210
1211static int team_user_linkup_en_option_set(struct team *team,
1212 struct team_gsetter_ctx *ctx)
1213{
Jiri Pirko85d59a82012-06-19 05:54:10 +00001214 struct team_port *port = ctx->info->port;
Jiri Pirko71472ec2012-04-10 05:15:44 +00001215
1216 port->user.linkup_enabled = ctx->data.bool_val;
Jiri Pirko85d59a82012-06-19 05:54:10 +00001217 team_refresh_port_linkup(port);
Jiri Pirko71472ec2012-04-10 05:15:44 +00001218 return 0;
1219}
1220
Jiri Pirkoa86fc6b2012-07-27 06:28:54 +00001221static int team_priority_option_get(struct team *team,
1222 struct team_gsetter_ctx *ctx)
1223{
1224 struct team_port *port = ctx->info->port;
1225
1226 ctx->data.s32_val = port->priority;
1227 return 0;
1228}
1229
1230static int team_priority_option_set(struct team *team,
1231 struct team_gsetter_ctx *ctx)
1232{
1233 struct team_port *port = ctx->info->port;
1234
1235 port->priority = ctx->data.s32_val;
Jiri Pirko8ff51052012-07-27 06:28:55 +00001236 team_queue_override_port_refresh(team, port);
Jiri Pirkoa86fc6b2012-07-27 06:28:54 +00001237 return 0;
1238}
1239
Jiri Pirko8ff51052012-07-27 06:28:55 +00001240static int team_queue_id_option_get(struct team *team,
1241 struct team_gsetter_ctx *ctx)
1242{
1243 struct team_port *port = ctx->info->port;
1244
1245 ctx->data.u32_val = port->queue_id;
1246 return 0;
1247}
1248
1249static int team_queue_id_option_set(struct team *team,
1250 struct team_gsetter_ctx *ctx)
1251{
1252 struct team_port *port = ctx->info->port;
1253
1254 if (port->queue_id == ctx->data.u32_val)
1255 return 0;
1256 if (ctx->data.u32_val >= team->dev->real_num_tx_queues)
1257 return -EINVAL;
1258 port->queue_id = ctx->data.u32_val;
1259 team_queue_override_port_refresh(team, port);
1260 return 0;
1261}
1262
1263
Jiri Pirko358b8382011-11-16 11:09:09 +00001264static const struct team_option team_options[] = {
Jiri Pirko3d249d42011-11-11 22:16:48 +00001265 {
1266 .name = "mode",
1267 .type = TEAM_OPTION_TYPE_STRING,
1268 .getter = team_mode_option_get,
1269 .setter = team_mode_option_set,
1270 },
Jiri Pirko71472ec2012-04-10 05:15:44 +00001271 {
Jiri Pirkoacd69962012-04-20 04:42:06 +00001272 .name = "enabled",
1273 .type = TEAM_OPTION_TYPE_BOOL,
1274 .per_port = true,
1275 .getter = team_port_en_option_get,
1276 .setter = team_port_en_option_set,
1277 },
1278 {
Jiri Pirko71472ec2012-04-10 05:15:44 +00001279 .name = "user_linkup",
1280 .type = TEAM_OPTION_TYPE_BOOL,
1281 .per_port = true,
1282 .getter = team_user_linkup_option_get,
1283 .setter = team_user_linkup_option_set,
1284 },
1285 {
1286 .name = "user_linkup_enabled",
1287 .type = TEAM_OPTION_TYPE_BOOL,
1288 .per_port = true,
1289 .getter = team_user_linkup_en_option_get,
1290 .setter = team_user_linkup_en_option_set,
1291 },
Jiri Pirkoa86fc6b2012-07-27 06:28:54 +00001292 {
1293 .name = "priority",
1294 .type = TEAM_OPTION_TYPE_S32,
1295 .per_port = true,
1296 .getter = team_priority_option_get,
1297 .setter = team_priority_option_set,
1298 },
Jiri Pirko8ff51052012-07-27 06:28:55 +00001299 {
1300 .name = "queue_id",
1301 .type = TEAM_OPTION_TYPE_U32,
1302 .per_port = true,
1303 .getter = team_queue_id_option_get,
1304 .setter = team_queue_id_option_set,
1305 },
Jiri Pirko3d249d42011-11-11 22:16:48 +00001306};
1307
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001308static struct lock_class_key team_netdev_xmit_lock_key;
1309static struct lock_class_key team_netdev_addr_lock_key;
1310
1311static void team_set_lockdep_class_one(struct net_device *dev,
1312 struct netdev_queue *txq,
1313 void *unused)
1314{
1315 lockdep_set_class(&txq->_xmit_lock, &team_netdev_xmit_lock_key);
1316}
1317
1318static void team_set_lockdep_class(struct net_device *dev)
1319{
1320 lockdep_set_class(&dev->addr_list_lock, &team_netdev_addr_lock_key);
1321 netdev_for_each_tx_queue(dev, team_set_lockdep_class_one, NULL);
1322}
1323
Jiri Pirko3d249d42011-11-11 22:16:48 +00001324static int team_init(struct net_device *dev)
1325{
1326 struct team *team = netdev_priv(dev);
1327 int i;
Jiri Pirko358b8382011-11-16 11:09:09 +00001328 int err;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001329
1330 team->dev = dev;
Jiri Pirko61dc3462011-11-16 11:09:08 +00001331 mutex_init(&team->lock);
Jiri Pirkod299cd52012-06-19 05:54:04 +00001332 team_set_no_mode(team);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001333
1334 team->pcpu_stats = alloc_percpu(struct team_pcpu_stats);
1335 if (!team->pcpu_stats)
1336 return -ENOMEM;
1337
1338 for (i = 0; i < TEAM_PORT_HASHENTRIES; i++)
Jiri Pirko19a0b582012-04-20 04:42:05 +00001339 INIT_HLIST_HEAD(&team->en_port_hlist[i]);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001340 INIT_LIST_HEAD(&team->port_list);
Jiri Pirko8ff51052012-07-27 06:28:55 +00001341 err = team_queue_override_init(team);
1342 if (err)
1343 goto err_team_queue_override_init;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001344
1345 team_adjust_ops(team);
1346
1347 INIT_LIST_HEAD(&team->option_list);
Jiri Pirko80f7c662012-04-10 05:15:42 +00001348 INIT_LIST_HEAD(&team->option_inst_list);
Jiri Pirko358b8382011-11-16 11:09:09 +00001349 err = team_options_register(team, team_options, ARRAY_SIZE(team_options));
1350 if (err)
1351 goto err_options_register;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001352 netif_carrier_off(dev);
1353
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001354 team_set_lockdep_class(dev);
1355
Jiri Pirko3d249d42011-11-11 22:16:48 +00001356 return 0;
Jiri Pirko358b8382011-11-16 11:09:09 +00001357
1358err_options_register:
Jiri Pirko8ff51052012-07-27 06:28:55 +00001359 team_queue_override_fini(team);
1360err_team_queue_override_init:
Jiri Pirko358b8382011-11-16 11:09:09 +00001361 free_percpu(team->pcpu_stats);
1362
1363 return err;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001364}
1365
1366static void team_uninit(struct net_device *dev)
1367{
1368 struct team *team = netdev_priv(dev);
1369 struct team_port *port;
1370 struct team_port *tmp;
1371
Jiri Pirko61dc3462011-11-16 11:09:08 +00001372 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001373 list_for_each_entry_safe(port, tmp, &team->port_list, list)
1374 team_port_del(team, port->dev);
1375
1376 __team_change_mode(team, NULL); /* cleanup */
1377 __team_options_unregister(team, team_options, ARRAY_SIZE(team_options));
Jiri Pirko8ff51052012-07-27 06:28:55 +00001378 team_queue_override_fini(team);
Jiri Pirko61dc3462011-11-16 11:09:08 +00001379 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001380}
1381
1382static void team_destructor(struct net_device *dev)
1383{
1384 struct team *team = netdev_priv(dev);
1385
1386 free_percpu(team->pcpu_stats);
1387 free_netdev(dev);
1388}
1389
1390static int team_open(struct net_device *dev)
1391{
1392 netif_carrier_on(dev);
1393 return 0;
1394}
1395
1396static int team_close(struct net_device *dev)
1397{
1398 netif_carrier_off(dev);
1399 return 0;
1400}
1401
1402/*
1403 * note: already called with rcu_read_lock
1404 */
1405static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)
1406{
1407 struct team *team = netdev_priv(dev);
Jiri Pirko8ff51052012-07-27 06:28:55 +00001408 bool tx_success;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001409 unsigned int len = skb->len;
1410
Jiri Pirko8ff51052012-07-27 06:28:55 +00001411 tx_success = team_queue_override_transmit(team, skb);
1412 if (!tx_success)
1413 tx_success = team->ops.transmit(team, skb);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001414 if (tx_success) {
1415 struct team_pcpu_stats *pcpu_stats;
1416
1417 pcpu_stats = this_cpu_ptr(team->pcpu_stats);
1418 u64_stats_update_begin(&pcpu_stats->syncp);
1419 pcpu_stats->tx_packets++;
1420 pcpu_stats->tx_bytes += len;
1421 u64_stats_update_end(&pcpu_stats->syncp);
1422 } else {
1423 this_cpu_inc(team->pcpu_stats->tx_dropped);
1424 }
1425
1426 return NETDEV_TX_OK;
1427}
1428
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001429static u16 team_select_queue(struct net_device *dev, struct sk_buff *skb)
1430{
1431 /*
1432 * This helper function exists to help dev_pick_tx get the correct
1433 * destination queue. Using a helper function skips a call to
1434 * skb_tx_hash and will put the skbs in the queue we expect on their
1435 * way down to the team driver.
1436 */
1437 u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
1438
1439 /*
1440 * Save the original txq to restore before passing to the driver
1441 */
1442 qdisc_skb_cb(skb)->slave_dev_queue_mapping = skb->queue_mapping;
1443
1444 if (unlikely(txq >= dev->real_num_tx_queues)) {
1445 do {
1446 txq -= dev->real_num_tx_queues;
1447 } while (txq >= dev->real_num_tx_queues);
1448 }
1449 return txq;
1450}
1451
Jiri Pirko3d249d42011-11-11 22:16:48 +00001452static void team_change_rx_flags(struct net_device *dev, int change)
1453{
1454 struct team *team = netdev_priv(dev);
1455 struct team_port *port;
1456 int inc;
1457
1458 rcu_read_lock();
1459 list_for_each_entry_rcu(port, &team->port_list, list) {
1460 if (change & IFF_PROMISC) {
1461 inc = dev->flags & IFF_PROMISC ? 1 : -1;
1462 dev_set_promiscuity(port->dev, inc);
1463 }
1464 if (change & IFF_ALLMULTI) {
1465 inc = dev->flags & IFF_ALLMULTI ? 1 : -1;
1466 dev_set_allmulti(port->dev, inc);
1467 }
1468 }
1469 rcu_read_unlock();
1470}
1471
1472static void team_set_rx_mode(struct net_device *dev)
1473{
1474 struct team *team = netdev_priv(dev);
1475 struct team_port *port;
1476
1477 rcu_read_lock();
1478 list_for_each_entry_rcu(port, &team->port_list, list) {
1479 dev_uc_sync(port->dev, dev);
1480 dev_mc_sync(port->dev, dev);
1481 }
1482 rcu_read_unlock();
1483}
1484
1485static int team_set_mac_address(struct net_device *dev, void *p)
1486{
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001487 struct sockaddr *addr = p;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001488 struct team *team = netdev_priv(dev);
1489 struct team_port *port;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001490
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001491 if (dev->type == ARPHRD_ETHER && !is_valid_ether_addr(addr->sa_data))
1492 return -EADDRNOTAVAIL;
1493 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1494 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001495 rcu_read_lock();
1496 list_for_each_entry_rcu(port, &team->port_list, list)
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001497 if (team->ops.port_change_dev_addr)
1498 team->ops.port_change_dev_addr(team, port);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001499 rcu_read_unlock();
1500 return 0;
1501}
1502
1503static int team_change_mtu(struct net_device *dev, int new_mtu)
1504{
1505 struct team *team = netdev_priv(dev);
1506 struct team_port *port;
1507 int err;
1508
1509 /*
1510 * Alhough this is reader, it's guarded by team lock. It's not possible
1511 * to traverse list in reverse under rcu_read_lock
1512 */
Jiri Pirko61dc3462011-11-16 11:09:08 +00001513 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001514 list_for_each_entry(port, &team->port_list, list) {
1515 err = dev_set_mtu(port->dev, new_mtu);
1516 if (err) {
1517 netdev_err(dev, "Device %s failed to change mtu",
1518 port->dev->name);
1519 goto unwind;
1520 }
1521 }
Jiri Pirko61dc3462011-11-16 11:09:08 +00001522 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001523
1524 dev->mtu = new_mtu;
1525
1526 return 0;
1527
1528unwind:
1529 list_for_each_entry_continue_reverse(port, &team->port_list, list)
1530 dev_set_mtu(port->dev, dev->mtu);
Jiri Pirko61dc3462011-11-16 11:09:08 +00001531 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001532
1533 return err;
1534}
1535
1536static struct rtnl_link_stats64 *
1537team_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
1538{
1539 struct team *team = netdev_priv(dev);
1540 struct team_pcpu_stats *p;
1541 u64 rx_packets, rx_bytes, rx_multicast, tx_packets, tx_bytes;
1542 u32 rx_dropped = 0, tx_dropped = 0;
1543 unsigned int start;
1544 int i;
1545
1546 for_each_possible_cpu(i) {
1547 p = per_cpu_ptr(team->pcpu_stats, i);
1548 do {
1549 start = u64_stats_fetch_begin_bh(&p->syncp);
1550 rx_packets = p->rx_packets;
1551 rx_bytes = p->rx_bytes;
1552 rx_multicast = p->rx_multicast;
1553 tx_packets = p->tx_packets;
1554 tx_bytes = p->tx_bytes;
1555 } while (u64_stats_fetch_retry_bh(&p->syncp, start));
1556
1557 stats->rx_packets += rx_packets;
1558 stats->rx_bytes += rx_bytes;
1559 stats->multicast += rx_multicast;
1560 stats->tx_packets += tx_packets;
1561 stats->tx_bytes += tx_bytes;
1562 /*
1563 * rx_dropped & tx_dropped are u32, updated
1564 * without syncp protection.
1565 */
1566 rx_dropped += p->rx_dropped;
1567 tx_dropped += p->tx_dropped;
1568 }
1569 stats->rx_dropped = rx_dropped;
1570 stats->tx_dropped = tx_dropped;
1571 return stats;
1572}
1573
Jiri Pirko8e586132011-12-08 19:52:37 -05001574static int team_vlan_rx_add_vid(struct net_device *dev, uint16_t vid)
Jiri Pirko3d249d42011-11-11 22:16:48 +00001575{
1576 struct team *team = netdev_priv(dev);
1577 struct team_port *port;
Jiri Pirko87002b02011-12-08 04:11:17 +00001578 int err;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001579
Jiri Pirko87002b02011-12-08 04:11:17 +00001580 /*
1581 * Alhough this is reader, it's guarded by team lock. It's not possible
1582 * to traverse list in reverse under rcu_read_lock
1583 */
1584 mutex_lock(&team->lock);
1585 list_for_each_entry(port, &team->port_list, list) {
1586 err = vlan_vid_add(port->dev, vid);
1587 if (err)
1588 goto unwind;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001589 }
Jiri Pirko87002b02011-12-08 04:11:17 +00001590 mutex_unlock(&team->lock);
Jiri Pirko8e586132011-12-08 19:52:37 -05001591
1592 return 0;
Jiri Pirko87002b02011-12-08 04:11:17 +00001593
1594unwind:
1595 list_for_each_entry_continue_reverse(port, &team->port_list, list)
1596 vlan_vid_del(port->dev, vid);
1597 mutex_unlock(&team->lock);
1598
1599 return err;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001600}
1601
Jiri Pirko8e586132011-12-08 19:52:37 -05001602static int team_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
Jiri Pirko3d249d42011-11-11 22:16:48 +00001603{
1604 struct team *team = netdev_priv(dev);
1605 struct team_port *port;
1606
1607 rcu_read_lock();
Jiri Pirko87002b02011-12-08 04:11:17 +00001608 list_for_each_entry_rcu(port, &team->port_list, list)
1609 vlan_vid_del(port->dev, vid);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001610 rcu_read_unlock();
Jiri Pirko8e586132011-12-08 19:52:37 -05001611
1612 return 0;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001613}
1614
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001615#ifdef CONFIG_NET_POLL_CONTROLLER
1616static void team_poll_controller(struct net_device *dev)
1617{
1618}
1619
1620static void __team_netpoll_cleanup(struct team *team)
1621{
1622 struct team_port *port;
1623
1624 list_for_each_entry(port, &team->port_list, list)
1625 team_port_disable_netpoll(port);
1626}
1627
1628static void team_netpoll_cleanup(struct net_device *dev)
1629{
1630 struct team *team = netdev_priv(dev);
1631
1632 mutex_lock(&team->lock);
1633 __team_netpoll_cleanup(team);
1634 mutex_unlock(&team->lock);
1635}
1636
1637static int team_netpoll_setup(struct net_device *dev,
Amerigo Wang47be03a22012-08-10 01:24:37 +00001638 struct netpoll_info *npifo, gfp_t gfp)
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001639{
1640 struct team *team = netdev_priv(dev);
1641 struct team_port *port;
Jiri Pirko3324d022012-07-24 01:20:48 +00001642 int err = 0;
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001643
1644 mutex_lock(&team->lock);
1645 list_for_each_entry(port, &team->port_list, list) {
Amerigo Wang47be03a22012-08-10 01:24:37 +00001646 err = team_port_enable_netpoll(team, port, gfp);
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001647 if (err) {
1648 __team_netpoll_cleanup(team);
1649 break;
1650 }
1651 }
1652 mutex_unlock(&team->lock);
1653 return err;
1654}
1655#endif
1656
Jiri Pirko3d249d42011-11-11 22:16:48 +00001657static int team_add_slave(struct net_device *dev, struct net_device *port_dev)
1658{
1659 struct team *team = netdev_priv(dev);
1660 int err;
1661
Jiri Pirko61dc3462011-11-16 11:09:08 +00001662 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001663 err = team_port_add(team, port_dev);
Jiri Pirko61dc3462011-11-16 11:09:08 +00001664 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001665 return err;
1666}
1667
1668static int team_del_slave(struct net_device *dev, struct net_device *port_dev)
1669{
1670 struct team *team = netdev_priv(dev);
1671 int err;
1672
Jiri Pirko61dc3462011-11-16 11:09:08 +00001673 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001674 err = team_port_del(team, port_dev);
Jiri Pirko61dc3462011-11-16 11:09:08 +00001675 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001676 return err;
1677}
1678
Jiri Pirko234a8fd2011-11-17 04:16:04 +00001679static netdev_features_t team_fix_features(struct net_device *dev,
1680 netdev_features_t features)
1681{
1682 struct team_port *port;
1683 struct team *team = netdev_priv(dev);
1684 netdev_features_t mask;
1685
1686 mask = features;
1687 features &= ~NETIF_F_ONE_FOR_ALL;
1688 features |= NETIF_F_ALL_FOR_ALL;
1689
1690 rcu_read_lock();
1691 list_for_each_entry_rcu(port, &team->port_list, list) {
1692 features = netdev_increment_features(features,
1693 port->dev->features,
1694 mask);
1695 }
1696 rcu_read_unlock();
1697 return features;
1698}
1699
Jiri Pirko3d249d42011-11-11 22:16:48 +00001700static const struct net_device_ops team_netdev_ops = {
1701 .ndo_init = team_init,
1702 .ndo_uninit = team_uninit,
1703 .ndo_open = team_open,
1704 .ndo_stop = team_close,
1705 .ndo_start_xmit = team_xmit,
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001706 .ndo_select_queue = team_select_queue,
Jiri Pirko3d249d42011-11-11 22:16:48 +00001707 .ndo_change_rx_flags = team_change_rx_flags,
1708 .ndo_set_rx_mode = team_set_rx_mode,
1709 .ndo_set_mac_address = team_set_mac_address,
1710 .ndo_change_mtu = team_change_mtu,
1711 .ndo_get_stats64 = team_get_stats64,
1712 .ndo_vlan_rx_add_vid = team_vlan_rx_add_vid,
1713 .ndo_vlan_rx_kill_vid = team_vlan_rx_kill_vid,
Jiri Pirkobd2d0832012-07-17 05:22:36 +00001714#ifdef CONFIG_NET_POLL_CONTROLLER
1715 .ndo_poll_controller = team_poll_controller,
1716 .ndo_netpoll_setup = team_netpoll_setup,
1717 .ndo_netpoll_cleanup = team_netpoll_cleanup,
1718#endif
Jiri Pirko3d249d42011-11-11 22:16:48 +00001719 .ndo_add_slave = team_add_slave,
1720 .ndo_del_slave = team_del_slave,
Jiri Pirko234a8fd2011-11-17 04:16:04 +00001721 .ndo_fix_features = team_fix_features,
Jiri Pirko3d249d42011-11-11 22:16:48 +00001722};
1723
1724
1725/***********************
1726 * rt netlink interface
1727 ***********************/
1728
Jiri Pirko1d76efe2012-08-17 04:00:48 +00001729static void team_setup_by_port(struct net_device *dev,
1730 struct net_device *port_dev)
1731{
1732 dev->header_ops = port_dev->header_ops;
1733 dev->type = port_dev->type;
1734 dev->hard_header_len = port_dev->hard_header_len;
1735 dev->addr_len = port_dev->addr_len;
1736 dev->mtu = port_dev->mtu;
1737 memcpy(dev->broadcast, port_dev->broadcast, port_dev->addr_len);
1738 memcpy(dev->dev_addr, port_dev->dev_addr, port_dev->addr_len);
1739 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
1740}
1741
1742static int team_dev_type_check_change(struct net_device *dev,
1743 struct net_device *port_dev)
1744{
1745 struct team *team = netdev_priv(dev);
1746 char *portname = port_dev->name;
1747 int err;
1748
1749 if (dev->type == port_dev->type)
1750 return 0;
1751 if (!list_empty(&team->port_list)) {
1752 netdev_err(dev, "Device %s is of different type\n", portname);
1753 return -EBUSY;
1754 }
1755 err = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, dev);
1756 err = notifier_to_errno(err);
1757 if (err) {
1758 netdev_err(dev, "Refused to change device type\n");
1759 return err;
1760 }
1761 dev_uc_flush(dev);
1762 dev_mc_flush(dev);
1763 team_setup_by_port(dev, port_dev);
1764 call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE, dev);
1765 return 0;
1766}
1767
Jiri Pirko3d249d42011-11-11 22:16:48 +00001768static void team_setup(struct net_device *dev)
1769{
1770 ether_setup(dev);
1771
1772 dev->netdev_ops = &team_netdev_ops;
1773 dev->destructor = team_destructor;
1774 dev->tx_queue_len = 0;
1775 dev->flags |= IFF_MULTICAST;
1776 dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
1777
1778 /*
1779 * Indicate we support unicast address filtering. That way core won't
1780 * bring us to promisc mode in case a unicast addr is added.
1781 * Let this up to underlay drivers.
1782 */
Jiri Pirko5a1d1c82012-06-29 05:10:07 +00001783 dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE;
Jiri Pirko3d249d42011-11-11 22:16:48 +00001784
1785 dev->features |= NETIF_F_LLTX;
1786 dev->features |= NETIF_F_GRO;
1787 dev->hw_features = NETIF_F_HW_VLAN_TX |
1788 NETIF_F_HW_VLAN_RX |
1789 NETIF_F_HW_VLAN_FILTER;
1790
1791 dev->features |= dev->hw_features;
1792}
1793
1794static int team_newlink(struct net *src_net, struct net_device *dev,
1795 struct nlattr *tb[], struct nlattr *data[])
1796{
1797 int err;
1798
1799 if (tb[IFLA_ADDRESS] == NULL)
Danny Kukawka7ce5d222012-02-15 06:45:40 +00001800 eth_hw_addr_random(dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001801
1802 err = register_netdevice(dev);
1803 if (err)
1804 return err;
1805
1806 return 0;
1807}
1808
1809static int team_validate(struct nlattr *tb[], struct nlattr *data[])
1810{
1811 if (tb[IFLA_ADDRESS]) {
1812 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
1813 return -EINVAL;
1814 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
1815 return -EADDRNOTAVAIL;
1816 }
1817 return 0;
1818}
1819
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001820static unsigned int team_get_num_tx_queues(void)
1821{
1822 return TEAM_DEFAULT_NUM_TX_QUEUES;
1823}
1824
1825static unsigned int team_get_num_rx_queues(void)
1826{
1827 return TEAM_DEFAULT_NUM_RX_QUEUES;
1828}
1829
Jiri Pirko3d249d42011-11-11 22:16:48 +00001830static struct rtnl_link_ops team_link_ops __read_mostly = {
Jiri Pirko6c85f2b2012-07-20 02:28:51 +00001831 .kind = DRV_NAME,
1832 .priv_size = sizeof(struct team),
1833 .setup = team_setup,
1834 .newlink = team_newlink,
1835 .validate = team_validate,
1836 .get_num_tx_queues = team_get_num_tx_queues,
1837 .get_num_rx_queues = team_get_num_rx_queues,
Jiri Pirko3d249d42011-11-11 22:16:48 +00001838};
1839
1840
1841/***********************************
1842 * Generic netlink custom interface
1843 ***********************************/
1844
1845static struct genl_family team_nl_family = {
1846 .id = GENL_ID_GENERATE,
1847 .name = TEAM_GENL_NAME,
1848 .version = TEAM_GENL_VERSION,
1849 .maxattr = TEAM_ATTR_MAX,
1850 .netnsok = true,
1851};
1852
1853static const struct nla_policy team_nl_policy[TEAM_ATTR_MAX + 1] = {
1854 [TEAM_ATTR_UNSPEC] = { .type = NLA_UNSPEC, },
1855 [TEAM_ATTR_TEAM_IFINDEX] = { .type = NLA_U32 },
1856 [TEAM_ATTR_LIST_OPTION] = { .type = NLA_NESTED },
1857 [TEAM_ATTR_LIST_PORT] = { .type = NLA_NESTED },
1858};
1859
1860static const struct nla_policy
1861team_nl_option_policy[TEAM_ATTR_OPTION_MAX + 1] = {
1862 [TEAM_ATTR_OPTION_UNSPEC] = { .type = NLA_UNSPEC, },
1863 [TEAM_ATTR_OPTION_NAME] = {
1864 .type = NLA_STRING,
1865 .len = TEAM_STRING_MAX_LEN,
1866 },
1867 [TEAM_ATTR_OPTION_CHANGED] = { .type = NLA_FLAG },
1868 [TEAM_ATTR_OPTION_TYPE] = { .type = NLA_U8 },
Jiri Pirko26155982012-04-04 12:16:26 +00001869 [TEAM_ATTR_OPTION_DATA] = { .type = NLA_BINARY },
Jiri Pirko3d249d42011-11-11 22:16:48 +00001870};
1871
1872static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
1873{
1874 struct sk_buff *msg;
1875 void *hdr;
1876 int err;
1877
Thomas Graf58050fc2012-06-28 03:57:45 +00001878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001879 if (!msg)
1880 return -ENOMEM;
1881
1882 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
1883 &team_nl_family, 0, TEAM_CMD_NOOP);
1884 if (IS_ERR(hdr)) {
1885 err = PTR_ERR(hdr);
1886 goto err_msg_put;
1887 }
1888
1889 genlmsg_end(msg, hdr);
1890
1891 return genlmsg_unicast(genl_info_net(info), msg, info->snd_pid);
1892
1893err_msg_put:
1894 nlmsg_free(msg);
1895
1896 return err;
1897}
1898
1899/*
1900 * Netlink cmd functions should be locked by following two functions.
Jiri Pirko8c0713a2011-11-16 11:55:54 +00001901 * Since dev gets held here, that ensures dev won't disappear in between.
Jiri Pirko3d249d42011-11-11 22:16:48 +00001902 */
1903static struct team *team_nl_team_get(struct genl_info *info)
1904{
1905 struct net *net = genl_info_net(info);
1906 int ifindex;
1907 struct net_device *dev;
1908 struct team *team;
1909
1910 if (!info->attrs[TEAM_ATTR_TEAM_IFINDEX])
1911 return NULL;
1912
1913 ifindex = nla_get_u32(info->attrs[TEAM_ATTR_TEAM_IFINDEX]);
Jiri Pirko8c0713a2011-11-16 11:55:54 +00001914 dev = dev_get_by_index(net, ifindex);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001915 if (!dev || dev->netdev_ops != &team_netdev_ops) {
Jiri Pirko8c0713a2011-11-16 11:55:54 +00001916 if (dev)
1917 dev_put(dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001918 return NULL;
1919 }
1920
1921 team = netdev_priv(dev);
Jiri Pirko61dc3462011-11-16 11:09:08 +00001922 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001923 return team;
1924}
1925
1926static void team_nl_team_put(struct team *team)
1927{
Jiri Pirko61dc3462011-11-16 11:09:08 +00001928 mutex_unlock(&team->lock);
Jiri Pirko8c0713a2011-11-16 11:55:54 +00001929 dev_put(team->dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001930}
1931
1932static int team_nl_send_generic(struct genl_info *info, struct team *team,
1933 int (*fill_func)(struct sk_buff *skb,
1934 struct genl_info *info,
1935 int flags, struct team *team))
1936{
1937 struct sk_buff *skb;
1938 int err;
1939
Thomas Graf58050fc2012-06-28 03:57:45 +00001940 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Jiri Pirko3d249d42011-11-11 22:16:48 +00001941 if (!skb)
1942 return -ENOMEM;
1943
1944 err = fill_func(skb, info, NLM_F_ACK, team);
1945 if (err < 0)
1946 goto err_fill;
1947
1948 err = genlmsg_unicast(genl_info_net(info), skb, info->snd_pid);
1949 return err;
1950
1951err_fill:
1952 nlmsg_free(skb);
1953 return err;
1954}
1955
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001956typedef int team_nl_send_func_t(struct sk_buff *skb,
1957 struct team *team, u32 pid);
1958
1959static int team_nl_send_unicast(struct sk_buff *skb, struct team *team, u32 pid)
1960{
1961 return genlmsg_unicast(dev_net(team->dev), skb, pid);
1962}
1963
Jiri Pirko01048d92012-06-19 05:54:14 +00001964static int team_nl_fill_one_option_get(struct sk_buff *skb, struct team *team,
1965 struct team_option_inst *opt_inst)
1966{
1967 struct nlattr *option_item;
1968 struct team_option *option = opt_inst->option;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001969 struct team_option_inst_info *opt_inst_info = &opt_inst->info;
Jiri Pirko01048d92012-06-19 05:54:14 +00001970 struct team_gsetter_ctx ctx;
1971 int err;
1972
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001973 ctx.info = opt_inst_info;
1974 err = team_option_get(team, opt_inst, &ctx);
1975 if (err)
1976 return err;
1977
Jiri Pirko01048d92012-06-19 05:54:14 +00001978 option_item = nla_nest_start(skb, TEAM_ATTR_ITEM_OPTION);
1979 if (!option_item)
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001980 return -EMSGSIZE;
Jiri Pirko01048d92012-06-19 05:54:14 +00001981
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001982 if (nla_put_string(skb, TEAM_ATTR_OPTION_NAME, option->name))
1983 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00001984 if (opt_inst_info->port &&
1985 nla_put_u32(skb, TEAM_ATTR_OPTION_PORT_IFINDEX,
1986 opt_inst_info->port->dev->ifindex))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001987 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00001988 if (opt_inst->option->array_size &&
1989 nla_put_u32(skb, TEAM_ATTR_OPTION_ARRAY_INDEX,
1990 opt_inst_info->array_index))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001991 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00001992
1993 switch (option->type) {
1994 case TEAM_OPTION_TYPE_U32:
1995 if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_U32))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001996 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00001997 if (nla_put_u32(skb, TEAM_ATTR_OPTION_DATA, ctx.data.u32_val))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00001998 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00001999 break;
2000 case TEAM_OPTION_TYPE_STRING:
2001 if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_STRING))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002002 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002003 if (nla_put_string(skb, TEAM_ATTR_OPTION_DATA,
2004 ctx.data.str_val))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002005 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002006 break;
2007 case TEAM_OPTION_TYPE_BINARY:
2008 if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_BINARY))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002009 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002010 if (nla_put(skb, TEAM_ATTR_OPTION_DATA, ctx.data.bin_val.len,
2011 ctx.data.bin_val.ptr))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002012 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002013 break;
2014 case TEAM_OPTION_TYPE_BOOL:
2015 if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_FLAG))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002016 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002017 if (ctx.data.bool_val &&
2018 nla_put_flag(skb, TEAM_ATTR_OPTION_DATA))
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002019 goto nest_cancel;
Jiri Pirko01048d92012-06-19 05:54:14 +00002020 break;
Jiri Pirko69821632012-07-27 06:28:53 +00002021 case TEAM_OPTION_TYPE_S32:
2022 if (nla_put_u8(skb, TEAM_ATTR_OPTION_TYPE, NLA_S32))
2023 goto nest_cancel;
2024 if (nla_put_s32(skb, TEAM_ATTR_OPTION_DATA, ctx.data.s32_val))
2025 goto nest_cancel;
2026 break;
Jiri Pirko01048d92012-06-19 05:54:14 +00002027 default:
2028 BUG();
2029 }
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002030 if (opt_inst->removed && nla_put_flag(skb, TEAM_ATTR_OPTION_REMOVED))
2031 goto nest_cancel;
2032 if (opt_inst->changed) {
2033 if (nla_put_flag(skb, TEAM_ATTR_OPTION_CHANGED))
2034 goto nest_cancel;
2035 opt_inst->changed = false;
2036 }
Jiri Pirko01048d92012-06-19 05:54:14 +00002037 nla_nest_end(skb, option_item);
2038 return 0;
2039
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002040nest_cancel:
2041 nla_nest_cancel(skb, option_item);
2042 return -EMSGSIZE;
Jiri Pirko01048d92012-06-19 05:54:14 +00002043}
2044
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002045static int __send_and_alloc_skb(struct sk_buff **pskb,
2046 struct team *team, u32 pid,
2047 team_nl_send_func_t *send_func)
2048{
2049 int err;
2050
2051 if (*pskb) {
2052 err = send_func(*pskb, team, pid);
2053 if (err)
2054 return err;
2055 }
Thomas Graf58050fc2012-06-28 03:57:45 +00002056 *pskb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002057 if (!*pskb)
2058 return -ENOMEM;
2059 return 0;
2060}
2061
2062static int team_nl_send_options_get(struct team *team, u32 pid, u32 seq,
2063 int flags, team_nl_send_func_t *send_func,
Jiri Pirko01048d92012-06-19 05:54:14 +00002064 struct list_head *sel_opt_inst_list)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002065{
2066 struct nlattr *option_list;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002067 struct nlmsghdr *nlh;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002068 void *hdr;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002069 struct team_option_inst *opt_inst;
2070 int err;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002071 struct sk_buff *skb = NULL;
2072 bool incomplete;
2073 int i;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002074
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002075 opt_inst = list_first_entry(sel_opt_inst_list,
2076 struct team_option_inst, tmp_list);
2077
2078start_again:
2079 err = __send_and_alloc_skb(&skb, team, pid, send_func);
2080 if (err)
2081 return err;
2082
2083 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags | NLM_F_MULTI,
Jiri Pirko3d249d42011-11-11 22:16:48 +00002084 TEAM_CMD_OPTIONS_GET);
2085 if (IS_ERR(hdr))
2086 return PTR_ERR(hdr);
2087
David S. Miller86ebb022012-04-01 20:25:18 -04002088 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
2089 goto nla_put_failure;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002090 option_list = nla_nest_start(skb, TEAM_ATTR_LIST_OPTION);
2091 if (!option_list)
Jiri Pirko75db9862012-06-19 05:54:12 +00002092 goto nla_put_failure;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002093
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002094 i = 0;
2095 incomplete = false;
2096 list_for_each_entry_from(opt_inst, sel_opt_inst_list, tmp_list) {
Jiri Pirko01048d92012-06-19 05:54:14 +00002097 err = team_nl_fill_one_option_get(skb, team, opt_inst);
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002098 if (err) {
2099 if (err == -EMSGSIZE) {
2100 if (!i)
2101 goto errout;
2102 incomplete = true;
2103 break;
2104 }
Jiri Pirko01048d92012-06-19 05:54:14 +00002105 goto errout;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002106 }
2107 i++;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002108 }
2109
2110 nla_nest_end(skb, option_list);
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002111 genlmsg_end(skb, hdr);
2112 if (incomplete)
2113 goto start_again;
2114
2115send_done:
2116 nlh = nlmsg_put(skb, pid, seq, NLMSG_DONE, 0, flags | NLM_F_MULTI);
2117 if (!nlh) {
2118 err = __send_and_alloc_skb(&skb, team, pid, send_func);
2119 if (err)
2120 goto errout;
2121 goto send_done;
2122 }
2123
2124 return send_func(skb, team, pid);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002125
2126nla_put_failure:
Jiri Pirko80f7c662012-04-10 05:15:42 +00002127 err = -EMSGSIZE;
2128errout:
Jiri Pirko3d249d42011-11-11 22:16:48 +00002129 genlmsg_cancel(skb, hdr);
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002130 nlmsg_free(skb);
Jiri Pirko80f7c662012-04-10 05:15:42 +00002131 return err;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002132}
2133
Jiri Pirko3d249d42011-11-11 22:16:48 +00002134static int team_nl_cmd_options_get(struct sk_buff *skb, struct genl_info *info)
2135{
2136 struct team *team;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002137 struct team_option_inst *opt_inst;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002138 int err;
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002139 LIST_HEAD(sel_opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002140
2141 team = team_nl_team_get(info);
2142 if (!team)
2143 return -EINVAL;
2144
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002145 list_for_each_entry(opt_inst, &team->option_inst_list, list)
2146 list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
2147 err = team_nl_send_options_get(team, info->snd_pid, info->snd_seq,
2148 NLM_F_ACK, team_nl_send_unicast,
2149 &sel_opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002150
2151 team_nl_team_put(team);
2152
2153 return err;
2154}
2155
Jiri Pirko2fcdb2c2012-06-19 05:54:20 +00002156static int team_nl_send_event_options_get(struct team *team,
2157 struct list_head *sel_opt_inst_list);
2158
Jiri Pirko3d249d42011-11-11 22:16:48 +00002159static int team_nl_cmd_options_set(struct sk_buff *skb, struct genl_info *info)
2160{
2161 struct team *team;
2162 int err = 0;
2163 int i;
2164 struct nlattr *nl_option;
Jiri Pirko2fcdb2c2012-06-19 05:54:20 +00002165 LIST_HEAD(opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002166
2167 team = team_nl_team_get(info);
2168 if (!team)
2169 return -EINVAL;
2170
2171 err = -EINVAL;
2172 if (!info->attrs[TEAM_ATTR_LIST_OPTION]) {
2173 err = -EINVAL;
2174 goto team_put;
2175 }
2176
2177 nla_for_each_nested(nl_option, info->attrs[TEAM_ATTR_LIST_OPTION], i) {
Jiri Pirko80f7c662012-04-10 05:15:42 +00002178 struct nlattr *opt_attrs[TEAM_ATTR_OPTION_MAX + 1];
Jiri Pirkob1303322012-06-19 05:54:08 +00002179 struct nlattr *attr;
Jiri Pirko14f066b2012-04-10 05:15:43 +00002180 struct nlattr *attr_data;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002181 enum team_option_type opt_type;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002182 int opt_port_ifindex = 0; /* != 0 for per-port options */
Jiri Pirkob1303322012-06-19 05:54:08 +00002183 u32 opt_array_index = 0;
2184 bool opt_is_array = false;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002185 struct team_option_inst *opt_inst;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002186 char *opt_name;
2187 bool opt_found = false;
2188
2189 if (nla_type(nl_option) != TEAM_ATTR_ITEM_OPTION) {
2190 err = -EINVAL;
2191 goto team_put;
2192 }
Jiri Pirko80f7c662012-04-10 05:15:42 +00002193 err = nla_parse_nested(opt_attrs, TEAM_ATTR_OPTION_MAX,
Jiri Pirko3d249d42011-11-11 22:16:48 +00002194 nl_option, team_nl_option_policy);
2195 if (err)
2196 goto team_put;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002197 if (!opt_attrs[TEAM_ATTR_OPTION_NAME] ||
Jiri Pirko14f066b2012-04-10 05:15:43 +00002198 !opt_attrs[TEAM_ATTR_OPTION_TYPE]) {
Jiri Pirko3d249d42011-11-11 22:16:48 +00002199 err = -EINVAL;
2200 goto team_put;
2201 }
Jiri Pirko80f7c662012-04-10 05:15:42 +00002202 switch (nla_get_u8(opt_attrs[TEAM_ATTR_OPTION_TYPE])) {
Jiri Pirko3d249d42011-11-11 22:16:48 +00002203 case NLA_U32:
2204 opt_type = TEAM_OPTION_TYPE_U32;
2205 break;
2206 case NLA_STRING:
2207 opt_type = TEAM_OPTION_TYPE_STRING;
2208 break;
Jiri Pirko26155982012-04-04 12:16:26 +00002209 case NLA_BINARY:
2210 opt_type = TEAM_OPTION_TYPE_BINARY;
2211 break;
Jiri Pirko14f066b2012-04-10 05:15:43 +00002212 case NLA_FLAG:
2213 opt_type = TEAM_OPTION_TYPE_BOOL;
2214 break;
Jiri Pirko69821632012-07-27 06:28:53 +00002215 case NLA_S32:
2216 opt_type = TEAM_OPTION_TYPE_S32;
2217 break;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002218 default:
2219 goto team_put;
2220 }
2221
Jiri Pirko14f066b2012-04-10 05:15:43 +00002222 attr_data = opt_attrs[TEAM_ATTR_OPTION_DATA];
2223 if (opt_type != TEAM_OPTION_TYPE_BOOL && !attr_data) {
2224 err = -EINVAL;
2225 goto team_put;
2226 }
2227
Jiri Pirko80f7c662012-04-10 05:15:42 +00002228 opt_name = nla_data(opt_attrs[TEAM_ATTR_OPTION_NAME]);
Jiri Pirkob1303322012-06-19 05:54:08 +00002229 attr = opt_attrs[TEAM_ATTR_OPTION_PORT_IFINDEX];
2230 if (attr)
2231 opt_port_ifindex = nla_get_u32(attr);
2232
2233 attr = opt_attrs[TEAM_ATTR_OPTION_ARRAY_INDEX];
2234 if (attr) {
2235 opt_is_array = true;
2236 opt_array_index = nla_get_u32(attr);
2237 }
Jiri Pirko3d249d42011-11-11 22:16:48 +00002238
Jiri Pirko80f7c662012-04-10 05:15:42 +00002239 list_for_each_entry(opt_inst, &team->option_inst_list, list) {
2240 struct team_option *option = opt_inst->option;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002241 struct team_gsetter_ctx ctx;
Jiri Pirko85d59a82012-06-19 05:54:10 +00002242 struct team_option_inst_info *opt_inst_info;
Jiri Pirko80f7c662012-04-10 05:15:42 +00002243 int tmp_ifindex;
2244
Jiri Pirko85d59a82012-06-19 05:54:10 +00002245 opt_inst_info = &opt_inst->info;
2246 tmp_ifindex = opt_inst_info->port ?
2247 opt_inst_info->port->dev->ifindex : 0;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002248 if (option->type != opt_type ||
Jiri Pirko80f7c662012-04-10 05:15:42 +00002249 strcmp(option->name, opt_name) ||
Jiri Pirkob1303322012-06-19 05:54:08 +00002250 tmp_ifindex != opt_port_ifindex ||
2251 (option->array_size && !opt_is_array) ||
Jiri Pirko85d59a82012-06-19 05:54:10 +00002252 opt_inst_info->array_index != opt_array_index)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002253 continue;
2254 opt_found = true;
Jiri Pirko85d59a82012-06-19 05:54:10 +00002255 ctx.info = opt_inst_info;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002256 switch (opt_type) {
2257 case TEAM_OPTION_TYPE_U32:
Jiri Pirko14f066b2012-04-10 05:15:43 +00002258 ctx.data.u32_val = nla_get_u32(attr_data);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002259 break;
2260 case TEAM_OPTION_TYPE_STRING:
Jiri Pirko14f066b2012-04-10 05:15:43 +00002261 if (nla_len(attr_data) > TEAM_STRING_MAX_LEN) {
Jiri Pirko26155982012-04-04 12:16:26 +00002262 err = -EINVAL;
2263 goto team_put;
2264 }
Jiri Pirko14f066b2012-04-10 05:15:43 +00002265 ctx.data.str_val = nla_data(attr_data);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002266 break;
Jiri Pirko26155982012-04-04 12:16:26 +00002267 case TEAM_OPTION_TYPE_BINARY:
Jiri Pirko14f066b2012-04-10 05:15:43 +00002268 ctx.data.bin_val.len = nla_len(attr_data);
2269 ctx.data.bin_val.ptr = nla_data(attr_data);
2270 break;
2271 case TEAM_OPTION_TYPE_BOOL:
2272 ctx.data.bool_val = attr_data ? true : false;
Jiri Pirko26155982012-04-04 12:16:26 +00002273 break;
Jiri Pirko69821632012-07-27 06:28:53 +00002274 case TEAM_OPTION_TYPE_S32:
2275 ctx.data.s32_val = nla_get_s32(attr_data);
2276 break;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002277 default:
2278 BUG();
2279 }
Jiri Pirko80f7c662012-04-10 05:15:42 +00002280 err = team_option_set(team, opt_inst, &ctx);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002281 if (err)
2282 goto team_put;
Jiri Pirko2fcdb2c2012-06-19 05:54:20 +00002283 opt_inst->changed = true;
2284 list_add(&opt_inst->tmp_list, &opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002285 }
2286 if (!opt_found) {
2287 err = -ENOENT;
2288 goto team_put;
2289 }
2290 }
2291
Jiri Pirko2fcdb2c2012-06-19 05:54:20 +00002292 err = team_nl_send_event_options_get(team, &opt_inst_list);
2293
Jiri Pirko3d249d42011-11-11 22:16:48 +00002294team_put:
2295 team_nl_team_put(team);
2296
2297 return err;
2298}
2299
Jiri Pirkob82b9182012-01-24 05:16:00 +00002300static int team_nl_fill_port_list_get(struct sk_buff *skb,
2301 u32 pid, u32 seq, int flags,
2302 struct team *team,
2303 bool fillall)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002304{
2305 struct nlattr *port_list;
2306 void *hdr;
2307 struct team_port *port;
2308
2309 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
2310 TEAM_CMD_PORT_LIST_GET);
2311 if (IS_ERR(hdr))
2312 return PTR_ERR(hdr);
2313
David S. Miller86ebb022012-04-01 20:25:18 -04002314 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
2315 goto nla_put_failure;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002316 port_list = nla_nest_start(skb, TEAM_ATTR_LIST_PORT);
2317 if (!port_list)
Jiri Pirko3221c642012-06-19 05:54:13 +00002318 goto nla_put_failure;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002319
2320 list_for_each_entry(port, &team->port_list, list) {
2321 struct nlattr *port_item;
2322
Jiri Pirkob82b9182012-01-24 05:16:00 +00002323 /* Include only changed ports if fill all mode is not on */
2324 if (!fillall && !port->changed)
2325 continue;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002326 port_item = nla_nest_start(skb, TEAM_ATTR_ITEM_PORT);
2327 if (!port_item)
2328 goto nla_put_failure;
David S. Miller86ebb022012-04-01 20:25:18 -04002329 if (nla_put_u32(skb, TEAM_ATTR_PORT_IFINDEX, port->dev->ifindex))
2330 goto nla_put_failure;
Jiri Pirkob82b9182012-01-24 05:16:00 +00002331 if (port->changed) {
David S. Miller86ebb022012-04-01 20:25:18 -04002332 if (nla_put_flag(skb, TEAM_ATTR_PORT_CHANGED))
2333 goto nla_put_failure;
Jiri Pirkob82b9182012-01-24 05:16:00 +00002334 port->changed = false;
2335 }
David S. Miller86ebb022012-04-01 20:25:18 -04002336 if ((port->removed &&
2337 nla_put_flag(skb, TEAM_ATTR_PORT_REMOVED)) ||
Jiri Pirko71472ec2012-04-10 05:15:44 +00002338 (port->state.linkup &&
David S. Miller86ebb022012-04-01 20:25:18 -04002339 nla_put_flag(skb, TEAM_ATTR_PORT_LINKUP)) ||
Jiri Pirko71472ec2012-04-10 05:15:44 +00002340 nla_put_u32(skb, TEAM_ATTR_PORT_SPEED, port->state.speed) ||
2341 nla_put_u8(skb, TEAM_ATTR_PORT_DUPLEX, port->state.duplex))
David S. Miller86ebb022012-04-01 20:25:18 -04002342 goto nla_put_failure;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002343 nla_nest_end(skb, port_item);
2344 }
2345
2346 nla_nest_end(skb, port_list);
2347 return genlmsg_end(skb, hdr);
2348
2349nla_put_failure:
2350 genlmsg_cancel(skb, hdr);
2351 return -EMSGSIZE;
2352}
2353
Jiri Pirkob82b9182012-01-24 05:16:00 +00002354static int team_nl_fill_port_list_get_all(struct sk_buff *skb,
2355 struct genl_info *info, int flags,
2356 struct team *team)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002357{
Jiri Pirkob82b9182012-01-24 05:16:00 +00002358 return team_nl_fill_port_list_get(skb, info->snd_pid,
2359 info->snd_seq, NLM_F_ACK,
2360 team, true);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002361}
2362
2363static int team_nl_cmd_port_list_get(struct sk_buff *skb,
2364 struct genl_info *info)
2365{
2366 struct team *team;
2367 int err;
2368
2369 team = team_nl_team_get(info);
2370 if (!team)
2371 return -EINVAL;
2372
Jiri Pirkob82b9182012-01-24 05:16:00 +00002373 err = team_nl_send_generic(info, team, team_nl_fill_port_list_get_all);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002374
2375 team_nl_team_put(team);
2376
2377 return err;
2378}
2379
2380static struct genl_ops team_nl_ops[] = {
2381 {
2382 .cmd = TEAM_CMD_NOOP,
2383 .doit = team_nl_cmd_noop,
2384 .policy = team_nl_policy,
2385 },
2386 {
2387 .cmd = TEAM_CMD_OPTIONS_SET,
2388 .doit = team_nl_cmd_options_set,
2389 .policy = team_nl_policy,
2390 .flags = GENL_ADMIN_PERM,
2391 },
2392 {
2393 .cmd = TEAM_CMD_OPTIONS_GET,
2394 .doit = team_nl_cmd_options_get,
2395 .policy = team_nl_policy,
2396 .flags = GENL_ADMIN_PERM,
2397 },
2398 {
2399 .cmd = TEAM_CMD_PORT_LIST_GET,
2400 .doit = team_nl_cmd_port_list_get,
2401 .policy = team_nl_policy,
2402 .flags = GENL_ADMIN_PERM,
2403 },
2404};
2405
2406static struct genl_multicast_group team_change_event_mcgrp = {
2407 .name = TEAM_GENL_CHANGE_EVENT_MC_GRP_NAME,
2408};
2409
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002410static int team_nl_send_multicast(struct sk_buff *skb,
2411 struct team *team, u32 pid)
2412{
2413 return genlmsg_multicast_netns(dev_net(team->dev), skb, 0,
2414 team_change_event_mcgrp.id, GFP_KERNEL);
2415}
2416
Jiri Pirko01048d92012-06-19 05:54:14 +00002417static int team_nl_send_event_options_get(struct team *team,
2418 struct list_head *sel_opt_inst_list)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002419{
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002420 return team_nl_send_options_get(team, 0, 0, 0, team_nl_send_multicast,
2421 sel_opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002422}
2423
Jiri Pirkob82b9182012-01-24 05:16:00 +00002424static int team_nl_send_event_port_list_get(struct team *team)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002425{
2426 struct sk_buff *skb;
2427 int err;
Jiri Pirkob82b9182012-01-24 05:16:00 +00002428 struct net *net = dev_net(team->dev);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002429
Thomas Graf58050fc2012-06-28 03:57:45 +00002430 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002431 if (!skb)
2432 return -ENOMEM;
2433
Jiri Pirkob82b9182012-01-24 05:16:00 +00002434 err = team_nl_fill_port_list_get(skb, 0, 0, 0, team, false);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002435 if (err < 0)
2436 goto err_fill;
2437
2438 err = genlmsg_multicast_netns(net, skb, 0, team_change_event_mcgrp.id,
2439 GFP_KERNEL);
2440 return err;
2441
2442err_fill:
2443 nlmsg_free(skb);
2444 return err;
2445}
2446
2447static int team_nl_init(void)
2448{
2449 int err;
2450
2451 err = genl_register_family_with_ops(&team_nl_family, team_nl_ops,
2452 ARRAY_SIZE(team_nl_ops));
2453 if (err)
2454 return err;
2455
2456 err = genl_register_mc_group(&team_nl_family, &team_change_event_mcgrp);
2457 if (err)
2458 goto err_change_event_grp_reg;
2459
2460 return 0;
2461
2462err_change_event_grp_reg:
2463 genl_unregister_family(&team_nl_family);
2464
2465 return err;
2466}
2467
2468static void team_nl_fini(void)
2469{
2470 genl_unregister_family(&team_nl_family);
2471}
2472
2473
2474/******************
2475 * Change checkers
2476 ******************/
2477
Jiri Pirkob82b9182012-01-24 05:16:00 +00002478static void __team_options_change_check(struct team *team)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002479{
2480 int err;
Jiri Pirko01048d92012-06-19 05:54:14 +00002481 struct team_option_inst *opt_inst;
2482 LIST_HEAD(sel_opt_inst_list);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002483
Jiri Pirko01048d92012-06-19 05:54:14 +00002484 list_for_each_entry(opt_inst, &team->option_inst_list, list) {
2485 if (opt_inst->changed)
2486 list_add_tail(&opt_inst->tmp_list, &sel_opt_inst_list);
2487 }
2488 err = team_nl_send_event_options_get(team, &sel_opt_inst_list);
Jiri Pirko0c7517e2012-08-23 03:26:51 +00002489 if (err && err != -ESRCH)
Jiri Pirko9b00cf22012-06-19 05:54:18 +00002490 netdev_warn(team->dev, "Failed to send options change via netlink (err %d)\n",
2491 err);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002492}
2493
2494/* rtnl lock is held */
2495static void __team_port_change_check(struct team_port *port, bool linkup)
2496{
2497 int err;
2498
Jiri Pirko71472ec2012-04-10 05:15:44 +00002499 if (!port->removed && port->state.linkup == linkup)
Jiri Pirko3d249d42011-11-11 22:16:48 +00002500 return;
2501
Jiri Pirkob82b9182012-01-24 05:16:00 +00002502 port->changed = true;
Jiri Pirko71472ec2012-04-10 05:15:44 +00002503 port->state.linkup = linkup;
2504 team_refresh_port_linkup(port);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002505 if (linkup) {
2506 struct ethtool_cmd ecmd;
2507
2508 err = __ethtool_get_settings(port->dev, &ecmd);
2509 if (!err) {
Jiri Pirko71472ec2012-04-10 05:15:44 +00002510 port->state.speed = ethtool_cmd_speed(&ecmd);
2511 port->state.duplex = ecmd.duplex;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002512 goto send_event;
2513 }
2514 }
Jiri Pirko71472ec2012-04-10 05:15:44 +00002515 port->state.speed = 0;
2516 port->state.duplex = 0;
Jiri Pirko3d249d42011-11-11 22:16:48 +00002517
2518send_event:
Jiri Pirkob82b9182012-01-24 05:16:00 +00002519 err = team_nl_send_event_port_list_get(port->team);
Jiri Pirko0c7517e2012-08-23 03:26:51 +00002520 if (err && err != -ESRCH)
2521 netdev_warn(port->team->dev, "Failed to send port change of device %s via netlink (err %d)\n",
2522 port->dev->name, err);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002523
2524}
2525
2526static void team_port_change_check(struct team_port *port, bool linkup)
2527{
2528 struct team *team = port->team;
2529
Jiri Pirko61dc3462011-11-16 11:09:08 +00002530 mutex_lock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002531 __team_port_change_check(port, linkup);
Jiri Pirko61dc3462011-11-16 11:09:08 +00002532 mutex_unlock(&team->lock);
Jiri Pirko3d249d42011-11-11 22:16:48 +00002533}
2534
Jiri Pirko0f1aad22012-06-19 05:54:11 +00002535
Jiri Pirko3d249d42011-11-11 22:16:48 +00002536/************************************
2537 * Net device notifier event handler
2538 ************************************/
2539
2540static int team_device_event(struct notifier_block *unused,
2541 unsigned long event, void *ptr)
2542{
2543 struct net_device *dev = (struct net_device *) ptr;
2544 struct team_port *port;
2545
2546 port = team_port_get_rtnl(dev);
2547 if (!port)
2548 return NOTIFY_DONE;
2549
2550 switch (event) {
2551 case NETDEV_UP:
2552 if (netif_carrier_ok(dev))
2553 team_port_change_check(port, true);
2554 case NETDEV_DOWN:
2555 team_port_change_check(port, false);
2556 case NETDEV_CHANGE:
2557 if (netif_running(port->dev))
2558 team_port_change_check(port,
2559 !!netif_carrier_ok(port->dev));
2560 break;
2561 case NETDEV_UNREGISTER:
2562 team_del_slave(port->team->dev, dev);
2563 break;
2564 case NETDEV_FEAT_CHANGE:
2565 team_compute_features(port->team);
2566 break;
2567 case NETDEV_CHANGEMTU:
2568 /* Forbid to change mtu of underlaying device */
2569 return NOTIFY_BAD;
2570 case NETDEV_PRE_TYPE_CHANGE:
2571 /* Forbid to change type of underlaying device */
2572 return NOTIFY_BAD;
2573 }
2574 return NOTIFY_DONE;
2575}
2576
2577static struct notifier_block team_notifier_block __read_mostly = {
2578 .notifier_call = team_device_event,
2579};
2580
2581
2582/***********************
2583 * Module init and exit
2584 ***********************/
2585
2586static int __init team_module_init(void)
2587{
2588 int err;
2589
2590 register_netdevice_notifier(&team_notifier_block);
2591
2592 err = rtnl_link_register(&team_link_ops);
2593 if (err)
2594 goto err_rtnl_reg;
2595
2596 err = team_nl_init();
2597 if (err)
2598 goto err_nl_init;
2599
2600 return 0;
2601
2602err_nl_init:
2603 rtnl_link_unregister(&team_link_ops);
2604
2605err_rtnl_reg:
2606 unregister_netdevice_notifier(&team_notifier_block);
2607
2608 return err;
2609}
2610
2611static void __exit team_module_exit(void)
2612{
2613 team_nl_fini();
2614 rtnl_link_unregister(&team_link_ops);
2615 unregister_netdevice_notifier(&team_notifier_block);
2616}
2617
2618module_init(team_module_init);
2619module_exit(team_module_exit);
2620
2621MODULE_LICENSE("GPL v2");
2622MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
2623MODULE_DESCRIPTION("Ethernet team device driver");
2624MODULE_ALIAS_RTNL_LINK(DRV_NAME);