team.c 68.9 KB
Newer Older
1
/*
2
 * drivers/net/team/team.c - Network team device driver
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/rcupdate.h>
#include <linux/errno.h>
#include <linux/ctype.h>
#include <linux/notifier.h>
#include <linux/netdevice.h>
Jiri Pirko's avatar
Jiri Pirko committed
21
#include <linux/netpoll.h>
22
#include <linux/if_vlan.h>
23
24
25
26
27
28
29
#include <linux/if_arp.h>
#include <linux/socket.h>
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include <net/rtnetlink.h>
#include <net/genetlink.h>
#include <net/netlink.h>
Jiri Pirko's avatar
Jiri Pirko committed
30
#include <net/sch_generic.h>
Flavio Leitner's avatar
Flavio Leitner committed
31
#include <generated/utsrelease.h>
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <linux/if_team.h>

#define DRV_NAME "team"


/**********
 * Helpers
 **********/

#define team_port_exists(dev) (dev->priv_flags & IFF_TEAM_PORT)

static struct team_port *team_port_get_rcu(const struct net_device *dev)
{
	struct team_port *port = rcu_dereference(dev->rx_handler_data);

	return team_port_exists(dev) ? port : NULL;
}

static struct team_port *team_port_get_rtnl(const struct net_device *dev)
{
	struct team_port *port = rtnl_dereference(dev->rx_handler_data);

	return team_port_exists(dev) ? port : NULL;
}

/*
58
 * Since the ability to change device address for open port device is tested in
59
60
 * team_port_add, this function can be called without control of return value
 */
61
62
static int __set_port_dev_addr(struct net_device *port_dev,
			       const unsigned char *dev_addr)
63
64
65
{
	struct sockaddr addr;

66
67
	memcpy(addr.sa_data, dev_addr, port_dev->addr_len);
	addr.sa_family = port_dev->type;
68
69
70
	return dev_set_mac_address(port_dev, &addr);
}

71
static int team_port_set_orig_dev_addr(struct team_port *port)
72
{
73
	return __set_port_dev_addr(port->dev, port->orig.dev_addr);
74
75
}

76
77
static int team_port_set_team_dev_addr(struct team *team,
				       struct team_port *port)
78
{
79
	return __set_port_dev_addr(port->dev, team->dev->dev_addr);
80
}
81
82
83
84
85
86
87
88
89
90
91
92
93

int team_modeop_port_enter(struct team *team, struct team_port *port)
{
	return team_port_set_team_dev_addr(team, port);
}
EXPORT_SYMBOL(team_modeop_port_enter);

void team_modeop_port_change_dev_addr(struct team *team,
				      struct team_port *port)
{
	team_port_set_team_dev_addr(team, port);
}
EXPORT_SYMBOL(team_modeop_port_change_dev_addr);
94

95
96
97
98
99
static void team_refresh_port_linkup(struct team_port *port)
{
	port->linkup = port->user.linkup_enabled ? port->user.linkup :
						   port->state.linkup;
}
100

Jiri Pirko's avatar
Jiri Pirko committed
101

102
103
104
105
/*******************
 * Options handling
 *******************/

106
107
struct team_option_inst { /* One for each option instance */
	struct list_head list;
108
	struct list_head tmp_list;
109
	struct team_option *option;
110
	struct team_option_inst_info info;
111
112
113
114
115
116
	bool changed;
	bool removed;
};

static struct team_option *__team_find_option(struct team *team,
					      const char *opt_name)
117
118
119
120
121
122
123
124
125
126
{
	struct team_option *option;

	list_for_each_entry(option, &team->option_list, list) {
		if (strcmp(option->name, opt_name) == 0)
			return option;
	}
	return NULL;
}

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
static void __team_option_inst_del(struct team_option_inst *opt_inst)
{
	list_del(&opt_inst->list);
	kfree(opt_inst);
}

static void __team_option_inst_del_option(struct team *team,
					  struct team_option *option)
{
	struct team_option_inst *opt_inst, *tmp;

	list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
		if (opt_inst->option == option)
			__team_option_inst_del(opt_inst);
	}
}

Jiri Pirko's avatar
Jiri Pirko committed
144
145
146
147
148
149
static int __team_option_inst_add(struct team *team, struct team_option *option,
				  struct team_port *port)
{
	struct team_option_inst *opt_inst;
	unsigned int array_size;
	unsigned int i;
150
	int err;
Jiri Pirko's avatar
Jiri Pirko committed
151
152
153
154
155
156
157
158
159
160

	array_size = option->array_size;
	if (!array_size)
		array_size = 1; /* No array but still need one instance */

	for (i = 0; i < array_size; i++) {
		opt_inst = kmalloc(sizeof(*opt_inst), GFP_KERNEL);
		if (!opt_inst)
			return -ENOMEM;
		opt_inst->option = option;
161
162
		opt_inst->info.port = port;
		opt_inst->info.array_index = i;
Jiri Pirko's avatar
Jiri Pirko committed
163
164
165
		opt_inst->changed = true;
		opt_inst->removed = false;
		list_add_tail(&opt_inst->list, &team->option_inst_list);
166
167
168
169
170
171
		if (option->init) {
			err = option->init(team, &opt_inst->info);
			if (err)
				return err;
		}

Jiri Pirko's avatar
Jiri Pirko committed
172
173
174
175
	}
	return 0;
}

176
177
178
179
180
static int __team_option_inst_add_option(struct team *team,
					 struct team_option *option)
{
	int err;

Jiri Pirko's avatar
Jiri Pirko committed
181
	if (!option->per_port) {
182
		err = __team_option_inst_add(team, option, NULL);
Jiri Pirko's avatar
Jiri Pirko committed
183
184
185
		if (err)
			goto inst_del_option;
	}
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	return 0;

inst_del_option:
	__team_option_inst_del_option(team, option);
	return err;
}

static void __team_option_inst_mark_removed_option(struct team *team,
						   struct team_option *option)
{
	struct team_option_inst *opt_inst;

	list_for_each_entry(opt_inst, &team->option_inst_list, list) {
		if (opt_inst->option == option) {
			opt_inst->changed = true;
			opt_inst->removed = true;
		}
	}
}

static void __team_option_inst_del_port(struct team *team,
					struct team_port *port)
{
	struct team_option_inst *opt_inst, *tmp;

	list_for_each_entry_safe(opt_inst, tmp, &team->option_inst_list, list) {
		if (opt_inst->option->per_port &&
213
		    opt_inst->info.port == port)
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
			__team_option_inst_del(opt_inst);
	}
}

static int __team_option_inst_add_port(struct team *team,
				       struct team_port *port)
{
	struct team_option *option;
	int err;

	list_for_each_entry(option, &team->option_list, list) {
		if (!option->per_port)
			continue;
		err = __team_option_inst_add(team, option, port);
		if (err)
			goto inst_del_port;
	}
	return 0;

inst_del_port:
	__team_option_inst_del_port(team, port);
	return err;
}

static void __team_option_inst_mark_removed_port(struct team *team,
						 struct team_port *port)
{
	struct team_option_inst *opt_inst;

	list_for_each_entry(opt_inst, &team->option_inst_list, list) {
244
		if (opt_inst->info.port == port) {
245
246
247
248
249
250
251
252
253
			opt_inst->changed = true;
			opt_inst->removed = true;
		}
	}
}

static int __team_options_register(struct team *team,
				   const struct team_option *option,
				   size_t option_count)
254
255
{
	int i;
256
	struct team_option **dst_opts;
257
	int err;
258

259
260
261
262
	dst_opts = kzalloc(sizeof(struct team_option *) * option_count,
			   GFP_KERNEL);
	if (!dst_opts)
		return -ENOMEM;
263
264
265
	for (i = 0; i < option_count; i++, option++) {
		if (__team_find_option(team, option->name)) {
			err = -EEXIST;
266
			goto alloc_rollback;
267
		}
268
269
		dst_opts[i] = kmemdup(option, sizeof(*option), GFP_KERNEL);
		if (!dst_opts[i]) {
270
			err = -ENOMEM;
271
			goto alloc_rollback;
272
273
274
		}
	}

275
	for (i = 0; i < option_count; i++) {
276
277
278
		err = __team_option_inst_add_option(team, dst_opts[i]);
		if (err)
			goto inst_rollback;
279
		list_add_tail(&dst_opts[i]->list, &team->option_list);
280
	}
281

282
	kfree(dst_opts);
283
284
	return 0;

285
286
287
288
289
290
291
inst_rollback:
	for (i--; i >= 0; i--)
		__team_option_inst_del_option(team, dst_opts[i]);

	i = option_count - 1;
alloc_rollback:
	for (i--; i >= 0; i--)
292
293
		kfree(dst_opts[i]);

294
	kfree(dst_opts);
295
	return err;
296
}
297

298
299
300
301
302
303
304
305
static void __team_options_mark_removed(struct team *team,
					const struct team_option *option,
					size_t option_count)
{
	int i;

	for (i = 0; i < option_count; i++, option++) {
		struct team_option *del_opt;
306

307
		del_opt = __team_find_option(team, option->name);
308
309
		if (del_opt)
			__team_option_inst_mark_removed_option(team, del_opt);
310
311
	}
}
312
313

static void __team_options_unregister(struct team *team,
314
				      const struct team_option *option,
315
316
317
318
				      size_t option_count)
{
	int i;

319
320
321
322
323
	for (i = 0; i < option_count; i++, option++) {
		struct team_option *del_opt;

		del_opt = __team_find_option(team, option->name);
		if (del_opt) {
324
			__team_option_inst_del_option(team, del_opt);
325
326
327
328
			list_del(&del_opt->list);
			kfree(del_opt);
		}
	}
329
330
}

331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
static void __team_options_change_check(struct team *team);

int team_options_register(struct team *team,
			  const struct team_option *option,
			  size_t option_count)
{
	int err;

	err = __team_options_register(team, option, option_count);
	if (err)
		return err;
	__team_options_change_check(team);
	return 0;
}
EXPORT_SYMBOL(team_options_register);

347
348
void team_options_unregister(struct team *team,
			     const struct team_option *option,
349
350
			     size_t option_count)
{
351
352
	__team_options_mark_removed(team, option, option_count);
	__team_options_change_check(team);
353
354
355
356
	__team_options_unregister(team, option, option_count);
}
EXPORT_SYMBOL(team_options_unregister);

357
358
359
360
static int team_option_get(struct team *team,
			   struct team_option_inst *opt_inst,
			   struct team_gsetter_ctx *ctx)
{
361
362
	if (!opt_inst->option->getter)
		return -EOPNOTSUPP;
363
364
365
366
367
368
	return opt_inst->option->getter(team, ctx);
}

static int team_option_set(struct team *team,
			   struct team_option_inst *opt_inst,
			   struct team_gsetter_ctx *ctx)
369
{
370
371
	if (!opt_inst->option->setter)
		return -EOPNOTSUPP;
372
	return opt_inst->option->setter(team, ctx);
373
374
}

Jiri Pirko's avatar
Jiri Pirko committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
void team_option_inst_set_change(struct team_option_inst_info *opt_inst_info)
{
	struct team_option_inst *opt_inst;

	opt_inst = container_of(opt_inst_info, struct team_option_inst, info);
	opt_inst->changed = true;
}
EXPORT_SYMBOL(team_option_inst_set_change);

void team_options_change_check(struct team *team)
{
	__team_options_change_check(team);
}
EXPORT_SYMBOL(team_options_change_check);


391
392
393
394
395
396
397
/****************
 * Mode handling
 ****************/

static LIST_HEAD(mode_list);
static DEFINE_SPINLOCK(mode_list_lock);

Jiri Pirko's avatar
Jiri Pirko committed
398
399
400
401
402
403
struct team_mode_item {
	struct list_head list;
	const struct team_mode *mode;
};

static struct team_mode_item *__find_mode(const char *kind)
404
{
Jiri Pirko's avatar
Jiri Pirko committed
405
	struct team_mode_item *mitem;
406

Jiri Pirko's avatar
Jiri Pirko committed
407
408
409
	list_for_each_entry(mitem, &mode_list, list) {
		if (strcmp(mitem->mode->kind, kind) == 0)
			return mitem;
410
411
412
413
414
415
416
417
418
419
420
421
422
423
	}
	return NULL;
}

static bool is_good_mode_name(const char *name)
{
	while (*name != '\0') {
		if (!isalpha(*name) && !isdigit(*name) && *name != '_')
			return false;
		name++;
	}
	return true;
}

Jiri Pirko's avatar
Jiri Pirko committed
424
int team_mode_register(const struct team_mode *mode)
425
426
{
	int err = 0;
Jiri Pirko's avatar
Jiri Pirko committed
427
	struct team_mode_item *mitem;
428
429
430
431

	if (!is_good_mode_name(mode->kind) ||
	    mode->priv_size > TEAM_MODE_PRIV_SIZE)
		return -EINVAL;
Jiri Pirko's avatar
Jiri Pirko committed
432
433
434
435
436

	mitem = kmalloc(sizeof(*mitem), GFP_KERNEL);
	if (!mitem)
		return -ENOMEM;

437
438
439
	spin_lock(&mode_list_lock);
	if (__find_mode(mode->kind)) {
		err = -EEXIST;
Jiri Pirko's avatar
Jiri Pirko committed
440
		kfree(mitem);
441
442
		goto unlock;
	}
Jiri Pirko's avatar
Jiri Pirko committed
443
444
	mitem->mode = mode;
	list_add_tail(&mitem->list, &mode_list);
445
446
447
448
449
450
unlock:
	spin_unlock(&mode_list_lock);
	return err;
}
EXPORT_SYMBOL(team_mode_register);

Jiri Pirko's avatar
Jiri Pirko committed
451
void team_mode_unregister(const struct team_mode *mode)
452
{
Jiri Pirko's avatar
Jiri Pirko committed
453
454
	struct team_mode_item *mitem;

455
	spin_lock(&mode_list_lock);
Jiri Pirko's avatar
Jiri Pirko committed
456
457
458
459
460
	mitem = __find_mode(mode->kind);
	if (mitem) {
		list_del_init(&mitem->list);
		kfree(mitem);
	}
461
462
463
464
	spin_unlock(&mode_list_lock);
}
EXPORT_SYMBOL(team_mode_unregister);

Jiri Pirko's avatar
Jiri Pirko committed
465
static const struct team_mode *team_mode_get(const char *kind)
466
{
Jiri Pirko's avatar
Jiri Pirko committed
467
468
	struct team_mode_item *mitem;
	const struct team_mode *mode = NULL;
469
470

	spin_lock(&mode_list_lock);
Jiri Pirko's avatar
Jiri Pirko committed
471
472
	mitem = __find_mode(kind);
	if (!mitem) {
473
474
475
		spin_unlock(&mode_list_lock);
		request_module("team-mode-%s", kind);
		spin_lock(&mode_list_lock);
Jiri Pirko's avatar
Jiri Pirko committed
476
		mitem = __find_mode(kind);
477
	}
Jiri Pirko's avatar
Jiri Pirko committed
478
479
	if (mitem) {
		mode = mitem->mode;
480
481
		if (!try_module_get(mode->owner))
			mode = NULL;
Jiri Pirko's avatar
Jiri Pirko committed
482
	}
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498

	spin_unlock(&mode_list_lock);
	return mode;
}

static void team_mode_put(const struct team_mode *mode)
{
	module_put(mode->owner);
}

static bool team_dummy_transmit(struct team *team, struct sk_buff *skb)
{
	dev_kfree_skb_any(skb);
	return false;
}

499
500
501
static rx_handler_result_t team_dummy_receive(struct team *team,
					      struct team_port *port,
					      struct sk_buff *skb)
502
503
504
505
{
	return RX_HANDLER_ANOTHER;
}

506
507
508
509
510
511
512
513
514
515
516
static const struct team_mode __team_no_mode = {
	.kind		= "*NOMODE*",
};

static bool team_is_mode_set(struct team *team)
{
	return team->mode != &__team_no_mode;
}

static void team_set_no_mode(struct team *team)
{
517
	team->user_carrier_enabled = false;
518
519
520
	team->mode = &__team_no_mode;
}

521
static void team_adjust_ops(struct team *team)
522
523
524
525
526
527
{
	/*
	 * To avoid checks in rx/tx skb paths, ensure here that non-null and
	 * correct ops are always set.
	 */

528
	if (!team->en_port_count || !team_is_mode_set(team) ||
529
	    !team->mode->ops->transmit)
530
531
532
533
		team->ops.transmit = team_dummy_transmit;
	else
		team->ops.transmit = team->mode->ops->transmit;

534
	if (!team->en_port_count || !team_is_mode_set(team) ||
535
	    !team->mode->ops->receive)
536
537
538
539
540
541
542
543
544
545
546
547
548
549
		team->ops.receive = team_dummy_receive;
	else
		team->ops.receive = team->mode->ops->receive;
}

/*
 * We can benefit from the fact that it's ensured no port is present
 * at the time of mode change. Therefore no packets are in fly so there's no
 * need to set mode operations in any special way.
 */
static int __team_change_mode(struct team *team,
			      const struct team_mode *new_mode)
{
	/* Check if mode was previously set and do cleanup if so */
550
	if (team_is_mode_set(team)) {
551
552
553
554
555
556
557
558
559
		void (*exit_op)(struct team *team) = team->ops.exit;

		/* Clear ops area so no callback is called any longer */
		memset(&team->ops, 0, sizeof(struct team_mode_ops));
		team_adjust_ops(team);

		if (exit_op)
			exit_op(team);
		team_mode_put(team->mode);
560
		team_set_no_mode(team);
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
		/* zero private data area */
		memset(&team->mode_priv, 0,
		       sizeof(struct team) - offsetof(struct team, mode_priv));
	}

	if (!new_mode)
		return 0;

	if (new_mode->ops->init) {
		int err;

		err = new_mode->ops->init(team);
		if (err)
			return err;
	}

	team->mode = new_mode;
	memcpy(&team->ops, new_mode->ops, sizeof(struct team_mode_ops));
	team_adjust_ops(team);

	return 0;
}

static int team_change_mode(struct team *team, const char *kind)
{
Jiri Pirko's avatar
Jiri Pirko committed
586
	const struct team_mode *new_mode;
587
588
589
590
591
592
593
594
	struct net_device *dev = team->dev;
	int err;

	if (!list_empty(&team->port_list)) {
		netdev_err(dev, "No ports can be present during mode change\n");
		return -EBUSY;
	}

595
	if (team_is_mode_set(team) && strcmp(team->mode->kind, kind) == 0) {
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
		netdev_err(dev, "Unable to change to the same mode the team is in\n");
		return -EINVAL;
	}

	new_mode = team_mode_get(kind);
	if (!new_mode) {
		netdev_err(dev, "Mode \"%s\" not found\n", kind);
		return -EINVAL;
	}

	err = __team_change_mode(team, new_mode);
	if (err) {
		netdev_err(dev, "Failed to change to mode \"%s\"\n", kind);
		team_mode_put(new_mode);
		return err;
	}

	netdev_info(dev, "Mode changed to \"%s\"\n", kind);
	return 0;
}


Jiri Pirko's avatar
Jiri Pirko committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/*********************
 * Peers notification
 *********************/

static void team_notify_peers_work(struct work_struct *work)
{
	struct team *team;

	team = container_of(work, struct team, notify_peers.dw.work);

	if (!rtnl_trylock()) {
		schedule_delayed_work(&team->notify_peers.dw, 0);
		return;
	}
	call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, team->dev);
	rtnl_unlock();
	if (!atomic_dec_and_test(&team->notify_peers.count_pending))
		schedule_delayed_work(&team->notify_peers.dw,
				      msecs_to_jiffies(team->notify_peers.interval));
}

static void team_notify_peers(struct team *team)
{
	if (!team->notify_peers.count || !netif_running(team->dev))
		return;
643
	atomic_add(team->notify_peers.count, &team->notify_peers.count_pending);
Jiri Pirko's avatar
Jiri Pirko committed
644
645
646
647
648
649
650
651
652
653
654
655
656
657
	schedule_delayed_work(&team->notify_peers.dw, 0);
}

static void team_notify_peers_init(struct team *team)
{
	INIT_DELAYED_WORK(&team->notify_peers.dw, team_notify_peers_work);
}

static void team_notify_peers_fini(struct team *team)
{
	cancel_delayed_work_sync(&team->notify_peers.dw);
}


658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/*******************************
 * Send multicast group rejoins
 *******************************/

static void team_mcast_rejoin_work(struct work_struct *work)
{
	struct team *team;

	team = container_of(work, struct team, mcast_rejoin.dw.work);

	if (!rtnl_trylock()) {
		schedule_delayed_work(&team->mcast_rejoin.dw, 0);
		return;
	}
	call_netdevice_notifiers(NETDEV_RESEND_IGMP, team->dev);
	rtnl_unlock();
	if (!atomic_dec_and_test(&team->mcast_rejoin.count_pending))
		schedule_delayed_work(&team->mcast_rejoin.dw,
				      msecs_to_jiffies(team->mcast_rejoin.interval));
}

static void team_mcast_rejoin(struct team *team)
{
	if (!team->mcast_rejoin.count || !netif_running(team->dev))
		return;
683
	atomic_add(team->mcast_rejoin.count, &team->mcast_rejoin.count_pending);
684
685
686
687
688
689
690
691
692
693
694
695
696
697
	schedule_delayed_work(&team->mcast_rejoin.dw, 0);
}

static void team_mcast_rejoin_init(struct team *team)
{
	INIT_DELAYED_WORK(&team->mcast_rejoin.dw, team_mcast_rejoin_work);
}

static void team_mcast_rejoin_fini(struct team *team)
{
	cancel_delayed_work_sync(&team->mcast_rejoin.dw);
}


698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/************************
 * Rx path frame handler
 ************************/

/* note: already called with rcu_read_lock */
static rx_handler_result_t team_handle_frame(struct sk_buff **pskb)
{
	struct sk_buff *skb = *pskb;
	struct team_port *port;
	struct team *team;
	rx_handler_result_t res;

	skb = skb_share_check(skb, GFP_ATOMIC);
	if (!skb)
		return RX_HANDLER_CONSUMED;

	*pskb = skb;

	port = team_port_get_rcu(skb->dev);
	team = port->team;
718
719
720
721
722
723
	if (!team_port_enabled(port)) {
		/* allow exact match delivery for disabled ports */
		res = RX_HANDLER_EXACT;
	} else {
		res = team->ops.receive(team, port, skb);
	}
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
	if (res == RX_HANDLER_ANOTHER) {
		struct team_pcpu_stats *pcpu_stats;

		pcpu_stats = this_cpu_ptr(team->pcpu_stats);
		u64_stats_update_begin(&pcpu_stats->syncp);
		pcpu_stats->rx_packets++;
		pcpu_stats->rx_bytes += skb->len;
		if (skb->pkt_type == PACKET_MULTICAST)
			pcpu_stats->rx_multicast++;
		u64_stats_update_end(&pcpu_stats->syncp);

		skb->dev = team->dev;
	} else {
		this_cpu_inc(team->pcpu_stats->rx_dropped);
	}

	return res;
}


744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/*************************************
 * Multiqueue Tx port select override
 *************************************/

static int team_queue_override_init(struct team *team)
{
	struct list_head *listarr;
	unsigned int queue_cnt = team->dev->num_tx_queues - 1;
	unsigned int i;

	if (!queue_cnt)
		return 0;
	listarr = kmalloc(sizeof(struct list_head) * queue_cnt, GFP_KERNEL);
	if (!listarr)
		return -ENOMEM;
	team->qom_lists = listarr;
	for (i = 0; i < queue_cnt; i++)
		INIT_LIST_HEAD(listarr++);
	return 0;
}

static void team_queue_override_fini(struct team *team)
{
	kfree(team->qom_lists);
}

static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id)
{
	return &team->qom_lists[queue_id - 1];
}

/*
 * note: already called with rcu_read_lock
 */
static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb)
{
	struct list_head *qom_list;
	struct team_port *port;

	if (!team->queue_override_enabled || !skb->queue_mapping)
		return false;
	qom_list = __team_get_qom_list(team, skb->queue_mapping);
	list_for_each_entry_rcu(port, qom_list, qom_list) {
		if (!team_dev_queue_xmit(team, port, skb))
			return true;
	}
	return false;
}

static void __team_queue_override_port_del(struct team *team,
					   struct team_port *port)
{
796
797
	if (!port->queue_id)
		return;
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
	list_del_rcu(&port->qom_list);
}

static bool team_queue_override_port_has_gt_prio_than(struct team_port *port,
						      struct team_port *cur)
{
	if (port->priority < cur->priority)
		return true;
	if (port->priority > cur->priority)
		return false;
	if (port->index < cur->index)
		return true;
	return false;
}

static void __team_queue_override_port_add(struct team *team,
					   struct team_port *port)
{
	struct team_port *cur;
	struct list_head *qom_list;
	struct list_head *node;

820
	if (!port->queue_id)
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
		return;
	qom_list = __team_get_qom_list(team, port->queue_id);
	node = qom_list;
	list_for_each_entry(cur, qom_list, qom_list) {
		if (team_queue_override_port_has_gt_prio_than(port, cur))
			break;
		node = &cur->qom_list;
	}
	list_add_tail_rcu(&port->qom_list, node);
}

static void __team_queue_override_enabled_check(struct team *team)
{
	struct team_port *port;
	bool enabled = false;

	list_for_each_entry(port, &team->port_list, list) {
838
		if (port->queue_id) {
839
840
841
842
843
844
845
846
847
848
849
			enabled = true;
			break;
		}
	}
	if (enabled == team->queue_override_enabled)
		return;
	netdev_dbg(team->dev, "%s queue override\n",
		   enabled ? "Enabling" : "Disabling");
	team->queue_override_enabled = enabled;
}

850
851
static void team_queue_override_port_prio_changed(struct team *team,
						  struct team_port *port)
852
{
853
854
	if (!port->queue_id || team_port_enabled(port))
		return;
855
856
857
858
859
	__team_queue_override_port_del(team, port);
	__team_queue_override_port_add(team, port);
	__team_queue_override_enabled_check(team);
}

860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
static void team_queue_override_port_change_queue_id(struct team *team,
						     struct team_port *port,
						     u16 new_queue_id)
{
	if (team_port_enabled(port)) {
		__team_queue_override_port_del(team, port);
		port->queue_id = new_queue_id;
		__team_queue_override_port_add(team, port);
		__team_queue_override_enabled_check(team);
	} else {
		port->queue_id = new_queue_id;
	}
}

static void team_queue_override_port_add(struct team *team,
					 struct team_port *port)
{
	__team_queue_override_port_add(team, port);
	__team_queue_override_enabled_check(team);
}

static void team_queue_override_port_del(struct team *team,
					 struct team_port *port)
{
	__team_queue_override_port_del(team, port);
	__team_queue_override_enabled_check(team);
}

888

889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
/****************
 * Port handling
 ****************/

static bool team_port_find(const struct team *team,
			   const struct team_port *port)
{
	struct team_port *cur;

	list_for_each_entry(cur, &team->port_list, list)
		if (cur == port)
			return true;
	return false;
}

/*
905
906
907
908
 * Enable/disable port by adding to enabled port hashlist and setting
 * port->index (Might be racy so reader could see incorrect ifindex when
 * processing a flying packet, but that is not a problem). Write guarded
 * by team->lock.
909
 */
910
911
static void team_port_enable(struct team *team,
			     struct team_port *port)
912
{
913
914
915
	if (team_port_enabled(port))
		return;
	port->index = team->en_port_count++;
916
917
	hlist_add_head_rcu(&port->hlist,
			   team_port_index_hash(team, port->index));
918
	team_adjust_ops(team);
919
	team_queue_override_port_add(team, port);
920
921
	if (team->ops.port_enabled)
		team->ops.port_enabled(team, port);
Jiri Pirko's avatar
Jiri Pirko committed
922
	team_notify_peers(team);
923
	team_mcast_rejoin(team);
924
925
926
927
928
929
930
}

static void __reconstruct_port_hlist(struct team *team, int rm_index)
{
	int i;
	struct team_port *port;

931
	for (i = rm_index + 1; i < team->en_port_count; i++) {
932
933
934
935
936
937
938
939
		port = team_get_port_by_index(team, i);
		hlist_del_rcu(&port->hlist);
		port->index--;
		hlist_add_head_rcu(&port->hlist,
				   team_port_index_hash(team, port->index));
	}
}

940
941
static void team_port_disable(struct team *team,
			      struct team_port *port)
942
{
943
944
	if (!team_port_enabled(port))
		return;
945
946
	if (team->ops.port_disabled)
		team->ops.port_disabled(team, port);
947
	hlist_del_rcu(&port->hlist);
948
	__reconstruct_port_hlist(team, port->index);
949
	port->index = -1;
950
	team->en_port_count--;
951
952
	team_queue_override_port_del(team, port);
	team_adjust_ops(team);
Jiri Pirko's avatar
Jiri Pirko committed
953
	team_notify_peers(team);
954
	team_mcast_rejoin(team);
955
956
957
958
959
960
961
962
963
}

#define TEAM_VLAN_FEATURES (NETIF_F_ALL_CSUM | NETIF_F_SG | \
			    NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
			    NETIF_F_HIGHDMA | NETIF_F_LRO)

static void __team_compute_features(struct team *team)
{
	struct team_port *port;
964
	u32 vlan_features = TEAM_VLAN_FEATURES & NETIF_F_ALL_FOR_ALL;
965
	unsigned short max_hard_header_len = ETH_HLEN;
966
967
	unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
					IFF_XMIT_DST_RELEASE_PERM;
968
969
970
971
972
973

	list_for_each_entry(port, &team->port_list, list) {
		vlan_features = netdev_increment_features(vlan_features,
					port->dev->vlan_features,
					TEAM_VLAN_FEATURES);

974
		dst_release_flag &= port->dev->priv_flags;
975
976
977
978
979
980
981
		if (port->dev->hard_header_len > max_hard_header_len)
			max_hard_header_len = port->dev->hard_header_len;
	}

	team->dev->vlan_features = vlan_features;
	team->dev->hard_header_len = max_hard_header_len;

982
983
984
	team->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
	if (dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM))
		team->dev->priv_flags |= IFF_XMIT_DST_RELEASE;
985

986
987
988
989
990
	netdev_change_features(team->dev);
}

static void team_compute_features(struct team *team)
{
991
	mutex_lock(&team->lock);
992
	__team_compute_features(team);
993
	mutex_unlock(&team->lock);
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
}

static int team_port_enter(struct team *team, struct team_port *port)
{
	int err = 0;

	dev_hold(team->dev);
	if (team->ops.port_enter) {
		err = team->ops.port_enter(team, port);
		if (err) {
			netdev_err(team->dev, "Device %s failed to enter team mode\n",
				   port->dev->name);
			goto err_port_enter;
		}
	}

	return 0;

err_port_enter:
	dev_put(team->dev);

	return err;
}

static void team_port_leave(struct team *team, struct team_port *port)
{
	if (team->ops.port_leave)
		team->ops.port_leave(team, port);
	dev_put(team->dev);
}

Jiri Pirko's avatar
Jiri Pirko committed
1025
#ifdef CONFIG_NET_POLL_CONTROLLER
1026
static int team_port_enable_netpoll(struct team *team, struct team_port *port)
Jiri Pirko's avatar
Jiri Pirko committed
1027
1028
1029
1030
{
	struct netpoll *np;
	int err;

1031
1032
1033
	if (!team->dev->npinfo)
		return 0;

1034
	np = kzalloc(sizeof(*np), GFP_KERNEL);
Jiri Pirko's avatar
Jiri Pirko committed
1035
1036
1037
	if (!np)
		return -ENOMEM;

1038
	err = __netpoll_setup(np, port->dev);
Jiri Pirko's avatar
Jiri Pirko committed
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
	if (err) {
		kfree(np);
		return err;
	}
	port->np = np;
	return err;
}

static void team_port_disable_netpoll(struct team_port *port)
{
	struct netpoll *np = port->np;

	if (!np)
		return;
	port->np = NULL;

	/* Wait for transmitting packets to finish before freeing. */
	synchronize_rcu_bh();
	__netpoll_cleanup(np);
	kfree(np);
}
#else
1061
static int team_port_enable_netpoll(struct team *team, struct team_port *port)
Jiri Pirko's avatar
Jiri Pirko committed
1062
1063
1064
1065
1066
1067
1068
1069
{
	return 0;
}
static void team_port_disable_netpoll(struct team_port *port)
{
}
#endif

1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
static int team_upper_dev_link(struct net_device *dev,
			       struct net_device *port_dev)
{
	int err;

	err = netdev_master_upper_dev_link(port_dev, dev);
	if (err)
		return err;
	port_dev->priv_flags |= IFF_TEAM_PORT;
	return 0;
}

static void team_upper_dev_unlink(struct net_device *dev,
				  struct net_device *port_dev)
{
	netdev_upper_dev_unlink(port_dev, dev);
	port_dev->priv_flags &= ~IFF_TEAM_PORT;
}

1089
static void __team_port_change_port_added(struct team_port *port, bool linkup);
1090
1091
static int team_dev_type_check_change(struct net_device *dev,
				      struct net_device *port_dev);
1092
1093
1094
1095
1096
1097
1098
1099

static int team_port_add(struct team *team, struct net_device *port_dev)
{
	struct net_device *dev = team->dev;
	struct team_port *port;
	char *portname = port_dev->name;
	int err;

1100
1101
	if (port_dev->flags & IFF_LOOPBACK) {
		netdev_err(dev, "Device %s is loopback device. Loopback devices can't be added as a team port\n",
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
			   portname);
		return -EINVAL;
	}

	if (team_port_exists(port_dev)) {
		netdev_err(dev, "Device %s is already a port "
				"of a team device\n", portname);
		return -EBUSY;
	}

1112
1113
1114
1115
1116
1117
1118
	if (port_dev->features & NETIF_F_VLAN_CHALLENGED &&
	    vlan_uses_dev(dev)) {
		netdev_err(dev, "Device %s is VLAN challenged and team device has VLAN set up\n",
			   portname);
		return -EPERM;
	}

1119
1120
1121
1122
	err = team_dev_type_check_change(dev, port_dev);
	if (err)
		return err;

1123
1124
1125
1126
1127
1128
	if (port_dev->flags & IFF_UP) {
		netdev_err(dev, "Device %s is up. Set it down before adding it as a team port\n",
			   portname);
		return -EBUSY;
	}

Jiri Pirko's avatar
Jiri Pirko committed
1129
1130
	port = kzalloc(sizeof(struct team_port) + team->mode->port_priv_size,
		       GFP_KERNEL);
1131
1132
1133
1134
1135
	if (!port)
		return -ENOMEM;

	port->dev = port_dev;
	port->team = team;
1136
	INIT_LIST_HEAD(&port->qom_list);
1137
1138
1139
1140
1141
1142
1143
1144

	port->orig.mtu = port_dev->mtu;
	err = dev_set_mtu(port_dev, dev->mtu);
	if (err) {
		netdev_dbg(dev, "Error %d calling dev_set_mtu\n", err);
		goto err_set_mtu;
	}

1145
	memcpy(port->orig.dev_addr, port_dev->dev_addr, port_dev->addr_len);
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160

	err = team_port_enter(team, port);
	if (err) {
		netdev_err(dev, "Device %s failed to enter team mode\n",
			   portname);
		goto err_port_enter;
	}

	err = dev_open(port_dev);
	if (err) {
		netdev_dbg(dev, "Device %s opening failed\n",
			   portname);
		goto err_dev_open;
	}

1161
1162
1163
1164
1165
1166
1167
	err = vlan_vids_add_by_dev(port_dev, dev);
	if (err) {
		netdev_err(dev, "Failed to add vlan ids to device %s\n",
				portname);
		goto err_vids_add;
	}

1168
	err = team_port_enable_netpoll(team, port);
1169
1170
1171
1172
	if (err) {
		netdev_err(dev, "Failed to enable netpoll on device %s\n",
			   portname);
		goto err_enable_netpoll;
Jiri Pirko's avatar
Jiri Pirko committed
1173
1174
	}

1175
1176
1177
	if (!(dev->features & NETIF_F_LRO))
		dev_disable_lro(port_dev);

1178
1179
1180
1181
1182
1183
1184
1185
	err = netdev_rx_handler_register(port_dev, team_handle_frame,
					 port);
	if (err) {
		netdev_err(dev, "Device %s failed to register rx_handler\n",
			   portname);
		goto err_handler_register;
	}

1186
1187
1188
1189
1190
1191
1192
	err = team_upper_dev_link(dev, port_dev);
	if (err) {
		netdev_err(dev, "Device %s failed to set upper link\n",
			   portname);
		goto err_set_upper_link;
	}

1193
	err = __team_option_inst_add_port(team, port);
1194
1195
1196
1197
1198
1199
	if (err) {
		netdev_err(dev, "Device %s failed to add per-port options\n",
			   portname);
		goto err_option_port_add;
	}

1200
1201
	port->index = -1;
	list_add_tail_rcu(&port->list, &team->port_list);
1202
	team_port_enable(team, port);
1203
	__team_compute_features(team);
1204
	__team_port_change_port_added(port, !!netif_carrier_ok(port_dev));
1205
	__team_options_change_check(team);
1206
1207
1208
1209
1210

	netdev_info(dev, "Port device %s added\n", portname);

	return 0;

1211
err_option_port_add:
1212
1213
1214
	team_upper_dev_unlink(dev, port_dev);

err_set_upper_link:
1215
1216
	netdev_rx_handler_unregister(port_dev);

1217
err_handler_register:
Jiri Pirko's avatar
Jiri Pirko committed
1218
1219
1220
	team_port_disable_netpoll(port);

err_enable_netpoll:
1221
1222
1223
	vlan_vids_del_by_dev(port_dev, dev);

err_vids_add:
1224
1225
1226
1227
	dev_close(port_dev);

err_dev_open:
	team_port_leave(team, port);
1228
	team_port_set_orig_dev_addr(port);
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

err_port_enter:
	dev_set_mtu(port_dev, port->orig.mtu);

err_set_mtu:
	kfree(port);

	return err;
}

1239
1240
static void __team_port_change_port_removed(struct team_port *port);

1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
static int team_port_del(struct team *team, struct net_device *port_dev)
{
	struct net_device *dev = team->dev;
	struct team_port *port;
	char *portname = port_dev->name;

	port = team_port_get_rtnl(port_dev);
	if (!port || !team_port_find(team, port)) {
		netdev_err(dev, "Device %s does not act as a port of this team\n",
			   portname);
		return -ENOENT;
	}

1254
1255
	team_port_disable(team, port);
	list_del_rcu(&port->list);
1256
	team_upper_dev_unlink(dev, port_dev);
1257
	netdev_rx_handler_unregister(port_dev);
Jiri Pirko's avatar
Jiri Pirko committed
1258
	team_port_disable_netpoll(port);
1259
	vlan_vids_del_by_dev(port_dev, dev);
1260
1261
	dev_uc_unsync(port_dev, dev);
	dev_mc_unsync(port_dev, dev);
1262
1263
	dev_close(port_dev);
	team_port_leave(team, port);
1264
1265
1266
1267
1268
1269

	__team_option_inst_mark_removed_port(team, port);
	__team_options_change_check(team);
	__team_option_inst_del_port(team, port);
	__team_port_change_port_removed(port);

1270
	team_port_set_orig_dev_addr(port);
1271
	dev_set_mtu(port_dev, port->orig.mtu);
1272
	kfree_rcu(port, rcu);
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
	netdev_info(dev, "Port device %s removed\n", portname);
	__team_compute_features(team);

	return 0;
}


/*****************
 * Net device ops
 *****************/

1284
static int team_mode_option_get(struct team *team, struct team_gsetter_ctx *ctx)
1285
{
1286
	ctx->data.str_val = team->mode->kind;
1287
1288
1289
	return 0;
}

1290
static int team_mode_option_set(struct team *team, struct team_gsetter_ctx *ctx)
1291
{
1292
	return team_change_mode(team, ctx->data.str_val);
1293
1294
}

Jiri Pirko's avatar
Jiri Pirko committed
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
static int team_notify_peers_count_get(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
	ctx->data.u32_val = team->notify_peers.count;
	return 0;
}

static int team_notify_peers_count_set(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
	team->notify_peers.count = ctx->data.u32_val;
	return 0;
}

static int team_notify_peers_interval_get(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
	ctx->data.u32_val = team->notify_peers.interval;
	return 0;
}

static int team_notify_peers_interval_set(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
	team->notify_peers.interval = ctx->data.u32_val;
	return 0;
}

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
static int team_mcast_rejoin_count_get(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
	ctx->data.u32_val = team->mcast_rejoin.count;
	return 0;
}

static int team_mcast_rejoin_count_set(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
	team->mcast_rejoin.count = ctx->data.u32_val;
	return 0;
}

static int team_mcast_rejoin_interval_get(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
	ctx->data.u32_val = team->mcast_rejoin.interval;
	return 0;
}

static int team_mcast_rejoin_interval_set(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
	team->mcast_rejoin.interval = ctx->data.u32_val;
	return 0;
}

1351
1352
1353
static int team_port_en_option_get(struct team *team,
				   struct team_gsetter_ctx *ctx)
{
1354
1355
1356
	struct team_port *port = ctx->info->port;

	ctx->data.bool_val = team_port_enabled(port);
1357
1358
1359
1360
1361
1362
	return 0;
}

static int team_port_en_option_set(struct team *team,
				   struct team_gsetter_ctx *ctx)
{
1363
1364
	struct team_port *port = ctx->info->port;

1365
	if (ctx->data.bool_val)
1366
		team_port_enable(team, port);
1367
	else
1368
		team_port_disable(team, port);
1369
1370
1371
	return 0;
}

1372
1373
1374
static int team_user_linkup_option_get(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
1375
1376
1377
	struct team_port *port = ctx->info->port;

	ctx->data.bool_val = port->user.linkup;
1378
1379
1380
	return 0;
}

1381
1382
static void __team_carrier_check(struct team *team);

1383
1384
1385
static int team_user_linkup_option_set(struct team *team,
				       struct team_gsetter_ctx *ctx)
{
1386
1387
1388
1389
	struct team_port *port = ctx->info->port;

	port->user.linkup = ctx->data.bool_val;
	team_refresh_port_linkup(port);
1390
	__team_carrier_check(port->team);
1391
1392
1393
1394
1395
1396
	return 0;
}

static int team_user_linkup_en_option_get(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
1397
	struct team_port *port = ctx->info->port;
1398
1399
1400
1401
1402
1403
1404
1405

	ctx->data.bool_val = port->user.linkup_enabled;
	return 0;
}

static int team_user_linkup_en_option_set(struct team *team,
					  struct team_gsetter_ctx *ctx)
{
1406
	struct team_port *port = ctx->info->port;
1407
1408

	port->user.linkup_enabled = ctx->data.bool_val;
1409
	team_refresh_port_linkup(port);
1410
	__team_carrier_check(port->team);
1411
1412
1413
	return 0;
}

1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
static int team_priority_option_get(struct team *team,
				    struct team_gsetter_ctx *ctx)
{
	struct team_port *port = ctx->info->port;

	ctx->data.s32_val = port->priority;
	return 0;
}

static int team_priority_option_set(struct team *team,
				    struct team_gsetter_ctx *ctx)
{
	struct team_port *port = ctx->info->port;
1427
	s32 priority = ctx->data.s32_val;
1428

1429
1430
1431
1432
	if (port->priority == priority)
		return 0;
	port->priority = priority;
	team_queue_override_port_prio_changed(team, port);
1433
1434
1435
1436
1437
1438
1439
1440
1441
	return 0;
}

static int team_queue_id_option_get(struct team *team,
				    struct team_gsetter_ctx *ctx)
{
	struct team_port *port = ctx->info->port;

	ctx->data.u32_val = port->queue_id;
1442
1443
1444
	return 0;
}

1445
1446
1447
1448
static int team_queue_id_option_set(struct team *team,
				    struct team_gsetter_ctx *ctx)
{
	struct team_port *port = ctx->info->port;
1449
	u16 new_queue_id = ctx->data.u32_val;
1450

1451
	if (port->queue_id == new_queue_id)
1452
		return 0;
1453
	if (new_queue_id >= team->dev->real_num_tx_queues)
1454
		return -EINVAL;
1455
	team_queue_override_port_change_queue_id(team, port, new_queue_id);
1456
1457
1458
	return 0;
}

1459
static const struct team_option team_options[] = {
1460
1461
1462
1463
1464
1465
	{
		.name = "mode",
		.type = TEAM_OPTION_TYPE_STRING,
		.getter = team_mode_option_get,
		.setter = team_mode_option_set,
	},
Jiri Pirko's avatar
Jiri Pirko committed
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
	{
		.name = "notify_peers_count",
		.type = TEAM_OPTION_TYPE_U32,
		.getter = team_notify_peers_count_get,
		.setter = team_notify_peers_count_set,
	},
	{
		.name = "notify_peers_interval",
		.type = TEAM_OPTION_TYPE_U32,
		.getter = team_notify_peers_interval_get,
		.setter = team_notify_peers_interval_set,
	},
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
	{
		.name = "mcast_rejoin_count",
		.type = TEAM_OPTION_TYPE_U32,
		.getter = team_mcast_rejoin_count_get,
		.setter = team_mcast_rejoin_count_set,
	},
	{
		.name = "mcast_rejoin_interval",
		.type = TEAM_OPTION_TYPE_U32,
		.getter = team_mcast_rejoin_interval_get,
		.setter = team_mcast_rejoin_interval_set,
	},
1490
1491
1492
1493
1494
1495
1496
	{
		.name = "enabled",
		.type = TEAM_OPTION_TYPE_BOOL,
		.per_port = true,
		.getter = team_port_en_option_get,
		.setter = team_port_en_option_set,
	},
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
	{
		.name = "user_linkup",
		.type = TEAM_OPTION_TYPE_BOOL,
		.per_port = true,
		.getter = team_user_linkup_option_get,
		.setter = team_user_linkup_option_set,
	},
	{
		.name = "user_linkup_enabled",
		.type = TEAM_OPTION_TYPE_BOOL,
		.per_port = true,
		.getter = team_user_linkup_en_option_get,
		.setter = team_user_linkup_en_option_set,
	},