xref: /dpdk/drivers/net/bonding/rte_eth_bond.h (revision 19da63ccfc7e83f06e1bb14d830d4e0de99b13cf)
15566a3e3SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
25566a3e3SBruce Richardson  * Copyright(c) 2010-2015 Intel Corporation
33eb6bdd8SBruce Richardson  */
43eb6bdd8SBruce Richardson 
53eb6bdd8SBruce Richardson #ifndef _RTE_ETH_BOND_H_
63eb6bdd8SBruce Richardson #define _RTE_ETH_BOND_H_
73eb6bdd8SBruce Richardson 
83eb6bdd8SBruce Richardson /**
93eb6bdd8SBruce Richardson  * @file rte_eth_bond.h
103eb6bdd8SBruce Richardson  *
113eb6bdd8SBruce Richardson  * RTE Link Bonding Ethernet Device
123eb6bdd8SBruce Richardson  * Link Bonding for 1GbE and 10GbE ports to allow the aggregation of multiple
134f840086SLong Wu  * (member) NICs into a single logical interface. The bonding device processes
143eb6bdd8SBruce Richardson  * these interfaces based on the mode of operation specified and supported.
153eb6bdd8SBruce Richardson  * This implementation supports 4 modes of operation round robin, active backup
163eb6bdd8SBruce Richardson  * balance and broadcast. Providing redundant links, fault tolerance and/or
173eb6bdd8SBruce Richardson  * load balancing of network ports
183eb6bdd8SBruce Richardson  */
193eb6bdd8SBruce Richardson 
20*719834a6SMattias Rönnblom #include <rte_ether.h>
21*719834a6SMattias Rönnblom 
223eb6bdd8SBruce Richardson #ifdef __cplusplus
233eb6bdd8SBruce Richardson extern "C" {
243eb6bdd8SBruce Richardson #endif
253eb6bdd8SBruce Richardson 
263eb6bdd8SBruce Richardson /* Supported modes of operation of link bonding library  */
273eb6bdd8SBruce Richardson 
283eb6bdd8SBruce Richardson #define BONDING_MODE_ROUND_ROBIN		(0)
293eb6bdd8SBruce Richardson /**< Round Robin (Mode 0).
303eb6bdd8SBruce Richardson  * In this mode all transmitted packets will be balanced equally across all
314f840086SLong Wu  * active members of the bonding in a round robin fashion.
3215e34522SLong Wu  */
333eb6bdd8SBruce Richardson #define BONDING_MODE_ACTIVE_BACKUP		(1)
343eb6bdd8SBruce Richardson /**< Active Backup (Mode 1).
353eb6bdd8SBruce Richardson  * In this mode all packets transmitted will be transmitted on the primary
3615e34522SLong Wu  * member until such point as the primary member is no longer available and then
3715e34522SLong Wu  * transmitted packets will be sent on the next available members. The primary
3815e34522SLong Wu  * member can be defined by the user but defaults to the first active member
3915e34522SLong Wu  * available if not specified.
4015e34522SLong Wu  */
413eb6bdd8SBruce Richardson #define BONDING_MODE_BALANCE			(2)
423eb6bdd8SBruce Richardson /**< Balance (Mode 2).
433eb6bdd8SBruce Richardson  * In this mode all packets transmitted will be balanced across the available
4415e34522SLong Wu  * members using one of three available transmit policies - l2, l2+3 or l3+4.
453eb6bdd8SBruce Richardson  * See BALANCE_XMIT_POLICY macros definitions for further details on transmit
4615e34522SLong Wu  * policies.
4715e34522SLong Wu  */
483eb6bdd8SBruce Richardson #define BONDING_MODE_BROADCAST			(3)
493eb6bdd8SBruce Richardson /**< Broadcast (Mode 3).
503eb6bdd8SBruce Richardson  * In this mode all transmitted packets will be transmitted on all available
514f840086SLong Wu  * active members of the bonding.
5215e34522SLong Wu  */
533eb6bdd8SBruce Richardson #define BONDING_MODE_8023AD				(4)
543eb6bdd8SBruce Richardson /**< 802.3AD (Mode 4).
553eb6bdd8SBruce Richardson  *
563eb6bdd8SBruce Richardson  * This mode provides auto negotiation/configuration
573eb6bdd8SBruce Richardson  * of peers and well as link status changes monitoring using out of band
583eb6bdd8SBruce Richardson  * LACP (link aggregation control protocol) messages. For further details of
593eb6bdd8SBruce Richardson  * LACP specification see the IEEE 802.3ad/802.1AX standards. It is also
603eb6bdd8SBruce Richardson  * described here
613eb6bdd8SBruce Richardson  * https://www.kernel.org/doc/Documentation/networking/bonding.txt.
623eb6bdd8SBruce Richardson  *
633eb6bdd8SBruce Richardson  * Important Usage Notes:
643eb6bdd8SBruce Richardson  * - for LACP mode to work the rx/tx burst functions must be invoked
653eb6bdd8SBruce Richardson  * at least once every 100ms, otherwise the out-of-band LACP messages will not
663eb6bdd8SBruce Richardson  * be handled with the expected latency and this may cause the link status to be
673eb6bdd8SBruce Richardson  * incorrectly marked as down or failure to correctly negotiate with peers.
683eb6bdd8SBruce Richardson  * - For optimal performance during initial handshaking the array of mbufs provided
6915e34522SLong Wu  * to rx_burst should be at least 2 times the member count size.
703eb6bdd8SBruce Richardson  */
713eb6bdd8SBruce Richardson #define BONDING_MODE_TLB	(5)
723eb6bdd8SBruce Richardson /**< Adaptive TLB (Mode 5)
733eb6bdd8SBruce Richardson  * This mode provides an adaptive transmit load balancing. It dynamically
7415e34522SLong Wu  * changes the transmitting member, according to the computed load. Statistics
7515e34522SLong Wu  * are collected in 100ms intervals and scheduled every 10ms.
7615e34522SLong Wu  */
773eb6bdd8SBruce Richardson #define BONDING_MODE_ALB	(6)
783eb6bdd8SBruce Richardson /**< Adaptive Load Balancing (Mode 6)
793eb6bdd8SBruce Richardson  * This mode includes adaptive TLB and receive load balancing (RLB). In RLB the
803eb6bdd8SBruce Richardson  * bonding driver intercepts ARP replies send by local system and overwrites its
813eb6bdd8SBruce Richardson  * source MAC address, so that different peers send data to the server on
8215e34522SLong Wu  * different member interfaces. When local system sends ARP request, it saves IP
833eb6bdd8SBruce Richardson  * information from it. When ARP reply from that peer is received, its MAC is
8415e34522SLong Wu  * stored, one of member MACs assigned and ARP reply send to that peer.
853eb6bdd8SBruce Richardson  */
863eb6bdd8SBruce Richardson 
873eb6bdd8SBruce Richardson /* Balance Mode Transmit Policies */
883eb6bdd8SBruce Richardson #define BALANCE_XMIT_POLICY_LAYER2		(0)
893eb6bdd8SBruce Richardson /**< Layer 2 (Ethernet MAC) */
903eb6bdd8SBruce Richardson #define BALANCE_XMIT_POLICY_LAYER23		(1)
913eb6bdd8SBruce Richardson /**< Layer 2+3 (Ethernet MAC + IP Addresses) transmit load balancing */
923eb6bdd8SBruce Richardson #define BALANCE_XMIT_POLICY_LAYER34		(2)
933eb6bdd8SBruce Richardson /**< Layer 3+4 (IP Addresses + UDP Ports) transmit load balancing */
943eb6bdd8SBruce Richardson 
953eb6bdd8SBruce Richardson /**
964f840086SLong Wu  * Create a bonding rte_eth_dev device
973eb6bdd8SBruce Richardson  *
983eb6bdd8SBruce Richardson  * @param name			Name of new link bonding device.
993eb6bdd8SBruce Richardson  * @param mode			Mode to initialize bonding device in.
1003eb6bdd8SBruce Richardson  * @param socket_id		Socket Id on which to allocate eth_dev resources.
1013eb6bdd8SBruce Richardson  *
1023eb6bdd8SBruce Richardson  * @return
1033eb6bdd8SBruce Richardson  *	Port Id of created rte_eth_dev on success, negative value otherwise
1043eb6bdd8SBruce Richardson  */
1053eb6bdd8SBruce Richardson int
1063eb6bdd8SBruce Richardson rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id);
1073eb6bdd8SBruce Richardson 
1083eb6bdd8SBruce Richardson /**
1094f840086SLong Wu  * Free a bonding rte_eth_dev device
1108d30fe7fSBernard Iremonger  *
1118d30fe7fSBernard Iremonger  * @param name			Name of the link bonding device.
1128d30fe7fSBernard Iremonger  *
1138d30fe7fSBernard Iremonger  * @return
1148d30fe7fSBernard Iremonger  *	0 on success, negative value otherwise
1158d30fe7fSBernard Iremonger  */
1168d30fe7fSBernard Iremonger int
1178d30fe7fSBernard Iremonger rte_eth_bond_free(const char *name);
1188d30fe7fSBernard Iremonger 
1198d30fe7fSBernard Iremonger /**
1204f840086SLong Wu  * Add a rte_eth_dev device as a member to the bonding device
1213eb6bdd8SBruce Richardson  *
1224f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
12315e34522SLong Wu  * @param member_port_id		Port ID of member device.
1243eb6bdd8SBruce Richardson  *
1253eb6bdd8SBruce Richardson  * @return
1263eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
1273eb6bdd8SBruce Richardson  */
1283eb6bdd8SBruce Richardson int
1294f840086SLong Wu rte_eth_bond_member_add(uint16_t bonding_port_id, uint16_t member_port_id);
1303eb6bdd8SBruce Richardson 
1313eb6bdd8SBruce Richardson /**
1324f840086SLong Wu  * Remove a member rte_eth_dev device from the bonding device
1333eb6bdd8SBruce Richardson  *
1344f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
13515e34522SLong Wu  * @param member_port_id		Port ID of member device.
1363eb6bdd8SBruce Richardson  *
1373eb6bdd8SBruce Richardson  * @return
1383eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
1393eb6bdd8SBruce Richardson  */
1403eb6bdd8SBruce Richardson int
1414f840086SLong Wu rte_eth_bond_member_remove(uint16_t bonding_port_id, uint16_t member_port_id);
1423eb6bdd8SBruce Richardson 
1433eb6bdd8SBruce Richardson /**
1444f840086SLong Wu  * Set link bonding mode of bonding device
1453eb6bdd8SBruce Richardson  *
1464f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
1473eb6bdd8SBruce Richardson  * @param mode				Bonding mode to set
1483eb6bdd8SBruce Richardson  *
1493eb6bdd8SBruce Richardson  * @return
1503eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
1513eb6bdd8SBruce Richardson  */
1523eb6bdd8SBruce Richardson int
1534f840086SLong Wu rte_eth_bond_mode_set(uint16_t bonding_port_id, uint8_t mode);
1543eb6bdd8SBruce Richardson 
1553eb6bdd8SBruce Richardson /**
1564f840086SLong Wu  * Get link bonding mode of bonding device
1573eb6bdd8SBruce Richardson  *
1584f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
1593eb6bdd8SBruce Richardson  *
1603eb6bdd8SBruce Richardson  * @return
1613eb6bdd8SBruce Richardson  *	link bonding mode on success, negative value otherwise
1623eb6bdd8SBruce Richardson  */
1633eb6bdd8SBruce Richardson int
1644f840086SLong Wu rte_eth_bond_mode_get(uint16_t bonding_port_id);
1653eb6bdd8SBruce Richardson 
1663eb6bdd8SBruce Richardson /**
1674f840086SLong Wu  * Set member rte_eth_dev as primary member of bonding device
1683eb6bdd8SBruce Richardson  *
1694f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
17015e34522SLong Wu  * @param member_port_id		Port ID of member device.
1713eb6bdd8SBruce Richardson  *
1723eb6bdd8SBruce Richardson  * @return
1733eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
1743eb6bdd8SBruce Richardson  */
1753eb6bdd8SBruce Richardson int
1764f840086SLong Wu rte_eth_bond_primary_set(uint16_t bonding_port_id, uint16_t member_port_id);
1773eb6bdd8SBruce Richardson 
1783eb6bdd8SBruce Richardson /**
1794f840086SLong Wu  * Get primary member of bonding device
1803eb6bdd8SBruce Richardson  *
1814f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
1823eb6bdd8SBruce Richardson  *
1833eb6bdd8SBruce Richardson  * @return
18415e34522SLong Wu  *	Port Id of primary member on success, -1 on failure
1853eb6bdd8SBruce Richardson  */
1863eb6bdd8SBruce Richardson int
1874f840086SLong Wu rte_eth_bond_primary_get(uint16_t bonding_port_id);
1883eb6bdd8SBruce Richardson 
1893eb6bdd8SBruce Richardson /**
1904f840086SLong Wu  * Populate an array with list of the members port id's of the bonding device
1913eb6bdd8SBruce Richardson  *
1924f840086SLong Wu  * @param bonding_port_id	Port ID of bonding eth_dev to interrogate
19315e34522SLong Wu  * @param members			Array to be populated with the current active members
19415e34522SLong Wu  * @param len				Length of members array
1953eb6bdd8SBruce Richardson  *
1963eb6bdd8SBruce Richardson  * @return
1974f840086SLong Wu  *	Number of members associated with bonding device on success,
1983eb6bdd8SBruce Richardson  *	negative value otherwise
1993eb6bdd8SBruce Richardson  */
2003eb6bdd8SBruce Richardson int
2014f840086SLong Wu rte_eth_bond_members_get(uint16_t bonding_port_id, uint16_t members[],
202f8244c63SZhiyong Yang 		uint16_t len);
2033eb6bdd8SBruce Richardson 
2043eb6bdd8SBruce Richardson /**
2054f840086SLong Wu  * Populate an array with list of the active members port id's of the bonding
2063eb6bdd8SBruce Richardson  * device.
2073eb6bdd8SBruce Richardson  *
2084f840086SLong Wu  * @param bonding_port_id	Port ID of bonding eth_dev to interrogate
20915e34522SLong Wu  * @param members			Array to be populated with the current active members
21015e34522SLong Wu  * @param len				Length of members array
2113eb6bdd8SBruce Richardson  *
2123eb6bdd8SBruce Richardson  * @return
2134f840086SLong Wu  *	Number of active members associated with bonding device on success,
2143eb6bdd8SBruce Richardson  *	negative value otherwise
2153eb6bdd8SBruce Richardson  */
2163eb6bdd8SBruce Richardson int
2174f840086SLong Wu rte_eth_bond_active_members_get(uint16_t bonding_port_id, uint16_t members[],
218f8244c63SZhiyong Yang 		uint16_t len);
2193eb6bdd8SBruce Richardson 
2203eb6bdd8SBruce Richardson /**
2214f840086SLong Wu  * Set explicit MAC address to use on bonding device and it's members.
2223eb6bdd8SBruce Richardson  *
2234f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2244f840086SLong Wu  * @param mac_addr			MAC Address to use on bonding device overriding
22515e34522SLong Wu  *							members MAC addresses
2263eb6bdd8SBruce Richardson  *
2273eb6bdd8SBruce Richardson  * @return
2283eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
2293eb6bdd8SBruce Richardson  */
2303eb6bdd8SBruce Richardson int
2314f840086SLong Wu rte_eth_bond_mac_address_set(uint16_t bonding_port_id,
2326d13ea8eSOlivier Matz 		struct rte_ether_addr *mac_addr);
2333eb6bdd8SBruce Richardson 
2343eb6bdd8SBruce Richardson /**
2354f840086SLong Wu  * Reset bonding device to use MAC from primary member on bonding device and it's
23615e34522SLong Wu  * members.
2373eb6bdd8SBruce Richardson  *
2384f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2393eb6bdd8SBruce Richardson  *
2403eb6bdd8SBruce Richardson  * @return
2413eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise
2423eb6bdd8SBruce Richardson  */
2433eb6bdd8SBruce Richardson int
2444f840086SLong Wu rte_eth_bond_mac_address_reset(uint16_t bonding_port_id);
2453eb6bdd8SBruce Richardson 
2463eb6bdd8SBruce Richardson /**
2474f840086SLong Wu  * Set the transmit policy for bonding device to use when it is operating in
2483eb6bdd8SBruce Richardson  * balance mode, this parameter is otherwise ignored in other modes of
2493eb6bdd8SBruce Richardson  * operation.
2503eb6bdd8SBruce Richardson  *
2514f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2523eb6bdd8SBruce Richardson  * @param policy			Balance mode transmission policy.
2533eb6bdd8SBruce Richardson  *
2543eb6bdd8SBruce Richardson  * @return
2553eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise.
2563eb6bdd8SBruce Richardson  */
2573eb6bdd8SBruce Richardson int
2584f840086SLong Wu rte_eth_bond_xmit_policy_set(uint16_t bonding_port_id, uint8_t policy);
2593eb6bdd8SBruce Richardson 
2603eb6bdd8SBruce Richardson /**
2614f840086SLong Wu  * Get the transmit policy set on bonding device for balance mode operation
2623eb6bdd8SBruce Richardson  *
2634f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2643eb6bdd8SBruce Richardson  *
2653eb6bdd8SBruce Richardson  * @return
2663eb6bdd8SBruce Richardson  *	Balance transmit policy on success, negative value otherwise.
2673eb6bdd8SBruce Richardson  */
2683eb6bdd8SBruce Richardson int
2694f840086SLong Wu rte_eth_bond_xmit_policy_get(uint16_t bonding_port_id);
2703eb6bdd8SBruce Richardson 
2713eb6bdd8SBruce Richardson /**
2723eb6bdd8SBruce Richardson  * Set the link monitoring frequency (in ms) for monitoring the link status of
27315e34522SLong Wu  * member devices
2743eb6bdd8SBruce Richardson  *
2754f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2763eb6bdd8SBruce Richardson  * @param internal_ms		Monitoring interval in milliseconds
2773eb6bdd8SBruce Richardson  *
2783eb6bdd8SBruce Richardson  * @return
2793eb6bdd8SBruce Richardson  *	0 on success, negative value otherwise.
2803eb6bdd8SBruce Richardson  */
2813eb6bdd8SBruce Richardson 
2823eb6bdd8SBruce Richardson int
2834f840086SLong Wu rte_eth_bond_link_monitoring_set(uint16_t bonding_port_id, uint32_t internal_ms);
2843eb6bdd8SBruce Richardson 
2853eb6bdd8SBruce Richardson /**
2863eb6bdd8SBruce Richardson  * Get the current link monitoring frequency (in ms) for monitoring of the link
28715e34522SLong Wu  * status of member devices
2883eb6bdd8SBruce Richardson  *
2894f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
2903eb6bdd8SBruce Richardson  *
2913eb6bdd8SBruce Richardson  * @return
2923eb6bdd8SBruce Richardson  *	Monitoring interval on success, negative value otherwise.
2933eb6bdd8SBruce Richardson  */
2943eb6bdd8SBruce Richardson int
2954f840086SLong Wu rte_eth_bond_link_monitoring_get(uint16_t bonding_port_id);
2963eb6bdd8SBruce Richardson 
2973eb6bdd8SBruce Richardson 
2983eb6bdd8SBruce Richardson /**
2994f840086SLong Wu  * Set the period in milliseconds for delaying the disabling of a bonding link
3003eb6bdd8SBruce Richardson  * when the link down status has been detected
3013eb6bdd8SBruce Richardson  *
3024f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
3033eb6bdd8SBruce Richardson  * @param delay_ms			Delay period in milliseconds.
3043eb6bdd8SBruce Richardson  *
3053eb6bdd8SBruce Richardson  * @return
3063eb6bdd8SBruce Richardson  *  0 on success, negative value otherwise.
3073eb6bdd8SBruce Richardson  */
3083eb6bdd8SBruce Richardson int
3094f840086SLong Wu rte_eth_bond_link_down_prop_delay_set(uint16_t bonding_port_id,
310f8244c63SZhiyong Yang 				       uint32_t delay_ms);
3113eb6bdd8SBruce Richardson 
3123eb6bdd8SBruce Richardson /**
3134f840086SLong Wu  * Get the period in milliseconds set for delaying the disabling of a bonding
3143eb6bdd8SBruce Richardson  * link when the link down status has been detected
3153eb6bdd8SBruce Richardson  *
3164f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
3173eb6bdd8SBruce Richardson  *
3183eb6bdd8SBruce Richardson  * @return
3193eb6bdd8SBruce Richardson  *  Delay period on success, negative value otherwise.
3203eb6bdd8SBruce Richardson  */
3213eb6bdd8SBruce Richardson int
3224f840086SLong Wu rte_eth_bond_link_down_prop_delay_get(uint16_t bonding_port_id);
3233eb6bdd8SBruce Richardson 
3243eb6bdd8SBruce Richardson /**
3254f840086SLong Wu  * Set the period in milliseconds for delaying the enabling of a bonding link
3263eb6bdd8SBruce Richardson  * when the link up status has been detected
3273eb6bdd8SBruce Richardson  *
3284f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
3293eb6bdd8SBruce Richardson  * @param delay_ms			Delay period in milliseconds.
3303eb6bdd8SBruce Richardson  *
3313eb6bdd8SBruce Richardson  * @return
3323eb6bdd8SBruce Richardson  *  0 on success, negative value otherwise.
3333eb6bdd8SBruce Richardson  */
3343eb6bdd8SBruce Richardson int
3354f840086SLong Wu rte_eth_bond_link_up_prop_delay_set(uint16_t bonding_port_id,
336f8244c63SZhiyong Yang 				    uint32_t delay_ms);
3373eb6bdd8SBruce Richardson 
3383eb6bdd8SBruce Richardson /**
3394f840086SLong Wu  * Get the period in milliseconds set for delaying the enabling of a bonding
3403eb6bdd8SBruce Richardson  * link when the link up status has been detected
3413eb6bdd8SBruce Richardson  *
3424f840086SLong Wu  * @param bonding_port_id	Port ID of bonding device.
3433eb6bdd8SBruce Richardson  *
3443eb6bdd8SBruce Richardson  * @return
3453eb6bdd8SBruce Richardson  *  Delay period on success, negative value otherwise.
3463eb6bdd8SBruce Richardson  */
3473eb6bdd8SBruce Richardson int
3484f840086SLong Wu rte_eth_bond_link_up_prop_delay_get(uint16_t bonding_port_id);
3493eb6bdd8SBruce Richardson 
3503eb6bdd8SBruce Richardson 
3513eb6bdd8SBruce Richardson #ifdef __cplusplus
3523eb6bdd8SBruce Richardson }
3533eb6bdd8SBruce Richardson #endif
3543eb6bdd8SBruce Richardson 
3553eb6bdd8SBruce Richardson #endif
356