team_mode_roundrobin.c 1.7 KB

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