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