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