xref: /dpdk/drivers/net/bonding/rte_eth_bond_alb.h (revision 4f84008676739874712cb95f3c3df62198b80dc8)
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_ALB_H_
63eb6bdd8SBruce Richardson #define RTE_ETH_BOND_ALB_H_
73eb6bdd8SBruce Richardson 
83eb6bdd8SBruce Richardson #include <rte_ether.h>
93eb6bdd8SBruce Richardson #include <rte_arp.h>
103eb6bdd8SBruce Richardson 
113eb6bdd8SBruce Richardson #define ALB_HASH_TABLE_SIZE	256
123eb6bdd8SBruce Richardson #define ALB_NULL_INDEX		0xFFFFFFFF
133eb6bdd8SBruce Richardson 
143eb6bdd8SBruce Richardson struct client_data {
153eb6bdd8SBruce Richardson 	/** ARP data of single client */
166d13ea8eSOlivier Matz 	struct rte_ether_addr app_mac;
173eb6bdd8SBruce Richardson 	/**< MAC address of application running DPDK */
183eb6bdd8SBruce Richardson 	uint32_t app_ip;
193eb6bdd8SBruce Richardson 	/**< IP address of application running DPDK */
206d13ea8eSOlivier Matz 	struct rte_ether_addr cli_mac;
213eb6bdd8SBruce Richardson 	/**< Client MAC address */
223eb6bdd8SBruce Richardson 	uint32_t cli_ip;
233eb6bdd8SBruce Richardson 	/**< Client IP address */
243eb6bdd8SBruce Richardson 
2515e34522SLong Wu 	uint16_t member_idx;
2615e34522SLong Wu 	/**< Index of member on which we connect with that client */
273eb6bdd8SBruce Richardson 	uint8_t in_use;
283eb6bdd8SBruce Richardson 	/**< Flag indicating if entry in client table is currently used */
293eb6bdd8SBruce Richardson 	uint8_t ntt;
303eb6bdd8SBruce Richardson 	/**< Flag indicating if we need to send update to this client on next tx */
313eb6bdd8SBruce Richardson 
326d13ea8eSOlivier Matz 	struct rte_vlan_hdr vlan[2];
333eb6bdd8SBruce Richardson 	/**< Content of vlan headers */
343eb6bdd8SBruce Richardson 	uint8_t vlan_count;
353eb6bdd8SBruce Richardson 	/**< Number of nested vlan headers */
363eb6bdd8SBruce Richardson };
373eb6bdd8SBruce Richardson 
383eb6bdd8SBruce Richardson struct mode_alb_private {
393eb6bdd8SBruce Richardson 	struct client_data client_table[ALB_HASH_TABLE_SIZE];
403eb6bdd8SBruce Richardson 	/**< Hash table storing ARP data of every client connected */
413eb6bdd8SBruce Richardson 	struct rte_mempool *mempool;
423eb6bdd8SBruce Richardson 	/**< Mempool for creating ARP update packets */
433eb6bdd8SBruce Richardson 	uint8_t ntt;
443eb6bdd8SBruce Richardson 	/**< Flag indicating if we need to send update to any client on next tx */
4515e34522SLong Wu 	uint32_t last_member;
4615e34522SLong Wu 	/**< Index of last used member in client table */
473eb6bdd8SBruce Richardson 	rte_spinlock_t lock;
483eb6bdd8SBruce Richardson };
493eb6bdd8SBruce Richardson 
503eb6bdd8SBruce Richardson /**
513eb6bdd8SBruce Richardson  * ALB mode initialization.
523eb6bdd8SBruce Richardson  *
533eb6bdd8SBruce Richardson  * @param bond_dev		Pointer to bonding device.
543eb6bdd8SBruce Richardson  *
553eb6bdd8SBruce Richardson  * @return
563eb6bdd8SBruce Richardson  * Error code - 0 on success.
573eb6bdd8SBruce Richardson  */
583eb6bdd8SBruce Richardson int
593eb6bdd8SBruce Richardson bond_mode_alb_enable(struct rte_eth_dev *bond_dev);
603eb6bdd8SBruce Richardson 
613eb6bdd8SBruce Richardson /**
623eb6bdd8SBruce Richardson  * Function handles ARP packet reception. If received ARP request, it is
633eb6bdd8SBruce Richardson  * forwarded to application without changes. If it is ARP reply, client table
643eb6bdd8SBruce Richardson  * is updated.
653eb6bdd8SBruce Richardson  *
663eb6bdd8SBruce Richardson  * @param eth_h			ETH header of received packet.
673eb6bdd8SBruce Richardson  * @param offset		Vlan header offset.
683eb6bdd8SBruce Richardson  * @param internals		Bonding data.
693eb6bdd8SBruce Richardson  */
703eb6bdd8SBruce Richardson void
716d13ea8eSOlivier Matz bond_mode_alb_arp_recv(struct rte_ether_hdr *eth_h, uint16_t offset,
723eb6bdd8SBruce Richardson 		struct bond_dev_private *internals);
733eb6bdd8SBruce Richardson 
743eb6bdd8SBruce Richardson /**
7515e34522SLong Wu  * Function handles ARP packet transmission. It also decides on which member
7615e34522SLong Wu  * send that packet. If packet is ARP Request, it is send on primary member.
7715e34522SLong Wu  * If it is ARP Reply, it is send on member stored in client table for that
783eb6bdd8SBruce Richardson  * connection. On Reply function also updates data in client table.
793eb6bdd8SBruce Richardson  *
803eb6bdd8SBruce Richardson  * @param eth_h			ETH header of transmitted packet.
813eb6bdd8SBruce Richardson  * @param offset		Vlan header offset.
823eb6bdd8SBruce Richardson  * @param internals		Bonding data.
833eb6bdd8SBruce Richardson  *
843eb6bdd8SBruce Richardson  * @return
8515e34522SLong Wu  * Index of member on which packet should be sent.
863eb6bdd8SBruce Richardson  */
87f8244c63SZhiyong Yang uint16_t
886d13ea8eSOlivier Matz bond_mode_alb_arp_xmit(struct rte_ether_hdr *eth_h, uint16_t offset,
893eb6bdd8SBruce Richardson 		struct bond_dev_private *internals);
903eb6bdd8SBruce Richardson 
913eb6bdd8SBruce Richardson /**
923eb6bdd8SBruce Richardson  * Function fills packet with ARP data from client_info.
933eb6bdd8SBruce Richardson  *
943eb6bdd8SBruce Richardson  * @param client_info	Data of client to which packet is sent.
953eb6bdd8SBruce Richardson  * @param pkt			Pointer to packet which is sent.
963eb6bdd8SBruce Richardson  * @param internals		Bonding data.
973eb6bdd8SBruce Richardson  *
983eb6bdd8SBruce Richardson  * @return
9915e34522SLong Wu  * Index of member on which packet should be sent.
1003eb6bdd8SBruce Richardson  */
101f8244c63SZhiyong Yang uint16_t
1023eb6bdd8SBruce Richardson bond_mode_alb_arp_upd(struct client_data *client_info,
1033eb6bdd8SBruce Richardson 		struct rte_mbuf *pkt, struct bond_dev_private *internals);
1043eb6bdd8SBruce Richardson 
1053eb6bdd8SBruce Richardson /**
10615e34522SLong Wu  * Function updates member indexes of active connections.
1073eb6bdd8SBruce Richardson  *
108*4f840086SLong Wu  * @param bond_dev		Pointer to bonding device struct.
1093eb6bdd8SBruce Richardson  */
1103eb6bdd8SBruce Richardson void
1113eb6bdd8SBruce Richardson bond_mode_alb_client_list_upd(struct rte_eth_dev *bond_dev);
1123eb6bdd8SBruce Richardson 
1133eb6bdd8SBruce Richardson #endif /* RTE_ETH_BOND_ALB_H_ */
114