xref: /titanic_50/usr/src/uts/common/sys/aggr_lacp.h (revision f0e308969424e7466232f0795ba1891698c3adf7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_AGGR_LACP_H
27 #define	_SYS_AGGR_LACP_H
28 
29 #include <sys/aggr.h>
30 #include <sys/ethernet.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef _KERNEL
37 
38 /*
39  * 802.3ad LACP version number
40  */
41 #define	LACP_VERSION	0x01	/* LACP version from 802.3ad */
42 #define	LACP_SUBTYPE	0x1
43 
44 /*
45  * TLV type (type/length/value carried in the LACPDU structure.
46  */
47 #define	ACTOR_TLV	0x01	/* actor TLV type */
48 #define	PARTNER_TLV	0x02	/* partner TLV type */
49 #define	COLLECTOR_TLV	0x03	/* collector TLV type */
50 #define	TERMINATOR_TLV	0x00	/* end of message */
51 
52 /*
53  * Length fields as per 802.3ad.
54  */
55 #define	LACP_COLLECTOR_INFO_LEN		0x10
56 #define	LACP_TERMINATOR_INFO_LEN	0x00
57 
58 /* LACP Receive State Machine states */
59 typedef	enum {
60 	LACP_INITIALIZE		= 0,
61 	LACP_PORT_DISABLED	= 1,
62 	LACP_EXPIRED		= 2,
63 	LACP_DISABLED		= 3,
64 	LACP_DEFAULTED		= 4,
65 	LACP_CURRENT		= 5
66 } lacp_receive_state_t;
67 
68 #define	LACP_RECEIVE_STATE_STRINGS {	\
69 	"LACP_INITIALIZE",		\
70 	"LACP_PORT_DISABLED",		\
71 	"LACP_EXPIRED",			\
72 	"LACP_DISABLED",		\
73 	"LACP_DEFAULTED",		\
74 	"LACP_CURRENT"			\
75 }
76 
77 /* LACP Periodic State Machine states */
78 typedef	enum {
79 	LACP_NO_PERIODIC		= 0,
80 	LACP_FAST_PERIODIC		= 1,
81 	LACP_SLOW_PERIODIC		= 2,
82 	LACP_PERIODIC_TX		= 3
83 } lacp_periodic_state_t;
84 
85 #define	LACP_PERIODIC_STRINGS {		\
86 	"LACP_NO_PERIODIC",		\
87 	"LACP_FAST_PERIODIC",		\
88 	"LACP_SLOW_PERIODIC",		\
89 	"LACP_PERIODIC_TX"		\
90 }
91 
92 
93 /* LACP Mux State Machine states */
94 typedef	enum {
95 	LACP_DETACHED			= 0,
96 	LACP_WAITING			= 1,
97 	LACP_ATTACHED			= 2,
98 	LACP_COLLECTING_DISTRIBUTING	= 3
99 } lacp_mux_state_t;
100 
101 #define	LACP_MUX_STRINGS {		\
102 	"LACP_DETACHED",		\
103 	"LACP_WAITING",			\
104 	"LACP_ATTACHED",		\
105 	"LACP_COLLECTING_DISTRIBUTING"	\
106 }
107 
108 /* LACP Churn State Machine states */
109 typedef	enum {
110 	LACP_NO_ACTOR_CHURN		= 0,
111 	LACP_ACTOR_CHURN_MONITOR	= 1,
112 	LACP_ACTOR_CHURN		= 2
113 } lacp_churn_state_t;
114 
115 /*
116  * 802.3ad timer constants.  (IEEE 802.3ad: section 43.4.4)
117  *
118  * All timers specified have a implementation tolerance of +- 250 ms.
119  */
120 #define	FAST_PERIODIC_TIME		1	/* using short timeouts (tx) */
121 #define	SLOW_PERIODIC_TIME		30	/* using long timeouts (tx) */
122 #define	SHORT_TIMEOUT_TIME		3	/* before invalidate LACPDU */
123 #define	LONG_TIMEOUT_TIME		90	/* before invalidate LACPDU */
124 #define	CHURN_DETECTION_TIME		60	/* sync between actor/partner */
125 #define	AGGREGATE_WAIT_TIME		2  /* Delay wait to aggregate links */
126 
127 /*
128  * 802.3ad Variables associated with the system (section 43.4.5)
129  */
130 typedef struct system_info {
131 	struct ether_addr system_id;	/* MAC address assigned by admin */
132 	uint16_t system_priority; 	/* system priority assigned by admin */
133 } system_info_t;
134 
135 typedef struct lacp_timer {
136 	uint32_t	val;
137 	timeout_id_t	id;
138 } lacp_timer_t;
139 
140 /*
141  * 802.3ad Variables associated with each aggregation (section 43.4.6)
142  *	Note: These are on a per aggregation basis.
143  */
144 typedef struct Agg {
145 	uint32_t	AggregatorIdentifier;	/* not used */
146 	boolean_t	IndividualAggr;		/* individual aggregator */
147 	uint32_t	ActorAdminKey;		/* assigned by admin. */
148 	uint32_t	ActorOperKey;		/* assigned by admin. */
149 	struct ether_addr PartnerSystem;	/* partner system ID */
150 	uint32_t	PartnerSystemPriority;	/* partner system priority */
151 	uint32_t	PartnerOperAggrKey;	/* parter oper aggr. key */
152 	boolean_t	ReceiveState;		/* Enabled/Disabled */
153 	boolean_t	TransmitState;		/* Enabled/Disabled */
154 
155 	uint16_t	ActorSystemPriority;	/* System Priority */
156 	uint16_t	CollectorMaxDelay;	/* tens of Usecs */
157 	aggr_lacp_timer_t PeriodicTimer;	/* AGGR_LACP_{LONG,SHORT} */
158 	uint64_t	TimeOfLastOperChange;	/* Time in state */
159 	boolean_t	ready;			/* Ready_N for all ports TRUE */
160 
161 	krwlock_t	gl_lock;
162 } Agg_t;
163 
164 /*
165  * 802.3ad Variables used for managing the operation of
166  * the state machines (section 43.4.8)
167  * Note: These are on a per port basis.
168  */
169 typedef	enum {
170 	AGGR_UNSELECTED,	/* aggregator not selected */
171 	AGGR_SELECTED,		/* aggregator selected */
172 	AGGR_STANDBY		/* port in standby */
173 } lacp_selected_t;
174 
175 typedef struct state_machine {
176 	uint32_t	lacp_on : 1,		/* LACP on or off */
177 			begin : 1,		/* LACP init(or reinit.) */
178 			lacp_enabled : 1,	/* Full/Half Duplex */
179 			port_enabled : 1,	/* Link Up/Down */
180 			actor_churn : 1,	/* failed to converge */
181 			partner_churn : 1,
182 			ready_n : 1,		/* waiting */
183 			port_moved : 1,		/* any port is not waiting */
184 			pad_bits : 24;
185 	/* "Ready" is accessed from the aggregator structure */
186 	lacp_selected_t	selected;	/* SELECTED/UNSELECTED/STANDBY */
187 	uint32_t	current_while_timer_exp; /* # of times timer expired */
188 	lacp_periodic_state_t	periodic_state;	/* State of periodic machine */
189 	lacp_receive_state_t	receive_state;	/* State of receive machine */
190 	lacp_mux_state_t	mux_state;	/* State of mux machine */
191 	lacp_churn_state_t	churn_state;	/* State of churn machine */
192 } state_machine_t;
193 
194 /*
195  * 802.3ad Variables associated with each port (section 43.4.7)
196  */
197 typedef struct aggr_lacp_port {
198 	uint16_t	ActorPortNumber;	/* actor port number */
199 	uint16_t	ActorPortPriority;	/* actor port priority */
200 	uint32_t	ActorPortAggrId;	/* aggregator id */
201 	boolean_t	NTT;			/* need to transmit */
202 	uint16_t	ActorAdminPortKey;	/* admin. port key */
203 	uint16_t	ActorOperPortKey;	/* oper port key */
204 	aggr_lacp_state_t ActorAdminPortState;	/* actor admin. port state */
205 	aggr_lacp_state_t ActorOperPortState;	/* actor oper. port state */
206 
207 	/*
208 	 * partner information
209 	 */
210 	struct ether_addr PartnerAdminSystem;	/* partner admin. system */
211 	struct ether_addr PartnerOperSystem;	/* partner oper.system */
212 	uint16_t PartnerAdminSysPriority;	/* partner admin. sys. pri. */
213 	uint16_t PartnerOperSysPriority;	/* partner oper. sys. pri. */
214 	uint16_t PartnerAdminKey;		/* partner admin. key */
215 	uint16_t PartnerOperKey;		/* partner oper. key */
216 	uint16_t PartnerAdminPortNum;		/* partner admin. port # */
217 	uint16_t PartnerOperPortNum;		/* partner oper. port # */
218 	uint16_t PartnerAdminPortPriority;	/* partner admin. port pri. */
219 	uint16_t PartnerOperPortPriority;	/* partner oper. port pri. */
220 	aggr_lacp_state_t PartnerAdminPortState; /* partner admin port state */
221 	aggr_lacp_state_t PartnerOperPortState; /* partner oper port state */
222 	uint16_t PartnerCollectorMaxDelay;	/* tens of microseconds */
223 
224 	/*
225 	 * State machine and Timer information.
226 	 */
227 	state_machine_t	sm;		/* state machine variables per port */
228 	lacp_timer_t	current_while_timer;
229 	lacp_timer_t	periodic_timer;
230 	lacp_timer_t	wait_while_timer;
231 	hrtime_t	time;
232 } aggr_lacp_port_t;
233 
234 typedef struct lacp_stats_s {
235 	uint64_t	LACPDUsRx;
236 	uint64_t	MarkerPDUsRx;
237 	uint64_t	MarkerResponsePDUsRx;
238 	uint64_t	UnknownRx;
239 	uint64_t	IllegalRx;
240 	uint64_t	LACPDUsTx;
241 	uint64_t	MarkerPDUsTx;
242 	uint64_t	MarkerResponsePDUsTx;
243 } lacp_stats_t;
244 
245 /*
246  * 802.3ad protocol information
247  */
248 /*
249  * Actor/Partner information
250  */
251 typedef struct link_info {
252 	uint8_t			tlv_type;	/* type/length/value */
253 	uint8_t			information_len; /* information length */
254 	uint16_t		system_priority; /* system priority */
255 	struct ether_addr	system_id;	/* encoded as MAC address */
256 	uint16_t		key;		/* operational key */
257 	uint16_t		port_priority;	/* port priority */
258 	uint16_t		port;		/* port */
259 	aggr_lacp_state_t	state;		/* state info */
260 	uint8_t			reserved[3];	/* reserved */
261 } link_info_t;
262 
263 /*
264  * Link Aggregation Control Protocol (LACPDU) structure
265  */
266 typedef struct lacp {
267 	uint8_t			subtype;	/* = LACP */
268 	uint8_t			version;	/* LACP version */
269 	link_info_t		actor_info;	/* actor information */
270 	link_info_t		partner_info;	/* partner information */
271 	uint8_t			tlv_collector;	/* collector tlv */
272 	uint8_t			collector_len;	/* collector len */
273 	uint16_t		collector_max_delay; /* tens of miscrosecond */
274 	uint8_t			reserved[12];	/* reserved */
275 	uint8_t			tlv_terminator;	/* terminator tlv */
276 	uint8_t			terminator_len;	/* terminator len */
277 	uint8_t			lacp_reserved[50];	/* reserved */
278 } lacp_t;
279 
280 /*
281  * Marker protocol
282  */
283 
284 #define	MARKER_VERSION	0x1		/* 802.3ad Marker version number */
285 #define	MARKER_SUBTYPE	0x2
286 #define	MARKER_INFO_RESPONSE_LENGTH	16
287 
288 /*
289  * marker TLV_type
290  */
291 #define	MARKER_INFO_TLV		0x01	/* marker information */
292 #define	MARKER_RESPONSE_TLV	0x02	/* marker response information */
293 
294 typedef struct marker_pdu {
295 	struct ether_addr	dest_addr;	/* Slow protocol multicast */
296 	struct ether_addr	src_addr;	/* Source address */
297 	uint16_t		type;		/* Slow protocol type */
298 	uint8_t			subtype;	/* = Marker 0x2 */
299 	uint8_t			version;	/* Marker version 0x01 */
300 	uint8_t			tlv_marker;	/* marker tlv */
301 	uint8_t			marker_len;	/* marker len */
302 	uint16_t		requestor_port; /* requestor port */
303 	struct ether_addr	system_id;	/* requestor system */
304 	uint8_t			transaction_id[4];	/* transaction id */
305 	uint8_t			pad[2];		/* zeros to align */
306 	uint8_t			reserved[90];	/* reserved */
307 	uint32_t		fcs;		/* generated by MAC */
308 } marker_pdu_t;
309 
310 /*
311  * 802.3ad Link Aggregation Group Identifier (IEEE 802.3ad 43.3.6)
312  * port identifire = port priority and port number.
313  */
314 typedef struct lag_id {
315 	uint16_t		system_priority;	/* system priority */
316 	struct ether_addr	system_id;		/* system identifier */
317 	uint16_t		oper_key;		/* operational key */
318 	uint16_t		port_priority;		/* port priority */
319 	uint16_t		port_number;		/* 0: aggregatable */
320 } lag_id_t;
321 
322 #endif /* _KERNEL */
323 
324 #ifdef	__cplusplus
325 }
326 #endif
327 
328 #endif	/* _SYS_AGGR_LACP_H */
329