rte_eth_bond_8023ad.h revision a41e6ff1
1/*-
2 *   BSD LICENSE
3 *
4 *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 *   All rights reserved.
6 *
7 *   Redistribution and use in source and binary forms, with or without
8 *   modification, are permitted provided that the following conditions
9 *   are met:
10 *
11 *     * Redistributions of source code must retain the above copyright
12 *       notice, this list of conditions and the following disclaimer.
13 *     * Redistributions in binary form must reproduce the above copyright
14 *       notice, this list of conditions and the following disclaimer in
15 *       the documentation and/or other materials provided with the
16 *       distribution.
17 *     * Neither the name of Intel Corporation nor the names of its
18 *       contributors may be used to endorse or promote products derived
19 *       from this software without specific prior written permission.
20 *
21 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef RTE_ETH_BOND_8023AD_H_
35#define RTE_ETH_BOND_8023AD_H_
36
37#include <rte_ether.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * Actor/partner states
45 */
46#define STATE_LACP_ACTIVE                   0x01
47#define STATE_LACP_SHORT_TIMEOUT            0x02
48#define STATE_AGGREGATION                   0x04
49#define STATE_SYNCHRONIZATION               0x08
50#define STATE_COLLECTING                    0x10
51#define STATE_DISTRIBUTING                  0x20
52/** Partners parameters are defaulted */
53#define STATE_DEFAULTED                     0x40
54#define STATE_EXPIRED                       0x80
55
56#define TLV_TYPE_ACTOR_INFORMATION          0x01
57#define TLV_TYPE_PARTNER_INFORMATION        0x02
58#define TLV_TYPE_COLLECTOR_INFORMATION      0x03
59#define TLV_TYPE_TERMINATOR_INFORMATION     0x00
60
61#define SLOW_SUBTYPE_LACP                   0x01
62#define SLOW_SUBTYPE_MARKER                 0x02
63
64#define MARKER_TLV_TYPE_INFO                0x01
65#define MARKER_TLV_TYPE_RESP                0x02
66
67typedef void (*rte_eth_bond_8023ad_ext_slowrx_fn)(uint8_t slave_id,
68						  struct rte_mbuf *lacp_pkt);
69
70enum rte_bond_8023ad_selection {
71	UNSELECTED,
72	STANDBY,
73	SELECTED
74};
75
76/** Generic slow protocol structure */
77struct slow_protocol {
78	uint8_t subtype;
79	uint8_t reserved_119[119];
80} __attribute__((__packed__));
81
82/** Generic slow protocol frame type structure */
83struct slow_protocol_frame {
84	struct ether_hdr eth_hdr;
85	struct slow_protocol slow_protocol;
86} __attribute__((__packed__));
87
88struct port_params {
89	uint16_t system_priority;
90	/**< System priority (unused in current implementation) */
91	struct ether_addr system;
92	/**< System ID - Slave MAC address, same as bonding MAC address */
93	uint16_t key;
94	/**< Speed information (implementation dependednt) and duplex. */
95	uint16_t port_priority;
96	/**< Priority of this (unused in current implementation) */
97	uint16_t port_number;
98	/**< Port number. It corresponds to slave port id. */
99} __attribute__((__packed__));
100
101struct lacpdu_actor_partner_params {
102	uint8_t tlv_type_info;
103	uint8_t info_length;
104	struct port_params port_params;
105	uint8_t state;
106	uint8_t reserved_3[3];
107} __attribute__((__packed__));
108
109/** LACPDU structure (5.4.2 in 802.1AX documentation). */
110struct lacpdu {
111	uint8_t subtype;
112	uint8_t version_number;
113
114	struct lacpdu_actor_partner_params actor;
115	struct lacpdu_actor_partner_params partner;
116
117	uint8_t tlv_type_collector_info;
118	uint8_t collector_info_length;
119	uint16_t collector_max_delay;
120	uint8_t reserved_12[12];
121
122	uint8_t tlv_type_terminator;
123	uint8_t terminator_length;
124	uint8_t reserved_50[50];
125} __attribute__((__packed__));
126
127/** LACPDU frame: Contains ethernet header and LACPDU. */
128struct lacpdu_header {
129	struct ether_hdr eth_hdr;
130	struct lacpdu lacpdu;
131} __attribute__((__packed__));
132
133struct marker {
134	uint8_t subtype;
135	uint8_t version_number;
136
137	uint8_t tlv_type_marker;
138	uint8_t info_length;
139	uint16_t requester_port;
140	struct ether_addr requester_system;
141	uint32_t requester_transaction_id;
142	uint8_t reserved_2[2];
143
144	uint8_t tlv_type_terminator;
145	uint8_t terminator_length;
146	uint8_t reserved_90[90];
147} __attribute__((__packed__));
148
149struct marker_header {
150	struct ether_hdr eth_hdr;
151	struct marker marker;
152} __attribute__((__packed__));
153
154struct rte_eth_bond_8023ad_conf {
155	uint32_t fast_periodic_ms;
156	uint32_t slow_periodic_ms;
157	uint32_t short_timeout_ms;
158	uint32_t long_timeout_ms;
159	uint32_t aggregate_wait_timeout_ms;
160	uint32_t tx_period_ms;
161	uint32_t rx_marker_period_ms;
162	uint32_t update_timeout_ms;
163	rte_eth_bond_8023ad_ext_slowrx_fn slowrx_cb;
164};
165
166struct rte_eth_bond_8023ad_slave_info {
167	enum rte_bond_8023ad_selection selected;
168	uint8_t actor_state;
169	struct port_params actor;
170	uint8_t partner_state;
171	struct port_params partner;
172	uint8_t agg_port_id;
173};
174
175/**
176 * @internal
177 *
178 * Function returns current configuration of 802.3AX mode.
179 *
180 * @param port_id   Bonding device id
181 * @param conf		Pointer to timeout structure.
182 *
183 * @return
184 *   0 - if ok
185 *   -EINVAL if conf is NULL
186 */
187int
188rte_eth_bond_8023ad_conf_get(uint8_t port_id,
189		struct rte_eth_bond_8023ad_conf *conf);
190int
191rte_eth_bond_8023ad_conf_get_v20(uint8_t port_id,
192		struct rte_eth_bond_8023ad_conf *conf);
193int
194rte_eth_bond_8023ad_conf_get_v1607(uint8_t port_id,
195		struct rte_eth_bond_8023ad_conf *conf);
196
197/**
198 * @internal
199 *
200 * Function set new configuration of 802.3AX mode.
201 *
202 * @param port_id   Bonding device id
203 * @param conf		Configuration, if NULL set default configuration.
204 * @return
205 *   0 - if ok
206 *   -EINVAL if configuration is invalid.
207 */
208int
209rte_eth_bond_8023ad_setup(uint8_t port_id,
210		struct rte_eth_bond_8023ad_conf *conf);
211int
212rte_eth_bond_8023ad_setup_v20(uint8_t port_id,
213		struct rte_eth_bond_8023ad_conf *conf);
214int
215rte_eth_bond_8023ad_setup_v1607(uint8_t port_id,
216		struct rte_eth_bond_8023ad_conf *conf);
217
218/**
219 * @internal
220 *
221 * Function returns current state of given slave device.
222 *
223 * @param slave_id  Port id of valid slave.
224 * @param conf		buffer for configuration
225 * @return
226 *   0 - if ok
227 *   -EINVAL if conf is NULL or slave id is invalid (not a slave of given
228 *       bonded device or is not inactive).
229 */
230int
231rte_eth_bond_8023ad_slave_info(uint8_t port_id, uint8_t slave_id,
232		struct rte_eth_bond_8023ad_slave_info *conf);
233
234#ifdef __cplusplus
235}
236#endif
237
238/**
239 * Configure a slave port to start collecting.
240 *
241 * @param port_id	Bonding device id
242 * @param slave_id	Port id of valid slave.
243 * @param enabled	Non-zero when collection enabled.
244 * @return
245 *   0 - if ok
246 *   -EINVAL if slave is not valid.
247 */
248int
249rte_eth_bond_8023ad_ext_collect(uint8_t port_id, uint8_t slave_id, int enabled);
250
251/**
252 * Get COLLECTING flag from slave port actor state.
253 *
254 * @param port_id	Bonding device id
255 * @param slave_id	Port id of valid slave.
256 * @return
257 *   0 - if not set
258 *   1 - if set
259 *   -EINVAL if slave is not valid.
260 */
261int
262rte_eth_bond_8023ad_ext_collect_get(uint8_t port_id, uint8_t slave_id);
263
264/**
265 * Configure a slave port to start distributing.
266 *
267 * @param port_id	Bonding device id
268 * @param slave_id	Port id of valid slave.
269 * @param enabled	Non-zero when distribution enabled.
270 * @return
271 *   0 - if ok
272 *   -EINVAL if slave is not valid.
273 */
274int
275rte_eth_bond_8023ad_ext_distrib(uint8_t port_id, uint8_t slave_id, int enabled);
276
277/**
278 * Get DISTRIBUTING flag from slave port actor state.
279 *
280 * @param port_id	Bonding device id
281 * @param slave_id	Port id of valid slave.
282 * @return
283 *   0 - if not set
284 *   1 - if set
285 *   -EINVAL if slave is not valid.
286 */
287int
288rte_eth_bond_8023ad_ext_distrib_get(uint8_t port_id, uint8_t slave_id);
289
290/**
291 * LACPDU transmit path for external 802.3ad state machine.  Caller retains
292 * ownership of the packet on failure.
293 *
294 * @param port_id	Bonding device id
295 * @param slave_id	Port ID of valid slave device.
296 * @param lacp_pkt	mbuf containing LACPDU.
297 *
298 * @return
299 *   0 on success, negative value otherwise.
300 */
301int
302rte_eth_bond_8023ad_ext_slowtx(uint8_t port_id, uint8_t slave_id,
303		struct rte_mbuf *lacp_pkt);
304
305#endif /* RTE_ETH_BOND_8023AD_H_ */
306