Imported Upstream version 16.04
[deb_dpdk.git] / drivers / net / bonding / rte_eth_bond_8023ad_private.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_PRIVATE_H_
35 #define RTE_ETH_BOND_8023AD_PRIVATE_H_
36
37 #include <stdint.h>
38
39 #include <rte_ether.h>
40 #include <rte_byteorder.h>
41 #include <rte_atomic.h>
42
43 #include "rte_eth_bond_8023ad.h"
44
45 #define BOND_MODE_8023AX_UPDATE_TIMEOUT_MS  100
46 /** Maximum number of packets to one slave queued in TX ring. */
47 #define BOND_MODE_8023AX_SLAVE_RX_PKTS        3
48 /** Maximum number of LACP packets from one slave queued in TX ring. */
49 #define BOND_MODE_8023AX_SLAVE_TX_PKTS        1
50 /**
51  * Timeouts deffinitions (5.4.4 in 802.1AX documentation).
52  */
53 #define BOND_8023AD_FAST_PERIODIC_MS                900
54 #define BOND_8023AD_SLOW_PERIODIC_MS              29000
55 #define BOND_8023AD_SHORT_TIMEOUT_MS               3000
56 #define BOND_8023AD_LONG_TIMEOUT_MS               90000
57 #define BOND_8023AD_CHURN_DETECTION_TIMEOUT_MS    60000
58 #define BOND_8023AD_AGGREGATE_WAIT_TIMEOUT_MS      2000
59 #define BOND_8023AD_TX_MACHINE_PERIOD_MS            500
60 #define BOND_8023AD_RX_MARKER_PERIOD_MS            2000
61
62 /**
63  * Interval of showing warning message from state machines. All messages will
64  * be held (and gathered together) to prevent flooding.
65  * This is no parto of 802.1AX standard.
66  */
67 #define BOND_8023AD_WARNINGS_PERIOD_MS             1000
68
69
70
71 /**
72  * State machine flags
73  */
74 #define SM_FLAGS_BEGIN                      0x0001
75 #define SM_FLAGS_LACP_ENABLED               0x0002
76 #define SM_FLAGS_ACTOR_CHURN                0x0004
77 #define SM_FLAGS_PARTNER_CHURN              0x0008
78 #define SM_FLAGS_MOVED                      0x0100
79 #define SM_FLAGS_PARTNER_SHORT_TIMEOUT      0x0200
80 #define SM_FLAGS_NTT                        0x0400
81
82 #define BOND_LINK_FULL_DUPLEX_KEY           0x01
83 #define BOND_LINK_SPEED_KEY_10M             0x02
84 #define BOND_LINK_SPEED_KEY_100M            0x04
85 #define BOND_LINK_SPEED_KEY_1000M           0x08
86 #define BOND_LINK_SPEED_KEY_10G             0x10
87 #define BOND_LINK_SPEED_KEY_20G             0x11
88 #define BOND_LINK_SPEED_KEY_40G             0x12
89
90 #define WRN_RX_MARKER_TO_FAST      0x01
91 #define WRN_UNKNOWN_SLOW_TYPE      0x02
92 #define WRN_UNKNOWN_MARKER_TYPE    0x04
93 #define WRN_NOT_LACP_CAPABLE       0x08
94 #define WRN_RX_QUEUE_FULL       0x10
95 #define WRN_TX_QUEUE_FULL       0x20
96
97 #define CHECK_FLAGS(_variable, _f) ((_variable) & (_f))
98 #define SET_FLAGS(_variable, _f) ((_variable) |= (_f))
99 #define CLEAR_FLAGS(_variable, _f) ((_variable) &= ~(_f))
100
101 #define SM_FLAG(_p, _f) (!!CHECK_FLAGS((_p)->sm_flags, SM_FLAGS_ ## _f))
102 #define SM_FLAG_SET(_p, _f) SET_FLAGS((_p)->sm_flags, SM_FLAGS_ ## _f)
103 #define SM_FLAG_CLR(_p, _f) CLEAR_FLAGS((_p)->sm_flags, SM_FLAGS_ ## _f)
104
105 #define ACTOR_STATE(_p, _f) (!!CHECK_FLAGS((_p)->actor_state, STATE_ ## _f))
106 #define ACTOR_STATE_SET(_p, _f) SET_FLAGS((_p)->actor_state, STATE_ ## _f)
107 #define ACTOR_STATE_CLR(_p, _f) CLEAR_FLAGS((_p)->actor_state, STATE_ ## _f)
108
109 #define PARTNER_STATE(_p, _f) (!!CHECK_FLAGS((_p)->partner_state, STATE_ ## _f))
110 #define PARTNER_STATE_SET(_p, _f) SET_FLAGS((_p)->partner_state, STATE_ ## _f)
111 #define PARTNER_STATE_CLR(_p, _f) CLEAR_FLAGS((_p)->partner_state, STATE_ ## _f)
112
113 /** Variables associated with each port (5.4.7 in 802.1AX documentation). */
114 struct port {
115         /**
116          * The operational values of the Actor's state parameters. Bitmask
117          * of port states.
118          */
119         uint8_t actor_state;
120
121         /** The operational Actor's port parameters */
122         struct port_params actor;
123
124         /**
125          * The operational value of the Actor's view of the current values of
126          * the Partner's state parameters. The Actor sets this variable either
127          * to the value received from the Partner in an LACPDU, or to the value
128          * of Partner_Admin_Port_State. Bitmask of port states.
129          */
130         uint8_t partner_state;
131
132         /** The operational Partner's port parameters */
133         struct port_params partner;
134
135         /* Additional port parameters not listed in documentation */
136         /** State machine flags */
137         uint16_t sm_flags;
138         enum rte_bond_8023ad_selection selected;
139
140         uint64_t current_while_timer;
141         uint64_t periodic_timer;
142         uint64_t wait_while_timer;
143         uint64_t tx_machine_timer;
144         uint64_t tx_marker_timer;
145         /* Agregator parameters */
146         /** Used aggregator port ID */
147         uint16_t aggregator_port_id;
148
149         /** Memory pool used to allocate rings */
150         struct rte_mempool *mbuf_pool;
151
152         /** Ring of LACP packets from RX burst function */
153         struct rte_ring *rx_ring;
154
155         /** Ring of slow protocol packets (LACP and MARKERS) to TX burst function */
156         struct rte_ring *tx_ring;
157
158         /** Timer which is also used as mutex. If is 0 (not running) RX marker
159          * packet might be responded. Otherwise shall be dropped. It is zeroed in
160          * mode 4 callback function after expire. */
161         volatile uint64_t rx_marker_timer;
162
163         uint64_t warning_timer;
164         volatile uint16_t warnings_to_show;
165 };
166
167 struct mode8023ad_private {
168         uint64_t fast_periodic_timeout;
169         uint64_t slow_periodic_timeout;
170         uint64_t short_timeout;
171         uint64_t long_timeout;
172         uint64_t aggregate_wait_timeout;
173         uint64_t tx_period_timeout;
174         uint64_t rx_marker_timeout;
175         uint64_t update_timeout_us;
176 };
177
178 /**
179  * @internal
180  * The pool of *port* structures. The size of the pool
181  * is configured at compile-time in the <rte_eth_bond_8023ad.c> file.
182  */
183 extern struct port mode_8023ad_ports[];
184
185 /* Forward declaration */
186 struct bond_dev_private;
187
188 /**
189  * @internal
190  *
191  * Get configuration of bonded interface.
192  *
193  *
194  * @param dev Bonded interface
195  * @param conf returned configuration
196  */
197 void
198 bond_mode_8023ad_conf_get(struct rte_eth_dev *dev,
199                 struct rte_eth_bond_8023ad_conf *conf);
200
201 /**
202  * @internal
203  *
204  * Set mode 4 configuration of bonded interface.
205  *
206  * @pre Bonded interface must be stopped.
207  *
208  * @param dev Bonded interface
209  * @param conf new configuration. If NULL set default configuration.
210  */
211 void
212 bond_mode_8023ad_setup(struct rte_eth_dev *dev,
213                 struct rte_eth_bond_8023ad_conf *conf);
214
215 /**
216  * @internal
217  *
218  * Enables 802.1AX mode and all active slaves on bonded interface.
219  *
220  * @param dev Bonded interface
221  * @return
222  *  0 on success, negative value otherwise.
223  */
224 int
225 bond_mode_8023ad_enable(struct rte_eth_dev *dev);
226
227 /**
228  * @internal
229  *
230  * Disables 802.1AX mode of the bonded interface and slaves.
231  *
232  * @param dev Bonded interface
233  * @return
234  *   0 on success, negative value otherwise.
235  */
236 int bond_mode_8023ad_disable(struct rte_eth_dev *dev);
237
238 /**
239  * @internal
240  *
241  * Starts 802.3AX state machines management logic.
242  * @param dev Bonded interface
243  * @return
244  *   0 if machines was started, 1 if machines was already running,
245  *   negative value otherwise.
246  */
247 int
248 bond_mode_8023ad_start(struct rte_eth_dev *dev);
249
250 /**
251  * @internal
252  *
253  * Stops 802.3AX state machines management logic.
254  * @param dev Bonded interface
255  * @return
256  *   0 if this call stopped state machines, -ENOENT if alarm was not set.
257  */
258 void
259 bond_mode_8023ad_stop(struct rte_eth_dev *dev);
260
261 /**
262  * @internal
263  *
264  * Passes given slow packet to state machines management logic.
265  * @param internals Bonded device private data.
266  * @param slave_id Slave port id.
267  * @param slot_pkt Slow packet.
268  */
269 void
270 bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,
271         uint8_t slave_id, struct rte_mbuf *pkt);
272
273 /**
274  * @internal
275  *
276  * Appends given slave used slave
277  *
278  * @param dev       Bonded interface.
279  * @param port_id   Slave port ID to be added
280  *
281  * @return
282  *  0 on success, negative value otherwise.
283  */
284 void
285 bond_mode_8023ad_activate_slave(struct rte_eth_dev *dev, uint8_t port_id);
286
287 /**
288  * @internal
289  *
290  * Denitializes and removes given slave from 802.1AX mode.
291  *
292  * @param dev       Bonded interface.
293  * @param slave_num Position of slave in active_slaves array
294  *
295  * @return
296  *  0 on success, negative value otherwise.
297  */
298 int
299 bond_mode_8023ad_deactivate_slave(struct rte_eth_dev *dev, uint8_t slave_pos);
300
301 /**
302  * Updates state when MAC was changed on bonded device or one of its slaves.
303  * @param bond_dev Bonded device
304  */
305 void
306 bond_mode_8023ad_mac_address_update(struct rte_eth_dev *bond_dev);
307
308 #endif /* RTE_ETH_BOND_8023AD_H_ */