1d353c7348708129ec26ea46fffe81a385bf6c76
[deb_dpdk.git] / drivers / net / bonding / rte_eth_bond_8023ad.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_8023AD_H_
35 #define RTE_ETH_BOND_8023AD_H_
36
37 #include <rte_ether.h>
38
39 #ifdef __cplusplus
40 extern "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
67 typedef void (*rte_eth_bond_8023ad_ext_slowrx_fn)(uint8_t slave_id,
68                                                   struct rte_mbuf *lacp_pkt);
69
70 enum rte_bond_8023ad_selection {
71         UNSELECTED,
72         STANDBY,
73         SELECTED
74 };
75
76 enum rte_bond_8023ad_agg_selection {
77         AGG_BANDWIDTH,
78         AGG_COUNT,
79         AGG_STABLE
80 };
81
82 /** Generic slow protocol structure */
83 struct slow_protocol {
84         uint8_t subtype;
85         uint8_t reserved_119[119];
86 } __attribute__((__packed__));
87
88 /** Generic slow protocol frame type structure */
89 struct slow_protocol_frame {
90         struct ether_hdr eth_hdr;
91         struct slow_protocol slow_protocol;
92 } __attribute__((__packed__));
93
94 struct port_params {
95         uint16_t system_priority;
96         /**< System priority (unused in current implementation) */
97         struct ether_addr system;
98         /**< System ID - Slave MAC address, same as bonding MAC address */
99         uint16_t key;
100         /**< Speed information (implementation dependednt) and duplex. */
101         uint16_t port_priority;
102         /**< Priority of this (unused in current implementation) */
103         uint16_t port_number;
104         /**< Port number. It corresponds to slave port id. */
105 } __attribute__((__packed__));
106
107 struct lacpdu_actor_partner_params {
108         uint8_t tlv_type_info;
109         uint8_t info_length;
110         struct port_params port_params;
111         uint8_t state;
112         uint8_t reserved_3[3];
113 } __attribute__((__packed__));
114
115 /** LACPDU structure (5.4.2 in 802.1AX documentation). */
116 struct lacpdu {
117         uint8_t subtype;
118         uint8_t version_number;
119
120         struct lacpdu_actor_partner_params actor;
121         struct lacpdu_actor_partner_params partner;
122
123         uint8_t tlv_type_collector_info;
124         uint8_t collector_info_length;
125         uint16_t collector_max_delay;
126         uint8_t reserved_12[12];
127
128         uint8_t tlv_type_terminator;
129         uint8_t terminator_length;
130         uint8_t reserved_50[50];
131 } __attribute__((__packed__));
132
133 /** LACPDU frame: Contains ethernet header and LACPDU. */
134 struct lacpdu_header {
135         struct ether_hdr eth_hdr;
136         struct lacpdu lacpdu;
137 } __attribute__((__packed__));
138
139 struct marker {
140         uint8_t subtype;
141         uint8_t version_number;
142
143         uint8_t tlv_type_marker;
144         uint8_t info_length;
145         uint16_t requester_port;
146         struct ether_addr requester_system;
147         uint32_t requester_transaction_id;
148         uint8_t reserved_2[2];
149
150         uint8_t tlv_type_terminator;
151         uint8_t terminator_length;
152         uint8_t reserved_90[90];
153 } __attribute__((__packed__));
154
155 struct marker_header {
156         struct ether_hdr eth_hdr;
157         struct marker marker;
158 } __attribute__((__packed__));
159
160 struct rte_eth_bond_8023ad_conf {
161         uint32_t fast_periodic_ms;
162         uint32_t slow_periodic_ms;
163         uint32_t short_timeout_ms;
164         uint32_t long_timeout_ms;
165         uint32_t aggregate_wait_timeout_ms;
166         uint32_t tx_period_ms;
167         uint32_t rx_marker_period_ms;
168         uint32_t update_timeout_ms;
169         rte_eth_bond_8023ad_ext_slowrx_fn slowrx_cb;
170         enum rte_bond_8023ad_agg_selection agg_selection;
171 };
172
173 struct rte_eth_bond_8023ad_slave_info {
174         enum rte_bond_8023ad_selection selected;
175         uint8_t actor_state;
176         struct port_params actor;
177         uint8_t partner_state;
178         struct port_params partner;
179         uint8_t agg_port_id;
180 };
181
182 /**
183  * @internal
184  *
185  * Function returns current configuration of 802.3AX mode.
186  *
187  * @param port_id   Bonding device id
188  * @param conf          Pointer to timeout structure.
189  *
190  * @return
191  *   0 - if ok
192  *   -EINVAL if conf is NULL
193  */
194 int
195 rte_eth_bond_8023ad_conf_get(uint8_t port_id,
196                 struct rte_eth_bond_8023ad_conf *conf);
197 int
198 rte_eth_bond_8023ad_conf_get_v20(uint8_t port_id,
199                 struct rte_eth_bond_8023ad_conf *conf);
200 int
201 rte_eth_bond_8023ad_conf_get_v1607(uint8_t port_id,
202                 struct rte_eth_bond_8023ad_conf *conf);
203 int
204 rte_eth_bond_8023ad_conf_get_v1708(uint8_t port_id,
205                 struct rte_eth_bond_8023ad_conf *conf);
206
207 /**
208  * @internal
209  *
210  * Function set new configuration of 802.3AX mode.
211  *
212  * @param port_id   Bonding device id
213  * @param conf          Configuration, if NULL set default configuration.
214  * @return
215  *   0 - if ok
216  *   -EINVAL if configuration is invalid.
217  */
218 int
219 rte_eth_bond_8023ad_setup(uint8_t port_id,
220                 struct rte_eth_bond_8023ad_conf *conf);
221 int
222 rte_eth_bond_8023ad_setup_v20(uint8_t port_id,
223                 struct rte_eth_bond_8023ad_conf *conf);
224 int
225 rte_eth_bond_8023ad_setup_v1607(uint8_t port_id,
226                 struct rte_eth_bond_8023ad_conf *conf);
227 int
228 rte_eth_bond_8023ad_setup_v1708(uint8_t port_id,
229                 struct rte_eth_bond_8023ad_conf *conf);
230
231 /**
232  * @internal
233  *
234  * Function returns current state of given slave device.
235  *
236  * @param slave_id  Port id of valid slave.
237  * @param conf          buffer for configuration
238  * @return
239  *   0 - if ok
240  *   -EINVAL if conf is NULL or slave id is invalid (not a slave of given
241  *       bonded device or is not inactive).
242  */
243 int
244 rte_eth_bond_8023ad_slave_info(uint8_t port_id, uint8_t slave_id,
245                 struct rte_eth_bond_8023ad_slave_info *conf);
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 /**
252  * Configure a slave port to start collecting.
253  *
254  * @param port_id       Bonding device id
255  * @param slave_id      Port id of valid slave.
256  * @param enabled       Non-zero when collection enabled.
257  * @return
258  *   0 - if ok
259  *   -EINVAL if slave is not valid.
260  */
261 int
262 rte_eth_bond_8023ad_ext_collect(uint8_t port_id, uint8_t slave_id, int enabled);
263
264 /**
265  * Get COLLECTING flag from slave port actor state.
266  *
267  * @param port_id       Bonding device id
268  * @param slave_id      Port id of valid slave.
269  * @return
270  *   0 - if not set
271  *   1 - if set
272  *   -EINVAL if slave is not valid.
273  */
274 int
275 rte_eth_bond_8023ad_ext_collect_get(uint8_t port_id, uint8_t slave_id);
276
277 /**
278  * Configure a slave port to start distributing.
279  *
280  * @param port_id       Bonding device id
281  * @param slave_id      Port id of valid slave.
282  * @param enabled       Non-zero when distribution enabled.
283  * @return
284  *   0 - if ok
285  *   -EINVAL if slave is not valid.
286  */
287 int
288 rte_eth_bond_8023ad_ext_distrib(uint8_t port_id, uint8_t slave_id, int enabled);
289
290 /**
291  * Get DISTRIBUTING flag from slave port actor state.
292  *
293  * @param port_id       Bonding device id
294  * @param slave_id      Port id of valid slave.
295  * @return
296  *   0 - if not set
297  *   1 - if set
298  *   -EINVAL if slave is not valid.
299  */
300 int
301 rte_eth_bond_8023ad_ext_distrib_get(uint8_t port_id, uint8_t slave_id);
302
303 /**
304  * LACPDU transmit path for external 802.3ad state machine.  Caller retains
305  * ownership of the packet on failure.
306  *
307  * @param port_id       Bonding device id
308  * @param slave_id      Port ID of valid slave device.
309  * @param lacp_pkt      mbuf containing LACPDU.
310  *
311  * @return
312  *   0 on success, negative value otherwise.
313  */
314 int
315 rte_eth_bond_8023ad_ext_slowtx(uint8_t port_id, uint8_t slave_id,
316                 struct rte_mbuf *lacp_pkt);
317
318 /**
319  * Enable dedicated hw queues for 802.3ad control plane traffic on on slaves
320  *
321  * This function creates an additional tx and rx queue on each slave for
322  * dedicated 802.3ad control plane traffic . A flow filtering rule is
323  * programmed on each slave to redirect all LACP slow packets to that rx queue
324  * for processing in the LACP state machine, this removes the need to filter
325  * these packets in the bonded devices data path. The additional tx queue is
326  * used to enable the LACP state machine to enqueue LACP packets directly to
327  * slave hw independently of the bonded devices data path.
328  *
329  * To use this feature all slaves must support the programming of the flow
330  * filter rule required for rx and have enough queues that one rx and tx queue
331  * can be reserved for the LACP state machines control packets.
332  *
333  * Bonding port must be stopped to change this configuration.
334  *
335  * @param port_id      Bonding device id
336  *
337  * @return
338  *   0 on success, negative value otherwise.
339  */
340 int
341 rte_eth_bond_8023ad_dedicated_queues_enable(uint8_t port_id);
342
343 /**
344  * Disable slow queue on slaves
345  *
346  * This function disables hardware slow packet filter.
347  *
348  * Bonding port must be stopped to change this configuration.
349  *
350  * @see rte_eth_bond_8023ad_slow_pkt_hw_filter_enable
351  *
352  * @param port_id      Bonding device id
353  * @return
354  *   0 on success, negative value otherwise.
355  *
356  */
357 int
358 rte_eth_bond_8023ad_dedicated_queues_disable(uint8_t port_id);
359
360 /*
361  * Get aggregator mode for 8023ad
362  * @param port_id Bonding device id
363  *
364  * @return
365  *   agregator mode on success, negative value otherwise
366  */
367 int
368 rte_eth_bond_8023ad_agg_selection_get(uint8_t port_id);
369
370 /**
371  * Set aggregator mode for 8023ad
372  * @param port_id Bonding device id
373  * @return
374  *   0 on success, negative value otherwise
375  */
376 int
377 rte_eth_bond_8023ad_agg_selection_set(uint8_t port_id,
378                 enum rte_bond_8023ad_agg_selection agg_selection);
379 #endif /* RTE_ETH_BOND_8023AD_H_ */