/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.3*/45#ifndef _NET_BOND_ALB_H6#define _NET_BOND_ALB_H78#include <linux/if_ether.h>910struct bonding;11struct slave;1213#define BOND_ALB_INFO(bond) ((bond)->alb_info)14#define SLAVE_TLB_INFO(slave) ((slave)->tlb_info)1516#define ALB_TIMER_TICKS_PER_SEC 10 /* should be a divisor of HZ */17#define BOND_TLB_REBALANCE_INTERVAL 10 /* In seconds, periodic re-balancing.18* Used for division - never set19* to zero !!!20*/21#define BOND_ALB_DEFAULT_LP_INTERVAL 122#define BOND_ALB_LP_INTERVAL(bond) (bond->params.lp_interval) /* In seconds, periodic send of23* learning packets to the switch24*/2526#define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \27* ALB_TIMER_TICKS_PER_SEC)2829#define BOND_ALB_LP_TICKS(bond) (BOND_ALB_LP_INTERVAL(bond) \30* ALB_TIMER_TICKS_PER_SEC)3132#define TLB_HASH_TABLE_SIZE 256 /* The size of the clients hash table.33* Note that this value MUST NOT be smaller34* because the key hash table is BYTE wide !35*/363738#define TLB_NULL_INDEX 0xffffffff3940/* rlb defs */41#define RLB_HASH_TABLE_SIZE 25642#define RLB_NULL_INDEX 0xffffffff43#define RLB_UPDATE_DELAY (2*ALB_TIMER_TICKS_PER_SEC) /* 2 seconds */44#define RLB_ARP_BURST_SIZE 245#define RLB_UPDATE_RETRY 3 /* 3-ticks - must be smaller than the rlb46* rebalance interval (5 min).47*/48/* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is49* promiscuous after failover50*/51#define RLB_PROMISC_TIMEOUT (10*ALB_TIMER_TICKS_PER_SEC)525354struct tlb_client_info {55struct slave *tx_slave; /* A pointer to slave used for transmitting56* packets to a Client that the Hash function57* gave this entry index.58*/59u32 tx_bytes; /* Each Client accumulates the BytesTx that60* were transmitted to it, and after each61* CallBack the LoadHistory is divided62* by the balance interval63*/64u32 load_history; /* This field contains the amount of Bytes65* that were transmitted to this client by66* the server on the previous balance67* interval in Bps.68*/69u32 next; /* The next Hash table entry index, assigned70* to use the same adapter for transmit.71*/72u32 prev; /* The previous Hash table entry index,73* assigned to use the same74*/75};7677/* -------------------------------------------------------------------------78* struct rlb_client_info contains all info related to a specific rx client79* connection. This is the Clients Hash Table entry struct.80* Note that this is not a proper hash table; if a new client's IP address81* hash collides with an existing client entry, the old entry is replaced.82*83* There is a linked list (linked by the used_next and used_prev members)84* linking all the used entries of the hash table. This allows updating85* all the clients without walking over all the unused elements of the table.86*87* There are also linked lists of entries with identical hash(ip_src). These88* allow cleaning up the table from ip_src<->mac_src associations that have89* become outdated and would cause sending out invalid ARP updates to the90* network. These are linked by the (src_next and src_prev members).91* -------------------------------------------------------------------------92*/93struct rlb_client_info {94__be32 ip_src; /* the server IP address */95__be32 ip_dst; /* the client IP address */96u8 mac_src[ETH_ALEN]; /* the server MAC address */97u8 mac_dst[ETH_ALEN]; /* the client MAC address */9899/* list of used hash table entries, starting at rx_hashtbl_used_head */100u32 used_next;101u32 used_prev;102103/* ip_src based hashing */104u32 src_next; /* next entry with same hash(ip_src) */105u32 src_prev; /* prev entry with same hash(ip_src) */106u32 src_first; /* first entry with hash(ip_src) == this entry's index */107108u8 assigned; /* checking whether this entry is assigned */109u8 ntt; /* flag - need to transmit client info */110struct slave *slave; /* the slave assigned to this client */111unsigned short vlan_id; /* VLAN tag associated with IP address */112};113114struct tlb_slave_info {115u32 head; /* Index to the head of the bi-directional clients116* hash table entries list. The entries in the list117* are the entries that were assigned to use this118* slave for transmit.119*/120u32 load; /* Each slave sums the loadHistory of all clients121* assigned to it122*/123};124125struct alb_bond_info {126struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */127u32 unbalanced_load;128atomic_t tx_rebalance_counter;129int lp_counter;130/* -------- rlb parameters -------- */131int rlb_enabled;132struct rlb_client_info *rx_hashtbl; /* Receive hash table */133u32 rx_hashtbl_used_head;134u8 rx_ntt; /* flag - need to transmit135* to all rx clients136*/137struct slave *rx_slave;/* last slave to xmit from */138u8 primary_is_promisc; /* boolean */139u32 rlb_promisc_timeout_counter;/* counts primary140* promiscuity time141*/142u32 rlb_update_delay_counter;143u32 rlb_update_retry_counter;/* counter of retries144* of client update145*/146u8 rlb_rebalance; /* flag - indicates that the147* rx traffic should be148* rebalanced149*/150};151152int bond_alb_initialize(struct bonding *bond, int rlb_enabled);153void bond_alb_deinitialize(struct bonding *bond);154int bond_alb_init_slave(struct bonding *bond, struct slave *slave);155void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave);156void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link);157void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);158netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);159netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);160struct slave *bond_xmit_alb_slave_get(struct bonding *bond,161struct sk_buff *skb);162struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,163struct sk_buff *skb);164void bond_alb_monitor(struct work_struct *);165int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);166void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id);167#endif /* _NET_BOND_ALB_H */168169170171