Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 1 | /* |
Jiri Pirko | 0d572e4 | 2012-06-19 05:54:09 +0000 | [diff] [blame] | 2 | * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 3 | * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/netdevice.h> |
| 17 | #include <linux/if_team.h> |
| 18 | |
| 19 | struct rr_priv { |
| 20 | unsigned int sent_packets; |
| 21 | }; |
| 22 | |
| 23 | static struct rr_priv *rr_priv(struct team *team) |
| 24 | { |
| 25 | return (struct rr_priv *) &team->mode_priv; |
| 26 | } |
| 27 | |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 28 | static bool rr_transmit(struct team *team, struct sk_buff *skb) |
| 29 | { |
| 30 | struct team_port *port; |
| 31 | int port_index; |
| 32 | |
Jiri Pirko | 735d381 | 2013-06-10 17:42:25 +0200 | [diff] [blame] | 33 | port_index = team_num_to_port_index(team, |
| 34 | rr_priv(team)->sent_packets++); |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 35 | port = team_get_port_by_index_rcu(team, port_index); |
Jiri Pirko | 76c455d | 2013-06-08 15:00:53 +0200 | [diff] [blame] | 36 | if (unlikely(!port)) |
| 37 | goto drop; |
Jiri Pirko | 753f993 | 2013-03-06 01:31:13 +0000 | [diff] [blame] | 38 | port = team_get_first_port_txable_rcu(team, port); |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 39 | if (unlikely(!port)) |
| 40 | goto drop; |
Jiri Pirko | bd2d083 | 2012-07-17 05:22:36 +0000 | [diff] [blame] | 41 | if (team_dev_queue_xmit(team, port, skb)) |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 42 | return false; |
| 43 | return true; |
| 44 | |
| 45 | drop: |
| 46 | dev_kfree_skb_any(skb); |
| 47 | return false; |
| 48 | } |
| 49 | |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 50 | static const struct team_mode_ops rr_mode_ops = { |
| 51 | .transmit = rr_transmit, |
Jiri Pirko | acbba0d | 2013-03-06 01:31:12 +0000 | [diff] [blame] | 52 | .port_enter = team_modeop_port_enter, |
| 53 | .port_change_dev_addr = team_modeop_port_change_dev_addr, |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Jiri Pirko | 0402788 | 2012-06-19 05:54:03 +0000 | [diff] [blame] | 56 | static const struct team_mode rr_mode = { |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 57 | .kind = "roundrobin", |
| 58 | .owner = THIS_MODULE, |
| 59 | .priv_size = sizeof(struct rr_priv), |
| 60 | .ops = &rr_mode_ops, |
Jiri Pirko | 8fd7285 | 2015-12-03 12:12:13 +0100 | [diff] [blame] | 61 | .lag_tx_type = NETDEV_LAG_TX_TYPE_ROUNDROBIN, |
Jiri Pirko | 3d249d4 | 2011-11-11 22:16:48 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static int __init rr_init_module(void) |
| 65 | { |
| 66 | return team_mode_register(&rr_mode); |
| 67 | } |
| 68 | |
| 69 | static void __exit rr_cleanup_module(void) |
| 70 | { |
| 71 | team_mode_unregister(&rr_mode); |
| 72 | } |
| 73 | |
| 74 | module_init(rr_init_module); |
| 75 | module_exit(rr_cleanup_module); |
| 76 | |
| 77 | MODULE_LICENSE("GPL v2"); |
| 78 | MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>"); |
| 79 | MODULE_DESCRIPTION("Round-robin mode for team"); |
| 80 | MODULE_ALIAS("team-mode-roundrobin"); |