xref: /dpdk/drivers/net/bonding/rte_eth_bond_alb.h (revision 4f84008676739874712cb95f3c3df62198b80dc8)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4 
5 #ifndef RTE_ETH_BOND_ALB_H_
6 #define RTE_ETH_BOND_ALB_H_
7 
8 #include <rte_ether.h>
9 #include <rte_arp.h>
10 
11 #define ALB_HASH_TABLE_SIZE	256
12 #define ALB_NULL_INDEX		0xFFFFFFFF
13 
14 struct client_data {
15 	/** ARP data of single client */
16 	struct rte_ether_addr app_mac;
17 	/**< MAC address of application running DPDK */
18 	uint32_t app_ip;
19 	/**< IP address of application running DPDK */
20 	struct rte_ether_addr cli_mac;
21 	/**< Client MAC address */
22 	uint32_t cli_ip;
23 	/**< Client IP address */
24 
25 	uint16_t member_idx;
26 	/**< Index of member on which we connect with that client */
27 	uint8_t in_use;
28 	/**< Flag indicating if entry in client table is currently used */
29 	uint8_t ntt;
30 	/**< Flag indicating if we need to send update to this client on next tx */
31 
32 	struct rte_vlan_hdr vlan[2];
33 	/**< Content of vlan headers */
34 	uint8_t vlan_count;
35 	/**< Number of nested vlan headers */
36 };
37 
38 struct mode_alb_private {
39 	struct client_data client_table[ALB_HASH_TABLE_SIZE];
40 	/**< Hash table storing ARP data of every client connected */
41 	struct rte_mempool *mempool;
42 	/**< Mempool for creating ARP update packets */
43 	uint8_t ntt;
44 	/**< Flag indicating if we need to send update to any client on next tx */
45 	uint32_t last_member;
46 	/**< Index of last used member in client table */
47 	rte_spinlock_t lock;
48 };
49 
50 /**
51  * ALB mode initialization.
52  *
53  * @param bond_dev		Pointer to bonding device.
54  *
55  * @return
56  * Error code - 0 on success.
57  */
58 int
59 bond_mode_alb_enable(struct rte_eth_dev *bond_dev);
60 
61 /**
62  * Function handles ARP packet reception. If received ARP request, it is
63  * forwarded to application without changes. If it is ARP reply, client table
64  * is updated.
65  *
66  * @param eth_h			ETH header of received packet.
67  * @param offset		Vlan header offset.
68  * @param internals		Bonding data.
69  */
70 void
71 bond_mode_alb_arp_recv(struct rte_ether_hdr *eth_h, uint16_t offset,
72 		struct bond_dev_private *internals);
73 
74 /**
75  * Function handles ARP packet transmission. It also decides on which member
76  * send that packet. If packet is ARP Request, it is send on primary member.
77  * If it is ARP Reply, it is send on member stored in client table for that
78  * connection. On Reply function also updates data in client table.
79  *
80  * @param eth_h			ETH header of transmitted packet.
81  * @param offset		Vlan header offset.
82  * @param internals		Bonding data.
83  *
84  * @return
85  * Index of member on which packet should be sent.
86  */
87 uint16_t
88 bond_mode_alb_arp_xmit(struct rte_ether_hdr *eth_h, uint16_t offset,
89 		struct bond_dev_private *internals);
90 
91 /**
92  * Function fills packet with ARP data from client_info.
93  *
94  * @param client_info	Data of client to which packet is sent.
95  * @param pkt			Pointer to packet which is sent.
96  * @param internals		Bonding data.
97  *
98  * @return
99  * Index of member on which packet should be sent.
100  */
101 uint16_t
102 bond_mode_alb_arp_upd(struct client_data *client_info,
103 		struct rte_mbuf *pkt, struct bond_dev_private *internals);
104 
105 /**
106  * Function updates member indexes of active connections.
107  *
108  * @param bond_dev		Pointer to bonding device struct.
109  */
110 void
111 bond_mode_alb_client_list_upd(struct rte_eth_dev *bond_dev);
112 
113 #endif /* RTE_ETH_BOND_ALB_H_ */
114