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