11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 51da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 61da177e4SLinus Torvalds * Free Software Foundation; either version 2 of the License, or 71da177e4SLinus Torvalds * (at your option) any later version. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 101da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 111da177e4SLinus Torvalds * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121da177e4SLinus Torvalds * for more details. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License along 15adf8d3ffSJeff Kirsher * with this program; if not, see <http://www.gnu.org/licenses/>. 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * The full GNU General Public License is included in this distribution in the 181da177e4SLinus Torvalds * file called LICENSE. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 22*1ef8019bSDavid S. Miller #ifndef _NET_BOND_ALB_H 23*1ef8019bSDavid S. Miller #define _NET_BOND_ALB_H 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <linux/if_ether.h> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds struct bonding; 281da177e4SLinus Torvalds struct slave; 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds #define BOND_ALB_INFO(bond) ((bond)->alb_info) 311da177e4SLinus Torvalds #define SLAVE_TLB_INFO(slave) ((slave)->tlb_info) 321da177e4SLinus Torvalds 33411204a5STaku Izumi #define ALB_TIMER_TICKS_PER_SEC 10 /* should be a divisor of HZ */ 34411204a5STaku Izumi #define BOND_TLB_REBALANCE_INTERVAL 10 /* In seconds, periodic re-balancing. 35411204a5STaku Izumi * Used for division - never set 36411204a5STaku Izumi * to zero !!! 37411204a5STaku Izumi */ 387eacd038SNeil Horman #define BOND_ALB_DEFAULT_LP_INTERVAL 1 397eacd038SNeil Horman #define BOND_ALB_LP_INTERVAL(bond) (bond->params.lp_interval) /* In seconds, periodic send of 40411204a5STaku Izumi * learning packets to the switch 41411204a5STaku Izumi */ 42411204a5STaku Izumi 43411204a5STaku Izumi #define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \ 44411204a5STaku Izumi * ALB_TIMER_TICKS_PER_SEC) 45411204a5STaku Izumi 467eacd038SNeil Horman #define BOND_ALB_LP_TICKS(bond) (BOND_ALB_LP_INTERVAL(bond) \ 47411204a5STaku Izumi * ALB_TIMER_TICKS_PER_SEC) 48411204a5STaku Izumi 49411204a5STaku Izumi #define TLB_HASH_TABLE_SIZE 256 /* The size of the clients hash table. 50411204a5STaku Izumi * Note that this value MUST NOT be smaller 51411204a5STaku Izumi * because the key hash table is BYTE wide ! 52411204a5STaku Izumi */ 53411204a5STaku Izumi 54411204a5STaku Izumi 55411204a5STaku Izumi #define TLB_NULL_INDEX 0xffffffff 56411204a5STaku Izumi 57411204a5STaku Izumi /* rlb defs */ 58411204a5STaku Izumi #define RLB_HASH_TABLE_SIZE 256 59411204a5STaku Izumi #define RLB_NULL_INDEX 0xffffffff 60411204a5STaku Izumi #define RLB_UPDATE_DELAY (2*ALB_TIMER_TICKS_PER_SEC) /* 2 seconds */ 61411204a5STaku Izumi #define RLB_ARP_BURST_SIZE 2 62411204a5STaku Izumi #define RLB_UPDATE_RETRY 3 /* 3-ticks - must be smaller than the rlb 63411204a5STaku Izumi * rebalance interval (5 min). 64411204a5STaku Izumi */ 65411204a5STaku Izumi /* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is 66411204a5STaku Izumi * promiscuous after failover 67411204a5STaku Izumi */ 68411204a5STaku Izumi #define RLB_PROMISC_TIMEOUT (10*ALB_TIMER_TICKS_PER_SEC) 69411204a5STaku Izumi 70411204a5STaku Izumi 711da177e4SLinus Torvalds struct tlb_client_info { 721da177e4SLinus Torvalds struct slave *tx_slave; /* A pointer to slave used for transmiting 731da177e4SLinus Torvalds * packets to a Client that the Hash function 741da177e4SLinus Torvalds * gave this entry index. 751da177e4SLinus Torvalds */ 765e8996e7SPeter Pan(潘卫平) u32 tx_bytes; /* Each Client accumulates the BytesTx that 779814290aSPeter Pan(潘卫平) * were transmitted to it, and after each 7825985edcSLucas De Marchi * CallBack the LoadHistory is divided 791da177e4SLinus Torvalds * by the balance interval 801da177e4SLinus Torvalds */ 811da177e4SLinus Torvalds u32 load_history; /* This field contains the amount of Bytes 821da177e4SLinus Torvalds * that were transmitted to this client by 831da177e4SLinus Torvalds * the server on the previous balance 841da177e4SLinus Torvalds * interval in Bps. 851da177e4SLinus Torvalds */ 861da177e4SLinus Torvalds u32 next; /* The next Hash table entry index, assigned 871da177e4SLinus Torvalds * to use the same adapter for transmit. 881da177e4SLinus Torvalds */ 891da177e4SLinus Torvalds u32 prev; /* The previous Hash table entry index, 901da177e4SLinus Torvalds * assigned to use the same 911da177e4SLinus Torvalds */ 921da177e4SLinus Torvalds }; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds /* ------------------------------------------------------------------------- 951da177e4SLinus Torvalds * struct rlb_client_info contains all info related to a specific rx client 96e53665c6SJiri Bohac * connection. This is the Clients Hash Table entry struct. 97e53665c6SJiri Bohac * Note that this is not a proper hash table; if a new client's IP address 98e53665c6SJiri Bohac * hash collides with an existing client entry, the old entry is replaced. 99e53665c6SJiri Bohac * 100e53665c6SJiri Bohac * There is a linked list (linked by the used_next and used_prev members) 101e53665c6SJiri Bohac * linking all the used entries of the hash table. This allows updating 102e53665c6SJiri Bohac * all the clients without walking over all the unused elements of the table. 103e53665c6SJiri Bohac * 104e53665c6SJiri Bohac * There are also linked lists of entries with identical hash(ip_src). These 105e53665c6SJiri Bohac * allow cleaning up the table from ip_src<->mac_src associations that have 106e53665c6SJiri Bohac * become outdated and would cause sending out invalid ARP updates to the 107e53665c6SJiri Bohac * network. These are linked by the (src_next and src_prev members). 1081da177e4SLinus Torvalds * ------------------------------------------------------------------------- 1091da177e4SLinus Torvalds */ 1101da177e4SLinus Torvalds struct rlb_client_info { 111d3bb52b0SAl Viro __be32 ip_src; /* the server IP address */ 112d3bb52b0SAl Viro __be32 ip_dst; /* the client IP address */ 113e53665c6SJiri Bohac u8 mac_src[ETH_ALEN]; /* the server MAC address */ 1141da177e4SLinus Torvalds u8 mac_dst[ETH_ALEN]; /* the client MAC address */ 115e53665c6SJiri Bohac 116e53665c6SJiri Bohac /* list of used hash table entries, starting at rx_hashtbl_used_head */ 117e53665c6SJiri Bohac u32 used_next; 118e53665c6SJiri Bohac u32 used_prev; 119e53665c6SJiri Bohac 120e53665c6SJiri Bohac /* ip_src based hashing */ 121e53665c6SJiri Bohac u32 src_next; /* next entry with same hash(ip_src) */ 122e53665c6SJiri Bohac u32 src_prev; /* prev entry with same hash(ip_src) */ 123e53665c6SJiri Bohac u32 src_first; /* first entry with hash(ip_src) == this entry's index */ 124e53665c6SJiri Bohac 1251da177e4SLinus Torvalds u8 assigned; /* checking whether this entry is assigned */ 1261da177e4SLinus Torvalds u8 ntt; /* flag - need to transmit client info */ 1271da177e4SLinus Torvalds struct slave *slave; /* the slave assigned to this client */ 1281da177e4SLinus Torvalds unsigned short vlan_id; /* VLAN tag associated with IP address */ 1291da177e4SLinus Torvalds }; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds struct tlb_slave_info { 1321da177e4SLinus Torvalds u32 head; /* Index to the head of the bi-directional clients 1331da177e4SLinus Torvalds * hash table entries list. The entries in the list 1341da177e4SLinus Torvalds * are the entries that were assigned to use this 1351da177e4SLinus Torvalds * slave for transmit. 1361da177e4SLinus Torvalds */ 1371da177e4SLinus Torvalds u32 load; /* Each slave sums the loadHistory of all clients 1381da177e4SLinus Torvalds * assigned to it 1391da177e4SLinus Torvalds */ 1401da177e4SLinus Torvalds }; 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds struct alb_bond_info { 1431da177e4SLinus Torvalds struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */ 1441da177e4SLinus Torvalds u32 unbalanced_load; 1451da177e4SLinus Torvalds int tx_rebalance_counter; 1461da177e4SLinus Torvalds int lp_counter; 1471da177e4SLinus Torvalds /* -------- rlb parameters -------- */ 1481da177e4SLinus Torvalds int rlb_enabled; 1491da177e4SLinus Torvalds struct rlb_client_info *rx_hashtbl; /* Receive hash table */ 150e53665c6SJiri Bohac u32 rx_hashtbl_used_head; 1511da177e4SLinus Torvalds u8 rx_ntt; /* flag - need to transmit 1521da177e4SLinus Torvalds * to all rx clients 1531da177e4SLinus Torvalds */ 1546475ae4cSVeaceslav Falico struct slave *rx_slave;/* last slave to xmit from */ 1551da177e4SLinus Torvalds u8 primary_is_promisc; /* boolean */ 1561da177e4SLinus Torvalds u32 rlb_promisc_timeout_counter;/* counts primary 1571da177e4SLinus Torvalds * promiscuity time 1581da177e4SLinus Torvalds */ 1591da177e4SLinus Torvalds u32 rlb_update_delay_counter; 1601da177e4SLinus Torvalds u32 rlb_update_retry_counter;/* counter of retries 1611da177e4SLinus Torvalds * of client update 1621da177e4SLinus Torvalds */ 1631da177e4SLinus Torvalds u8 rlb_rebalance; /* flag - indicates that the 1641da177e4SLinus Torvalds * rx traffic should be 1651da177e4SLinus Torvalds * rebalanced 1661da177e4SLinus Torvalds */ 1671da177e4SLinus Torvalds }; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds int bond_alb_initialize(struct bonding *bond, int rlb_enabled); 1701da177e4SLinus Torvalds void bond_alb_deinitialize(struct bonding *bond); 1711da177e4SLinus Torvalds int bond_alb_init_slave(struct bonding *bond, struct slave *slave); 1721da177e4SLinus Torvalds void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave); 1731da177e4SLinus Torvalds void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link); 1741da177e4SLinus Torvalds void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave); 1751da177e4SLinus Torvalds int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev); 176f05b42eaSMahesh Bandewar int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev); 1771b76b316SJay Vosburgh void bond_alb_monitor(struct work_struct *); 1781da177e4SLinus Torvalds int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr); 1791da177e4SLinus Torvalds void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id); 180*1ef8019bSDavid S. Miller #endif /* _NET_BOND_ALB_H */ 1811da177e4SLinus Torvalds 182