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