4117a707659e2daa6353d9aa0f6aecd52b65e1e2
[dpdk.git] / lib / librte_pmd_bond / rte_eth_bond.h
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_H_
35 #define _RTE_ETH_BOND_H_
36
37 /**
38  * @file rte_eth_bond.h
39  *
40  * RTE Link Bonding Ethernet Device
41  * Link Bonding for 1GbE and 10GbE ports to allow the aggregation of multiple
42  * (slave) NICs into a single logical interface. The bonded device processes
43  * these interfaces based on the mode of operation specified and supported.
44  * This implementation supports 4 modes of operation round robin, active backup
45  * balance and broadcast. Providing redundant links, fault tolerance and/or
46  * load balancing of network ports
47  */
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 #include <rte_ether.h>
54
55 /* Supported modes of operation of link bonding library  */
56
57 #define BONDING_MODE_ROUND_ROBIN                (0)
58 /**< Round Robin (Mode 0).
59  * In this mode all transmitted packets will be balanced equally across all
60  * active slaves of the bonded in a round robin fashion. */
61 #define BONDING_MODE_ACTIVE_BACKUP              (1)
62 /**< Active Backup (Mode 1).
63  * In this mode all packets transmitted will be transmitted on the primary
64  * slave until such point as the primary slave is no longer available and then
65  * transmitted packets will be sent on the next available slaves. The primary
66  * slave can be defined by the user but defaults to the first active slave
67  * available if not specified. */
68 #define BONDING_MODE_BALANCE                    (2)
69 /**< Balance (Mode 2).
70  * In this mode all packets transmitted will be balanced across the available
71  * slaves using one of three available transmit policies - l2, l2+3 or l3+4.
72  * See BALANCE_XMIT_POLICY macros definitions for further details on transmit
73  * policies. */
74 #ifdef RTE_MBUF_REFCNT
75 #define BONDING_MODE_BROADCAST                  (3)
76 /**< Broadcast (Mode 3).
77  * In this mode all transmitted packets will be transmitted on all available
78  * active slaves of the bonded. */
79 #endif
80 #define BONDING_MODE_8023AD                             (4)
81 /**< 802.3AD (Mode 4).
82  *
83  * This mode provides auto negotiation/configuration
84  * of peers and well as link status changes monitoring using out of band
85  * LACP (link aggregation control protocol) messages. For further details of
86  * LACP specification see the IEEE 802.3ad/802.1AX standards. It is also
87  * described here
88  * https://www.kernel.org/doc/Documentation/networking/bonding.txt.
89  *
90  * Important Usage Notes:
91  * - for LACP mode to work the rx/tx burst functions must be invoked
92  * at least once every 100ms, otherwise the out-of-band LACP messages will not
93  * be handled with the expected latency and this may cause the link status to be
94  * incorrectly marked as down or failure to correctly negotiate with peers.
95  * - For optimal performance during initial handshaking the array of mbufs provided
96  * to rx_burst should be at least 2 times the slave count size.
97  *
98  */
99 #define BONDING_MODE_TLB        (5)
100 /**< Adaptive TLB (Mode 5)
101  * This mode provides an adaptive transmit load balancing. It dynamically
102  * changes the transmitting slave, according to the computed load. Statistics
103  * are collected in 100ms intervals and scheduled every 10ms */
104 #define BONDING_MODE_ALB        (6)
105 /**< Adaptive Load Balancing (Mode 6)
106  * This mode includes adaptive TLB and receive load balancing (RLB). In RLB the
107  * bonding driver intercepts ARP replies send by local system and overwrites its
108  * source MAC address, so that different peers send data to the server on
109  * different slave interfaces. When local system sends ARP request, it saves IP
110  * information from it. When ARP reply from that peer is received, its MAC is
111  * stored, one of slave MACs assigned and ARP reply send to that peer.
112  */
113
114 /* Balance Mode Transmit Policies */
115 #define BALANCE_XMIT_POLICY_LAYER2              (0)
116 /**< Layer 2 (Ethernet MAC) */
117 #define BALANCE_XMIT_POLICY_LAYER23             (1)
118 /**< Layer 2+3 (Ethernet MAC + IP Addresses) transmit load balancing */
119 #define BALANCE_XMIT_POLICY_LAYER34             (2)
120 /**< Layer 3+4 (IP Addresses + UDP Ports) transmit load balancing */
121
122 /**
123  * Create a bonded rte_eth_dev device
124  *
125  * @param name                  Name of new link bonding device.
126  * @param mode                  Mode to initialize bonding device in.
127  * @param socket_id             Socket Id on which to allocate eth_dev resources.
128  *
129  * @return
130  *      Port Id of created rte_eth_dev on success, negative value otherwise
131  */
132 int
133 rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id);
134
135 /**
136  * Add a rte_eth_dev device as a slave to the bonded device
137  *
138  * @param bonded_port_id        Port ID of bonded device.
139  * @param slave_port_id         Port ID of slave device.
140  *
141  * @return
142  *      0 on success, negative value otherwise
143  */
144 int
145 rte_eth_bond_slave_add(uint8_t bonded_port_id, uint8_t slave_port_id);
146
147 /**
148  * Remove a slave rte_eth_dev device from the bonded device
149  *
150  * @param bonded_port_id        Port ID of bonded device.
151  * @param slave_port_id         Port ID of slave device.
152  *
153  * @return
154  *      0 on success, negative value otherwise
155  */
156 int
157 rte_eth_bond_slave_remove(uint8_t bonded_port_id, uint8_t slave_port_id);
158
159 /**
160  * Set link bonding mode of bonded device
161  *
162  * @param bonded_port_id        Port ID of bonded device.
163  * @param mode                          Bonding mode to set
164  *
165  * @return
166  *      0 on success, negative value otherwise
167  */
168 int
169 rte_eth_bond_mode_set(uint8_t bonded_port_id, uint8_t mode);
170
171 /**
172  * Get link bonding mode of bonded device
173  *
174  * @param bonded_port_id        Port ID of bonded device.
175  *
176  * @return
177  *      link bonding mode on success, negative value otherwise
178  */
179 int
180 rte_eth_bond_mode_get(uint8_t bonded_port_id);
181
182 /**
183  * Set slave rte_eth_dev as primary slave of bonded device
184  *
185  * @param bonded_port_id        Port ID of bonded device.
186  * @param slave_port_id         Port ID of slave device.
187  *
188  * @return
189  *      0 on success, negative value otherwise
190  */
191 int
192 rte_eth_bond_primary_set(uint8_t bonded_port_id, uint8_t slave_port_id);
193
194 /**
195  * Get primary slave of bonded device
196  *
197  * @param bonded_port_id        Port ID of bonded device.
198  *
199  * @return
200  *      Port Id of primary slave on success, -1 on failure
201  */
202 int
203 rte_eth_bond_primary_get(uint8_t bonded_port_id);
204
205 /**
206  * Populate an array with list of the slaves port id's of the bonded device
207  *
208  * @param bonded_port_id        Port ID of bonded eth_dev to interrogate
209  * @param slaves                        Array to be populated with the current active slaves
210  * @param len                           Length of slaves array
211  *
212  * @return
213  *      Number of slaves associated with bonded device on success,
214  *      negative value otherwise
215  */
216 int
217 rte_eth_bond_slaves_get(uint8_t bonded_port_id, uint8_t slaves[], uint8_t len);
218
219 /**
220  * Populate an array with list of the active slaves port id's of the bonded
221  * device.
222  *
223  * @param bonded_port_id        Port ID of bonded eth_dev to interrogate
224  * @param slaves                        Array to be populated with the current active slaves
225  * @param len                           Length of slaves array
226  *
227  * @return
228  *      Number of active slaves associated with bonded device on success,
229  *      negative value otherwise
230  */
231 int
232 rte_eth_bond_active_slaves_get(uint8_t bonded_port_id, uint8_t slaves[],
233                 uint8_t len);
234
235 /**
236  * Set explicit MAC address to use on bonded device and it's slaves.
237  *
238  * @param bonded_port_id        Port ID of bonded device.
239  * @param mac_addr                      MAC Address to use on bonded device overriding
240  *                                                      slaves MAC addresses
241  *
242  * @return
243  *      0 on success, negative value otherwise
244  */
245 int
246 rte_eth_bond_mac_address_set(uint8_t bonded_port_id,
247                 struct ether_addr *mac_addr);
248
249 /**
250  * Reset bonded device to use MAC from primary slave on bonded device and it's
251  * slaves.
252  *
253  * @param bonded_port_id        Port ID of bonded device.
254  *
255  * @return
256  *      0 on success, negative value otherwise
257  */
258 int
259 rte_eth_bond_mac_address_reset(uint8_t bonded_port_id);
260
261 /**
262  * Set the transmit policy for bonded device to use when it is operating in
263  * balance mode, this parameter is otherwise ignored in other modes of
264  * operation.
265  *
266  * @param bonded_port_id        Port ID of bonded device.
267  * @param policy                        Balance mode transmission policy.
268  *
269  * @return
270  *      0 on success, negative value otherwise.
271  */
272 int
273 rte_eth_bond_xmit_policy_set(uint8_t bonded_port_id, uint8_t policy);
274
275 /**
276  * Get the transmit policy set on bonded device for balance mode operation
277  *
278  * @param bonded_port_id        Port ID of bonded device.
279  *
280  * @return
281  *      Balance transmit policy on success, negative value otherwise.
282  */
283 int
284 rte_eth_bond_xmit_policy_get(uint8_t bonded_port_id);
285
286 /**
287  * Set the link monitoring frequency (in ms) for monitoring the link status of
288  * slave devices
289  *
290  * @param bonded_port_id        Port ID of bonded device.
291  * @param internal_ms           Monitoring interval in milliseconds
292  *
293  * @return
294  *      0 on success, negative value otherwise.
295  */
296
297 int
298 rte_eth_bond_link_monitoring_set(uint8_t bonded_port_id, uint32_t internal_ms);
299
300 /**
301  * Get the current link monitoring frequency (in ms) for monitoring of the link
302  * status of slave devices
303  *
304  * @param bonded_port_id        Port ID of bonded device.
305  *
306  * @return
307  *      Monitoring interval on success, negative value otherwise.
308  */
309 int
310 rte_eth_bond_link_monitoring_get(uint8_t bonded_port_id);
311
312
313 /**
314  * Set the period in milliseconds for delaying the disabling of a bonded link
315  * when the link down status has been detected
316  *
317  * @param bonded_port_id        Port ID of bonded device.
318  * @param delay_ms                      Delay period in milliseconds.
319  *
320  * @return
321  *  0 on success, negative value otherwise.
322  */
323 int
324 rte_eth_bond_link_down_prop_delay_set(uint8_t bonded_port_id, uint32_t delay_ms);
325
326 /**
327  * Get the period in milliseconds set for delaying the disabling of a bonded
328  * link when the link down status has been detected
329  *
330  * @param bonded_port_id        Port ID of bonded device.
331  *
332  * @return
333  *  Delay period on success, negative value otherwise.
334  */
335 int
336 rte_eth_bond_link_down_prop_delay_get(uint8_t bonded_port_id);
337
338 /**
339  * Set the period in milliseconds for delaying the enabling of a bonded link
340  * when the link up status has been detected
341  *
342  * @param bonded_port_id        Port ID of bonded device.
343  * @param delay_ms                      Delay period in milliseconds.
344  *
345  * @return
346  *  0 on success, negative value otherwise.
347  */
348 int
349 rte_eth_bond_link_up_prop_delay_set(uint8_t bonded_port_id, uint32_t delay_ms);
350
351 /**
352  * Get the period in milliseconds set for delaying the enabling of a bonded
353  * link when the link up status has been detected
354  *
355  * @param bonded_port_id        Port ID of bonded device.
356  *
357  * @return
358  *  Delay period on success, negative value otherwise.
359  */
360 int
361 rte_eth_bond_link_up_prop_delay_get(uint8_t bonded_port_id);
362
363
364 #ifdef __cplusplus
365 }
366 #endif
367
368 #endif