Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team
 4 * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
 5 */
 6
 7#include <linux/kernel.h>
 8#include <linux/types.h>
 9#include <linux/module.h>
10#include <linux/init.h>
 
11#include <linux/netdevice.h>
12#include <linux/if_team.h>
13
14struct rr_priv {
15	unsigned int sent_packets;
16};
17
18static struct rr_priv *rr_priv(struct team *team)
19{
20	return (struct rr_priv *) &team->mode_priv;
21}
22
23static bool rr_transmit(struct team *team, struct sk_buff *skb)
24{
25	struct team_port *port;
26	int port_index;
27
28	port_index = team_num_to_port_index(team,
29					    rr_priv(team)->sent_packets++);
30	port = team_get_port_by_index_rcu(team, port_index);
31	if (unlikely(!port))
32		goto drop;
33	port = team_get_first_port_txable_rcu(team, port);
34	if (unlikely(!port))
35		goto drop;
36	if (team_dev_queue_xmit(team, port, skb))
37		return false;
38	return true;
39
40drop:
41	dev_kfree_skb_any(skb);
42	return false;
43}
44
45static const struct team_mode_ops rr_mode_ops = {
46	.transmit		= rr_transmit,
47	.port_enter		= team_modeop_port_enter,
48	.port_change_dev_addr	= team_modeop_port_change_dev_addr,
49};
50
51static const struct team_mode rr_mode = {
52	.kind		= "roundrobin",
53	.owner		= THIS_MODULE,
54	.priv_size	= sizeof(struct rr_priv),
55	.ops		= &rr_mode_ops,
56	.lag_tx_type	= NETDEV_LAG_TX_TYPE_ROUNDROBIN,
57};
58
59static int __init rr_init_module(void)
60{
61	return team_mode_register(&rr_mode);
62}
63
64static void __exit rr_cleanup_module(void)
65{
66	team_mode_unregister(&rr_mode);
67}
68
69module_init(rr_init_module);
70module_exit(rr_cleanup_module);
71
72MODULE_LICENSE("GPL v2");
73MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
74MODULE_DESCRIPTION("Round-robin mode for team");
75MODULE_ALIAS_TEAM_MODE("roundrobin");
v5.4
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * drivers/net/team/team_mode_roundrobin.c - Round-robin mode for team
 4 * Copyright (c) 2011 Jiri Pirko <jpirko@redhat.com>
 5 */
 6
 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>
14
15struct rr_priv {
16	unsigned int sent_packets;
17};
18
19static struct rr_priv *rr_priv(struct team *team)
20{
21	return (struct rr_priv *) &team->mode_priv;
22}
23
24static bool rr_transmit(struct team *team, struct sk_buff *skb)
25{
26	struct team_port *port;
27	int port_index;
28
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);
32	if (unlikely(!port))
33		goto drop;
34	port = team_get_first_port_txable_rcu(team, port);
35	if (unlikely(!port))
36		goto drop;
37	if (team_dev_queue_xmit(team, port, skb))
38		return false;
39	return true;
40
41drop:
42	dev_kfree_skb_any(skb);
43	return false;
44}
45
46static 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,
50};
51
52static const struct team_mode rr_mode = {
53	.kind		= "roundrobin",
54	.owner		= THIS_MODULE,
55	.priv_size	= sizeof(struct rr_priv),
56	.ops		= &rr_mode_ops,
57	.lag_tx_type	= NETDEV_LAG_TX_TYPE_ROUNDROBIN,
58};
59
60static int __init rr_init_module(void)
61{
62	return team_mode_register(&rr_mode);
63}
64
65static void __exit rr_cleanup_module(void)
66{
67	team_mode_unregister(&rr_mode);
68}
69
70module_init(rr_init_module);
71module_exit(rr_cleanup_module);
72
73MODULE_LICENSE("GPL v2");
74MODULE_AUTHOR("Jiri Pirko <jpirko@redhat.com>");
75MODULE_DESCRIPTION("Round-robin mode for team");
76MODULE_ALIAS_TEAM_MODE("roundrobin");