1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/errno.h>
12 #include <linux/netdevice.h>
13 #include <linux/if_team.h>
16 unsigned int sent_packets;
19 static struct rr_priv *rr_priv(struct team *team)
21 return (struct rr_priv *) &team->mode_priv;
24 static bool rr_transmit(struct team *team, struct sk_buff *skb)
26 struct team_port *port;
29 port_index = team_num_to_port_index(team,
30 rr_priv(team)->sent_packets++);
31 port = team_get_port_by_index_rcu(team, port_index);
34 port = team_get_first_port_txable_rcu(team, port);
37 if (team_dev_queue_xmit(team, port, skb))
42 dev_kfree_skb_any(skb);
46 static const struct team_mode_ops rr_mode_ops = {
47 .transmit = rr_transmit,
48 .port_enter = team_modeop_port_enter,
49 .port_change_dev_addr = team_modeop_port_change_dev_addr,
52 static const struct team_mode rr_mode = {
55 .priv_size = sizeof(struct rr_priv),
57 .lag_tx_type = NETDEV_LAG_TX_TYPE_ROUNDROBIN,
60 static int __init rr_init_module(void)
62 return team_mode_register(&rr_mode);
65 static void __exit rr_cleanup_module(void)
67 team_mode_unregister(&rr_mode);
70 module_init(rr_init_module);
71 module_exit(rr_cleanup_module);
73 MODULE_LICENSE("GPL v2");
75 MODULE_DESCRIPTION("Round-robin mode for team");
76 MODULE_ALIAS_TEAM_MODE("roundrobin");