xref: /linux/include/net/bond_3ad.h (revision 9823271dbe1e43d1b7eb7707412d96317fb284d5)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
4  */
5 
6 #ifndef _NET_BOND_3AD_H
7 #define _NET_BOND_3AD_H
8 
9 #include <asm/byteorder.h>
10 #include <linux/skbuff.h>
11 #include <linux/netdevice.h>
12 #include <linux/if_ether.h>
13 
14 /* General definitions */
15 #define PKT_TYPE_LACPDU         cpu_to_be16(ETH_P_SLOW)
16 #define AD_TIMER_INTERVAL       100 /*msec*/
17 
18 #define AD_LACP_SLOW 0
19 #define AD_LACP_FAST 1
20 
21 typedef struct mac_addr {
22 	u8 mac_addr_value[ETH_ALEN];
23 } __packed mac_addr_t;
24 
25 enum {
26 	BOND_AD_STABLE = 0,
27 	BOND_AD_BANDWIDTH = 1,
28 	BOND_AD_COUNT = 2,
29 	BOND_AD_PRIO = 3,
30 };
31 
32 /* rx machine states(43.4.11 in the 802.3ad standard) */
33 typedef enum {
34 	AD_RX_DUMMY,
35 	AD_RX_INITIALIZE,	/* rx Machine */
36 	AD_RX_PORT_DISABLED,	/* rx Machine */
37 	AD_RX_LACP_DISABLED,	/* rx Machine */
38 	AD_RX_EXPIRED,		/* rx Machine */
39 	AD_RX_DEFAULTED,	/* rx Machine */
40 	AD_RX_CURRENT		/* rx Machine */
41 } rx_states_t;
42 
43 /* periodic machine states(43.4.12 in the 802.3ad standard) */
44 typedef enum {
45 	AD_PERIODIC_DUMMY,
46 	AD_NO_PERIODIC,		/* periodic machine */
47 	AD_FAST_PERIODIC,	/* periodic machine */
48 	AD_SLOW_PERIODIC,	/* periodic machine */
49 	AD_PERIODIC_TX		/* periodic machine */
50 } periodic_states_t;
51 
52 /* mux machine states(43.4.13 in the 802.3ad standard) */
53 typedef enum {
54 	AD_MUX_DUMMY,
55 	AD_MUX_DETACHED,	/* mux machine */
56 	AD_MUX_WAITING,		/* mux machine */
57 	AD_MUX_ATTACHED,	/* mux machine */
58 	AD_MUX_COLLECTING,	/* mux machine */
59 	AD_MUX_DISTRIBUTING,	/* mux machine */
60 	AD_MUX_COLLECTING_DISTRIBUTING	/* mux machine */
61 } mux_states_t;
62 
63 /* churn machine states(43.4.17 in the 802.3ad standard) */
64 typedef enum {
65 	 AD_CHURN_MONITOR, /* monitoring for churn */
66 	 AD_CHURN,         /* churn detected (error) */
67 	 AD_NO_CHURN       /* no churn (no error) */
68 } churn_state_t;
69 
70 /* rx indication types */
71 typedef enum {
72 	AD_TYPE_LACPDU = 1,	/* type lacpdu */
73 	AD_TYPE_MARKER		/* type marker */
74 } pdu_type_t;
75 
76 /* rx marker indication types */
77 typedef enum {
78 	AD_MARKER_INFORMATION_SUBTYPE = 1,	/* marker imformation subtype */
79 	AD_MARKER_RESPONSE_SUBTYPE		/* marker response subtype */
80 } bond_marker_subtype_t;
81 
82 /* timers types(43.4.9 in the 802.3ad standard) */
83 typedef enum {
84 	AD_CURRENT_WHILE_TIMER,
85 	AD_ACTOR_CHURN_TIMER,
86 	AD_PERIODIC_TIMER,
87 	AD_PARTNER_CHURN_TIMER,
88 	AD_WAIT_WHILE_TIMER
89 } ad_timers_t;
90 
91 #pragma pack(1)
92 
93 /* Link Aggregation Control Protocol(LACP) data unit structure(43.4.2.2 in the 802.3ad standard) */
94 typedef struct lacpdu {
95 	u8 subtype;		/* = LACP(= 0x01) */
96 	u8 version_number;
97 	u8 tlv_type_actor_info;	/* = actor information(type/length/value) */
98 	u8 actor_information_length;	/* = 20 */
99 	__be16 actor_system_priority;
100 	struct mac_addr actor_system;
101 	__be16 actor_key;
102 	__be16 actor_port_priority;
103 	__be16 actor_port;
104 	u8 actor_state;
105 	u8 reserved_3_1[3];		/* = 0 */
106 	u8 tlv_type_partner_info;	/* = partner information */
107 	u8 partner_information_length;	/* = 20 */
108 	__be16 partner_system_priority;
109 	struct mac_addr partner_system;
110 	__be16 partner_key;
111 	__be16 partner_port_priority;
112 	__be16 partner_port;
113 	u8 partner_state;
114 	u8 reserved_3_2[3];		/* = 0 */
115 	u8 tlv_type_collector_info;	/* = collector information */
116 	u8 collector_information_length;/* = 16 */
117 	__be16 collector_max_delay;
118 	u8 reserved_12[12];
119 	u8 tlv_type_terminator;		/* = terminator */
120 	u8 terminator_length;		/* = 0 */
121 	u8 reserved_50[50];		/* = 0 */
122 } __packed lacpdu_t;
123 
124 typedef struct lacpdu_header {
125 	struct ethhdr hdr;
126 	struct lacpdu lacpdu;
127 } __packed lacpdu_header_t;
128 
129 /* Marker Protocol Data Unit(PDU) structure(43.5.3.2 in the 802.3ad standard) */
130 typedef struct bond_marker {
131 	u8 subtype;		/* = 0x02  (marker PDU) */
132 	u8 version_number;	/* = 0x01 */
133 	u8 tlv_type;		/* = 0x01  (marker information) */
134 	/* = 0x02  (marker response information) */
135 	u8 marker_length;	/* = 0x16 */
136 	u16 requester_port;	/* The number assigned to the port by the requester */
137 	struct mac_addr requester_system;	/* The requester's system id */
138 	u32 requester_transaction_id;		/* The transaction id allocated by the requester, */
139 	u16 pad;		/* = 0 */
140 	u8 tlv_type_terminator;	/* = 0x00 */
141 	u8 terminator_length;	/* = 0x00 */
142 	u8 reserved_90[90];	/* = 0 */
143 } __packed bond_marker_t;
144 
145 typedef struct bond_marker_header {
146 	struct ethhdr hdr;
147 	struct bond_marker marker;
148 } __packed bond_marker_header_t;
149 
150 #pragma pack()
151 
152 struct slave;
153 struct bonding;
154 struct ad_info;
155 struct port;
156 
157 #ifdef __ia64__
158 #pragma pack(8)
159 #endif
160 
161 struct bond_3ad_stats {
162 	atomic64_t lacpdu_rx;
163 	atomic64_t lacpdu_tx;
164 	atomic64_t lacpdu_unknown_rx;
165 	atomic64_t lacpdu_illegal_rx;
166 
167 	atomic64_t marker_rx;
168 	atomic64_t marker_tx;
169 	atomic64_t marker_resp_rx;
170 	atomic64_t marker_resp_tx;
171 	atomic64_t marker_unknown_rx;
172 };
173 
174 /* aggregator structure(43.4.5 in the 802.3ad standard) */
175 typedef struct aggregator {
176 	struct mac_addr aggregator_mac_address;
177 	u16 aggregator_identifier;
178 	bool is_individual;
179 	u16 actor_admin_aggregator_key;
180 	u16 actor_oper_aggregator_key;
181 	struct mac_addr partner_system;
182 	u16 partner_system_priority;
183 	u16 partner_oper_aggregator_key;
184 	u16 receive_state;	/* BOOLEAN */
185 	u16 transmit_state;	/* BOOLEAN */
186 	struct port *lag_ports;
187 	/* ****** PRIVATE PARAMETERS ****** */
188 	struct slave *slave;	/* pointer to the bond slave that this aggregator belongs to */
189 	u16 is_active;		/* BOOLEAN. Indicates if this aggregator is active */
190 	u16 num_of_ports;
191 } aggregator_t;
192 
193 struct port_params {
194 	struct mac_addr system;
195 	u16 system_priority;
196 	u16 key;
197 	u16 port_number;
198 	u16 port_priority;
199 	u16 port_state;
200 };
201 
202 /* port structure(43.4.6 in the 802.3ad standard) */
203 typedef struct port {
204 	u16 actor_port_number;
205 	u16 actor_port_priority;
206 	struct mac_addr actor_system;	/* This parameter is added here although it is not specified in the standard, just for simplification */
207 	u16 actor_system_priority;	/* This parameter is added here although it is not specified in the standard, just for simplification */
208 	u16 actor_port_aggregator_identifier;
209 	bool ntt;
210 	u16 actor_admin_port_key;
211 	u16 actor_oper_port_key;
212 	u8 actor_admin_port_state;
213 	u8 actor_oper_port_state;
214 
215 	struct port_params partner_admin;
216 	struct port_params partner_oper;
217 
218 	bool is_enabled;
219 
220 	/* ****** PRIVATE PARAMETERS ****** */
221 	u16 sm_vars;		/* all state machines variables for this port */
222 	rx_states_t sm_rx_state;	/* state machine rx state */
223 	u16 sm_rx_timer_counter;	/* state machine rx timer counter */
224 	periodic_states_t sm_periodic_state;	/* state machine periodic state */
225 	u16 sm_periodic_timer_counter;	/* state machine periodic timer counter */
226 	mux_states_t sm_mux_state;	/* state machine mux state */
227 	u16 sm_mux_timer_counter;	/* state machine mux timer counter */
228 	u16 sm_tx_timer_counter;	/* state machine tx timer counter
229 					 * (always on - enter to transmit
230 					 *  state 3 time per second)
231 					 */
232 	u16 sm_churn_actor_timer_counter;
233 	u16 sm_churn_partner_timer_counter;
234 	u32 churn_actor_count;
235 	u32 churn_partner_count;
236 	churn_state_t sm_churn_actor_state;
237 	churn_state_t sm_churn_partner_state;
238 	struct slave *slave;		/* pointer to the bond slave that this port belongs to */
239 	struct aggregator __rcu *aggregator;	/* pointer to an aggregator that this port related to */
240 	struct port *next_port_in_aggregator;	/* Next port on the linked list of the parent aggregator */
241 	u32 transaction_id;		/* continuous number for identification of Marker PDU's; */
242 	struct lacpdu lacpdu;		/* the lacpdu that will be sent for this port */
243 } port_t;
244 
245 /* system structure */
246 struct ad_system {
247 	u16 sys_priority;
248 	struct mac_addr sys_mac_addr;
249 };
250 
251 #ifdef __ia64__
252 #pragma pack()
253 #endif
254 
255 /* ========== AD Exported structures to the main bonding code ========== */
256 #define BOND_AD_INFO(bond)   ((bond)->ad_info)
257 #define SLAVE_AD_INFO(slave) ((slave)->ad_info)
258 
259 struct ad_bond_info {
260 	struct ad_system system;	/* 802.3ad system structure */
261 	struct bond_3ad_stats stats;
262 	atomic_t agg_select_timer;		/* Timer to select aggregator after all adapter's hand shakes */
263 	u16 aggregator_identifier;
264 };
265 
266 struct ad_slave_info {
267 	struct aggregator aggregator;	/* 802.3ad aggregator structure */
268 	struct port port;		/* 802.3ad port structure */
269 	struct bond_3ad_stats stats;
270 	u16 id;
271 	u16 port_priority;
272 };
273 
274 static inline const char *bond_3ad_churn_desc(churn_state_t state)
275 {
276 	static const char *const churn_description[] = {
277 		"monitoring",
278 		"churned",
279 		"none",
280 		"unknown"
281 	};
282 	int max_size = ARRAY_SIZE(churn_description);
283 
284 	if (state >= max_size)
285 		state = max_size - 1;
286 
287 	return churn_description[state];
288 }
289 
290 /* ========== AD Exported functions to the main bonding code ========== */
291 void bond_3ad_initialize(struct bonding *bond);
292 void bond_3ad_bind_slave(struct slave *slave);
293 void bond_3ad_unbind_slave(struct slave *slave);
294 void bond_3ad_state_machine_handler(struct work_struct *);
295 void bond_3ad_initiate_agg_selection(struct bonding *bond, int timeout);
296 void bond_3ad_adapter_speed_duplex_changed(struct slave *slave);
297 void bond_3ad_handle_link_change(struct slave *slave, char link);
298 int  bond_3ad_get_active_agg_info(const struct bonding *bond, struct ad_info *ad_info);
299 int  __bond_3ad_get_active_agg_info(const struct bonding *bond,
300 				    struct ad_info *ad_info);
301 int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
302 			 struct slave *slave);
303 int bond_3ad_set_carrier(struct bonding *bond);
304 void bond_3ad_update_lacp_rate(struct bonding *bond);
305 void bond_3ad_update_lacp_active(struct bonding *bond);
306 void bond_3ad_update_ad_actor_settings(struct bonding *bond);
307 int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats);
308 size_t bond_3ad_stats_size(void);
309 #endif /* _NET_BOND_3AD_H */
310 
311