team_mode_roundrobin.c 1.7 KB

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