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