bond_alb.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef _NET_BOND_ALB_H
  6. #define _NET_BOND_ALB_H
  7. #include <linux/if_ether.h>
  8. struct bonding;
  9. struct slave;
  10. #define BOND_ALB_INFO(bond) ((bond)->alb_info)
  11. #define SLAVE_TLB_INFO(slave) ((slave)->tlb_info)
  12. #define ALB_TIMER_TICKS_PER_SEC 10 /* should be a divisor of HZ */
  13. #define BOND_TLB_REBALANCE_INTERVAL 10 /* In seconds, periodic re-balancing.
  14. * Used for division - never set
  15. * to zero !!!
  16. */
  17. #define BOND_ALB_DEFAULT_LP_INTERVAL 1
  18. #define BOND_ALB_LP_INTERVAL(bond) (bond->params.lp_interval) /* In seconds, periodic send of
  19. * learning packets to the switch
  20. */
  21. #define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \
  22. * ALB_TIMER_TICKS_PER_SEC)
  23. #define BOND_ALB_LP_TICKS(bond) (BOND_ALB_LP_INTERVAL(bond) \
  24. * ALB_TIMER_TICKS_PER_SEC)
  25. #define TLB_HASH_TABLE_SIZE 256 /* The size of the clients hash table.
  26. * Note that this value MUST NOT be smaller
  27. * because the key hash table is BYTE wide !
  28. */
  29. #define TLB_NULL_INDEX 0xffffffff
  30. /* rlb defs */
  31. #define RLB_HASH_TABLE_SIZE 256
  32. #define RLB_NULL_INDEX 0xffffffff
  33. #define RLB_UPDATE_DELAY (2*ALB_TIMER_TICKS_PER_SEC) /* 2 seconds */
  34. #define RLB_ARP_BURST_SIZE 2
  35. #define RLB_UPDATE_RETRY 3 /* 3-ticks - must be smaller than the rlb
  36. * rebalance interval (5 min).
  37. */
  38. /* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is
  39. * promiscuous after failover
  40. */
  41. #define RLB_PROMISC_TIMEOUT (10*ALB_TIMER_TICKS_PER_SEC)
  42. struct tlb_client_info {
  43. struct slave *tx_slave; /* A pointer to slave used for transmiting
  44. * packets to a Client that the Hash function
  45. * gave this entry index.
  46. */
  47. u32 tx_bytes; /* Each Client accumulates the BytesTx that
  48. * were transmitted to it, and after each
  49. * CallBack the LoadHistory is divided
  50. * by the balance interval
  51. */
  52. u32 load_history; /* This field contains the amount of Bytes
  53. * that were transmitted to this client by
  54. * the server on the previous balance
  55. * interval in Bps.
  56. */
  57. u32 next; /* The next Hash table entry index, assigned
  58. * to use the same adapter for transmit.
  59. */
  60. u32 prev; /* The previous Hash table entry index,
  61. * assigned to use the same
  62. */
  63. };
  64. /* -------------------------------------------------------------------------
  65. * struct rlb_client_info contains all info related to a specific rx client
  66. * connection. This is the Clients Hash Table entry struct.
  67. * Note that this is not a proper hash table; if a new client's IP address
  68. * hash collides with an existing client entry, the old entry is replaced.
  69. *
  70. * There is a linked list (linked by the used_next and used_prev members)
  71. * linking all the used entries of the hash table. This allows updating
  72. * all the clients without walking over all the unused elements of the table.
  73. *
  74. * There are also linked lists of entries with identical hash(ip_src). These
  75. * allow cleaning up the table from ip_src<->mac_src associations that have
  76. * become outdated and would cause sending out invalid ARP updates to the
  77. * network. These are linked by the (src_next and src_prev members).
  78. * -------------------------------------------------------------------------
  79. */
  80. struct rlb_client_info {
  81. __be32 ip_src; /* the server IP address */
  82. __be32 ip_dst; /* the client IP address */
  83. u8 mac_src[ETH_ALEN]; /* the server MAC address */
  84. u8 mac_dst[ETH_ALEN]; /* the client MAC address */
  85. /* list of used hash table entries, starting at rx_hashtbl_used_head */
  86. u32 used_next;
  87. u32 used_prev;
  88. /* ip_src based hashing */
  89. u32 src_next; /* next entry with same hash(ip_src) */
  90. u32 src_prev; /* prev entry with same hash(ip_src) */
  91. u32 src_first; /* first entry with hash(ip_src) == this entry's index */
  92. u8 assigned; /* checking whether this entry is assigned */
  93. u8 ntt; /* flag - need to transmit client info */
  94. struct slave *slave; /* the slave assigned to this client */
  95. unsigned short vlan_id; /* VLAN tag associated with IP address */
  96. };
  97. struct tlb_slave_info {
  98. u32 head; /* Index to the head of the bi-directional clients
  99. * hash table entries list. The entries in the list
  100. * are the entries that were assigned to use this
  101. * slave for transmit.
  102. */
  103. u32 load; /* Each slave sums the loadHistory of all clients
  104. * assigned to it
  105. */
  106. };
  107. struct alb_bond_info {
  108. struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */
  109. u32 unbalanced_load;
  110. atomic_t tx_rebalance_counter;
  111. int lp_counter;
  112. /* -------- rlb parameters -------- */
  113. int rlb_enabled;
  114. struct rlb_client_info *rx_hashtbl; /* Receive hash table */
  115. u32 rx_hashtbl_used_head;
  116. u8 rx_ntt; /* flag - need to transmit
  117. * to all rx clients
  118. */
  119. struct slave *rx_slave;/* last slave to xmit from */
  120. u8 primary_is_promisc; /* boolean */
  121. u32 rlb_promisc_timeout_counter;/* counts primary
  122. * promiscuity time
  123. */
  124. u32 rlb_update_delay_counter;
  125. u32 rlb_update_retry_counter;/* counter of retries
  126. * of client update
  127. */
  128. u8 rlb_rebalance; /* flag - indicates that the
  129. * rx traffic should be
  130. * rebalanced
  131. */
  132. };
  133. int bond_alb_initialize(struct bonding *bond, int rlb_enabled);
  134. void bond_alb_deinitialize(struct bonding *bond);
  135. int bond_alb_init_slave(struct bonding *bond, struct slave *slave);
  136. void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave);
  137. void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link);
  138. void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);
  139. netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
  140. netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
  141. struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
  142. struct sk_buff *skb);
  143. struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
  144. struct sk_buff *skb);
  145. void bond_alb_monitor(struct work_struct *);
  146. int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);
  147. void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id);
  148. #endif /* _NET_BOND_ALB_H */