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