xref: /openbmc/linux/include/net/bond_alb.h (revision 1ef8019b)
11ef8019bSDavid S. Miller /*
21ef8019bSDavid S. Miller  * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
31ef8019bSDavid S. Miller  *
41ef8019bSDavid S. Miller  * This program is free software; you can redistribute it and/or modify it
51ef8019bSDavid S. Miller  * under the terms of the GNU General Public License as published by the
61ef8019bSDavid S. Miller  * Free Software Foundation; either version 2 of the License, or
71ef8019bSDavid S. Miller  * (at your option) any later version.
81ef8019bSDavid S. Miller  *
91ef8019bSDavid S. Miller  * This program is distributed in the hope that it will be useful, but
101ef8019bSDavid S. Miller  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
111ef8019bSDavid S. Miller  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121ef8019bSDavid S. Miller  * for more details.
131ef8019bSDavid S. Miller  *
141ef8019bSDavid S. Miller  * You should have received a copy of the GNU General Public License along
151ef8019bSDavid S. Miller  * with this program; if not, see <http://www.gnu.org/licenses/>.
161ef8019bSDavid S. Miller  *
171ef8019bSDavid S. Miller  * The full GNU General Public License is included in this distribution in the
181ef8019bSDavid S. Miller  * file called LICENSE.
191ef8019bSDavid S. Miller  *
201ef8019bSDavid S. Miller  */
211ef8019bSDavid S. Miller 
221ef8019bSDavid S. Miller #ifndef _NET_BOND_ALB_H
231ef8019bSDavid S. Miller #define _NET_BOND_ALB_H
241ef8019bSDavid S. Miller 
251ef8019bSDavid S. Miller #include <linux/if_ether.h>
261ef8019bSDavid S. Miller 
271ef8019bSDavid S. Miller struct bonding;
281ef8019bSDavid S. Miller struct slave;
291ef8019bSDavid S. Miller 
301ef8019bSDavid S. Miller #define BOND_ALB_INFO(bond)   ((bond)->alb_info)
311ef8019bSDavid S. Miller #define SLAVE_TLB_INFO(slave) ((slave)->tlb_info)
321ef8019bSDavid S. Miller 
331ef8019bSDavid S. Miller #define ALB_TIMER_TICKS_PER_SEC	    10	/* should be a divisor of HZ */
341ef8019bSDavid S. Miller #define BOND_TLB_REBALANCE_INTERVAL 10	/* In seconds, periodic re-balancing.
351ef8019bSDavid S. Miller 					 * Used for division - never set
361ef8019bSDavid S. Miller 					 * to zero !!!
371ef8019bSDavid S. Miller 					 */
381ef8019bSDavid S. Miller #define BOND_ALB_DEFAULT_LP_INTERVAL 1
391ef8019bSDavid S. Miller #define BOND_ALB_LP_INTERVAL(bond) (bond->params.lp_interval)	/* In seconds, periodic send of
401ef8019bSDavid S. Miller 								 * learning packets to the switch
411ef8019bSDavid S. Miller 								 */
421ef8019bSDavid S. Miller 
431ef8019bSDavid S. Miller #define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \
441ef8019bSDavid S. Miller 				  * ALB_TIMER_TICKS_PER_SEC)
451ef8019bSDavid S. Miller 
461ef8019bSDavid S. Miller #define BOND_ALB_LP_TICKS(bond) (BOND_ALB_LP_INTERVAL(bond) \
471ef8019bSDavid S. Miller 			   * ALB_TIMER_TICKS_PER_SEC)
481ef8019bSDavid S. Miller 
491ef8019bSDavid S. Miller #define TLB_HASH_TABLE_SIZE 256	/* The size of the clients hash table.
501ef8019bSDavid S. Miller 				 * Note that this value MUST NOT be smaller
511ef8019bSDavid S. Miller 				 * because the key hash table is BYTE wide !
521ef8019bSDavid S. Miller 				 */
531ef8019bSDavid S. Miller 
541ef8019bSDavid S. Miller 
551ef8019bSDavid S. Miller #define TLB_NULL_INDEX		0xffffffff
561ef8019bSDavid S. Miller 
571ef8019bSDavid S. Miller /* rlb defs */
581ef8019bSDavid S. Miller #define RLB_HASH_TABLE_SIZE	256
591ef8019bSDavid S. Miller #define RLB_NULL_INDEX		0xffffffff
601ef8019bSDavid S. Miller #define RLB_UPDATE_DELAY	(2*ALB_TIMER_TICKS_PER_SEC) /* 2 seconds */
611ef8019bSDavid S. Miller #define RLB_ARP_BURST_SIZE	2
621ef8019bSDavid S. Miller #define RLB_UPDATE_RETRY	3 /* 3-ticks - must be smaller than the rlb
631ef8019bSDavid S. Miller 				   * rebalance interval (5 min).
641ef8019bSDavid S. Miller 				   */
651ef8019bSDavid S. Miller /* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is
661ef8019bSDavid S. Miller  * promiscuous after failover
671ef8019bSDavid S. Miller  */
681ef8019bSDavid S. Miller #define RLB_PROMISC_TIMEOUT	(10*ALB_TIMER_TICKS_PER_SEC)
691ef8019bSDavid S. Miller 
701ef8019bSDavid S. Miller 
711ef8019bSDavid S. Miller struct tlb_client_info {
721ef8019bSDavid S. Miller 	struct slave *tx_slave;	/* A pointer to slave used for transmiting
731ef8019bSDavid S. Miller 				 * packets to a Client that the Hash function
741ef8019bSDavid S. Miller 				 * gave this entry index.
751ef8019bSDavid S. Miller 				 */
761ef8019bSDavid S. Miller 	u32 tx_bytes;		/* Each Client accumulates the BytesTx that
771ef8019bSDavid S. Miller 				 * were transmitted to it, and after each
781ef8019bSDavid S. Miller 				 * CallBack the LoadHistory is divided
791ef8019bSDavid S. Miller 				 * by the balance interval
801ef8019bSDavid S. Miller 				 */
811ef8019bSDavid S. Miller 	u32 load_history;	/* This field contains the amount of Bytes
821ef8019bSDavid S. Miller 				 * that were transmitted to this client by
831ef8019bSDavid S. Miller 				 * the server on the previous balance
841ef8019bSDavid S. Miller 				 * interval in Bps.
851ef8019bSDavid S. Miller 				 */
861ef8019bSDavid S. Miller 	u32 next;		/* The next Hash table entry index, assigned
871ef8019bSDavid S. Miller 				 * to use the same adapter for transmit.
881ef8019bSDavid S. Miller 				 */
891ef8019bSDavid S. Miller 	u32 prev;		/* The previous Hash table entry index,
901ef8019bSDavid S. Miller 				 * assigned to use the same
911ef8019bSDavid S. Miller 				 */
921ef8019bSDavid S. Miller };
931ef8019bSDavid S. Miller 
941ef8019bSDavid S. Miller /* -------------------------------------------------------------------------
951ef8019bSDavid S. Miller  * struct rlb_client_info contains all info related to a specific rx client
961ef8019bSDavid S. Miller  * connection. This is the Clients Hash Table entry struct.
971ef8019bSDavid S. Miller  * Note that this is not a proper hash table; if a new client's IP address
981ef8019bSDavid S. Miller  * hash collides with an existing client entry, the old entry is replaced.
991ef8019bSDavid S. Miller  *
1001ef8019bSDavid S. Miller  * There is a linked list (linked by the used_next and used_prev members)
1011ef8019bSDavid S. Miller  * linking all the used entries of the hash table. This allows updating
1021ef8019bSDavid S. Miller  * all the clients without walking over all the unused elements of the table.
1031ef8019bSDavid S. Miller  *
1041ef8019bSDavid S. Miller  * There are also linked lists of entries with identical hash(ip_src). These
1051ef8019bSDavid S. Miller  * allow cleaning up the table from ip_src<->mac_src associations that have
1061ef8019bSDavid S. Miller  * become outdated and would cause sending out invalid ARP updates to the
1071ef8019bSDavid S. Miller  * network. These are linked by the (src_next and src_prev members).
1081ef8019bSDavid S. Miller  * -------------------------------------------------------------------------
1091ef8019bSDavid S. Miller  */
1101ef8019bSDavid S. Miller struct rlb_client_info {
1111ef8019bSDavid S. Miller 	__be32 ip_src;		/* the server IP address */
1121ef8019bSDavid S. Miller 	__be32 ip_dst;		/* the client IP address */
1131ef8019bSDavid S. Miller 	u8  mac_src[ETH_ALEN];	/* the server MAC address */
1141ef8019bSDavid S. Miller 	u8  mac_dst[ETH_ALEN];	/* the client MAC address */
1151ef8019bSDavid S. Miller 
1161ef8019bSDavid S. Miller 	/* list of used hash table entries, starting at rx_hashtbl_used_head */
1171ef8019bSDavid S. Miller 	u32 used_next;
1181ef8019bSDavid S. Miller 	u32 used_prev;
1191ef8019bSDavid S. Miller 
1201ef8019bSDavid S. Miller 	/* ip_src based hashing */
1211ef8019bSDavid S. Miller 	u32 src_next;	/* next entry with same hash(ip_src) */
1221ef8019bSDavid S. Miller 	u32 src_prev;	/* prev entry with same hash(ip_src) */
1231ef8019bSDavid S. Miller 	u32 src_first;	/* first entry with hash(ip_src) == this entry's index */
1241ef8019bSDavid S. Miller 
1251ef8019bSDavid S. Miller 	u8  assigned;		/* checking whether this entry is assigned */
1261ef8019bSDavid S. Miller 	u8  ntt;		/* flag - need to transmit client info */
1271ef8019bSDavid S. Miller 	struct slave *slave;	/* the slave assigned to this client */
1281ef8019bSDavid S. Miller 	unsigned short vlan_id;	/* VLAN tag associated with IP address */
1291ef8019bSDavid S. Miller };
1301ef8019bSDavid S. Miller 
1311ef8019bSDavid S. Miller struct tlb_slave_info {
1321ef8019bSDavid S. Miller 	u32 head;	/* Index to the head of the bi-directional clients
1331ef8019bSDavid S. Miller 			 * hash table entries list. The entries in the list
1341ef8019bSDavid S. Miller 			 * are the entries that were assigned to use this
1351ef8019bSDavid S. Miller 			 * slave for transmit.
1361ef8019bSDavid S. Miller 			 */
1371ef8019bSDavid S. Miller 	u32 load;	/* Each slave sums the loadHistory of all clients
1381ef8019bSDavid S. Miller 			 * assigned to it
1391ef8019bSDavid S. Miller 			 */
1401ef8019bSDavid S. Miller };
1411ef8019bSDavid S. Miller 
1421ef8019bSDavid S. Miller struct alb_bond_info {
1431ef8019bSDavid S. Miller 	struct tlb_client_info	*tx_hashtbl; /* Dynamically allocated */
1441ef8019bSDavid S. Miller 	u32			unbalanced_load;
1451ef8019bSDavid S. Miller 	int			tx_rebalance_counter;
1461ef8019bSDavid S. Miller 	int			lp_counter;
1471ef8019bSDavid S. Miller 	/* -------- rlb parameters -------- */
1481ef8019bSDavid S. Miller 	int rlb_enabled;
1491ef8019bSDavid S. Miller 	struct rlb_client_info	*rx_hashtbl;	/* Receive hash table */
1501ef8019bSDavid S. Miller 	u32			rx_hashtbl_used_head;
1511ef8019bSDavid S. Miller 	u8			rx_ntt;	/* flag - need to transmit
1521ef8019bSDavid S. Miller 					 * to all rx clients
1531ef8019bSDavid S. Miller 					 */
1541ef8019bSDavid S. Miller 	struct slave		*rx_slave;/* last slave to xmit from */
1551ef8019bSDavid S. Miller 	u8			primary_is_promisc;	   /* boolean */
1561ef8019bSDavid S. Miller 	u32			rlb_promisc_timeout_counter;/* counts primary
1571ef8019bSDavid S. Miller 							     * promiscuity time
1581ef8019bSDavid S. Miller 							     */
1591ef8019bSDavid S. Miller 	u32			rlb_update_delay_counter;
1601ef8019bSDavid S. Miller 	u32			rlb_update_retry_counter;/* counter of retries
1611ef8019bSDavid S. Miller 							  * of client update
1621ef8019bSDavid S. Miller 							  */
1631ef8019bSDavid S. Miller 	u8			rlb_rebalance;	/* flag - indicates that the
1641ef8019bSDavid S. Miller 						 * rx traffic should be
1651ef8019bSDavid S. Miller 						 * rebalanced
1661ef8019bSDavid S. Miller 						 */
1671ef8019bSDavid S. Miller };
1681ef8019bSDavid S. Miller 
1691ef8019bSDavid S. Miller int bond_alb_initialize(struct bonding *bond, int rlb_enabled);
1701ef8019bSDavid S. Miller void bond_alb_deinitialize(struct bonding *bond);
1711ef8019bSDavid S. Miller int bond_alb_init_slave(struct bonding *bond, struct slave *slave);
1721ef8019bSDavid S. Miller void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave);
1731ef8019bSDavid S. Miller void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link);
1741ef8019bSDavid S. Miller void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);
1751ef8019bSDavid S. Miller int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
1761ef8019bSDavid S. Miller int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
1771ef8019bSDavid S. Miller void bond_alb_monitor(struct work_struct *);
1781ef8019bSDavid S. Miller int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);
1791ef8019bSDavid S. Miller void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id);
1801ef8019bSDavid S. Miller #endif /* _NET_BOND_ALB_H */
1811ef8019bSDavid S. Miller 
182