blob: 472623f8ce3d1c3cb20efe4403e50341b6cbc86e [file] [log] [blame]
Jiri Pirko3d249d42011-11-11 22:16:48 +00001/*
Jiri Pirko0d572e42012-06-19 05:54:09 +00002 * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team
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/errno.h>
16#include <linux/netdevice.h>
17#include <linux/if_team.h>
18
19struct rr_priv {
20 unsigned int sent_packets;
21};
22
23static struct rr_priv *rr_priv(struct team *team)
24{
25 return (struct rr_priv *) &team->mode_priv;
26}
27
Jiri Pirko3d249d42011-11-11 22:16:48 +000028static bool rr_transmit(struct team *team, struct sk_buff *skb)
29{
30 struct team_port *port;
31 int port_index;
32
Jiri Pirko19a0b582012-04-20 04:42:05 +000033 port_index = rr_priv(team)->sent_packets++ % team->en_port_count;
Jiri Pirko3d249d42011-11-11 22:16:48 +000034 port = team_get_port_by_index_rcu(team, port_index);
Jiri Pirko76c455d2013-06-08 15:00:53 +020035 if (unlikely(!port))
36 goto drop;
Jiri Pirko753f9932013-03-06 01:31:13 +000037 port = team_get_first_port_txable_rcu(team, port);
Jiri Pirko3d249d42011-11-11 22:16:48 +000038 if (unlikely(!port))
39 goto drop;
Jiri Pirkobd2d0832012-07-17 05:22:36 +000040 if (team_dev_queue_xmit(team, port, skb))
Jiri Pirko3d249d42011-11-11 22:16:48 +000041 return false;
42 return true;
43
44drop:
45 dev_kfree_skb_any(skb);
46 return false;
47}
48
Jiri Pirko3d249d42011-11-11 22:16:48 +000049static const struct team_mode_ops rr_mode_ops = {
50 .transmit = rr_transmit,
Jiri Pirkoacbba0d2013-03-06 01:31:12 +000051 .port_enter = team_modeop_port_enter,
52 .port_change_dev_addr = team_modeop_port_change_dev_addr,
Jiri Pirko3d249d42011-11-11 22:16:48 +000053};
54
Jiri Pirko04027882012-06-19 05:54:03 +000055static const struct team_mode rr_mode = {
Jiri Pirko3d249d42011-11-11 22:16:48 +000056 .kind = "roundrobin",
57 .owner = THIS_MODULE,
58 .priv_size = sizeof(struct rr_priv),
59 .ops = &rr_mode_ops,
60};
61
62static int __init rr_init_module(void)
63{
64 return team_mode_register(&rr_mode);
65}
66
67static void __exit rr_cleanup_module(void)
68{
69 team_mode_unregister(&rr_mode);
70}
71
72module_init(rr_init_module);
73module_exit(rr_cleanup_module);
74
75MODULE_LICENSE("GPL v2");
76MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
77MODULE_DESCRIPTION("Round-robin mode for team");
78MODULE_ALIAS("team-mode-roundrobin");