xref: /onnv-gate/usr/src/uts/common/sys/aggr_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_AGGR_IMPL_H
28*0Sstevel@tonic-gate #define	_SYS_AGGR_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/mac.h>
34*0Sstevel@tonic-gate #include <sys/ght.h>
35*0Sstevel@tonic-gate #include <sys/aggr_lacp.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifdef	__cplusplus
38*0Sstevel@tonic-gate extern "C" {
39*0Sstevel@tonic-gate #endif
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #ifdef _KERNEL
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #define	AGGR_MINOR_CTL	0			/* control interface minor */
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate /* flags for aggr_grp_modify() */
46*0Sstevel@tonic-gate #define	AGGR_MODIFY_POLICY		0x01
47*0Sstevel@tonic-gate #define	AGGR_MODIFY_MAC			0x02
48*0Sstevel@tonic-gate #define	AGGR_MODIFY_LACP_MODE		0x04
49*0Sstevel@tonic-gate #define	AGGR_MODIFY_LACP_TIMER		0x08
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate /*
52*0Sstevel@tonic-gate  * A link aggregation MAC port.
53*0Sstevel@tonic-gate  * Note that lp_next is protected by the lg_lock of the group the
54*0Sstevel@tonic-gate  * port is part of.
55*0Sstevel@tonic-gate  */
56*0Sstevel@tonic-gate typedef struct aggr_port_s {
57*0Sstevel@tonic-gate 	struct aggr_port_s *lp_next;
58*0Sstevel@tonic-gate 	struct aggr_grp_s *lp_grp;		/* back ptr to group */
59*0Sstevel@tonic-gate 	char		lp_devname[MAXNAMELEN + 1];
60*0Sstevel@tonic-gate 	uint8_t		lp_addr[ETHERADDRL];	/* port MAC address */
61*0Sstevel@tonic-gate 	uint32_t	lp_refs;		/* refcount */
62*0Sstevel@tonic-gate 	aggr_port_state_t lp_state;
63*0Sstevel@tonic-gate 	uint32_t	lp_started : 1,
64*0Sstevel@tonic-gate 			lp_tx_enabled : 1,
65*0Sstevel@tonic-gate 			lp_collector_enabled : 1,
66*0Sstevel@tonic-gate 			lp_promisc_on : 1,
67*0Sstevel@tonic-gate 			lp_closing : 1,
68*0Sstevel@tonic-gate 			/*
69*0Sstevel@tonic-gate 			 * Indicates whether it is in the process of setting
70*0Sstevel@tonic-gate 			 * MAC address to the aggregation group MAC
71*0Sstevel@tonic-gate 			 */
72*0Sstevel@tonic-gate 			lp_set_grpmac : 1,
73*0Sstevel@tonic-gate 			lp_pad_bits : 26;
74*0Sstevel@tonic-gate 	uint_t		lp_port;
75*0Sstevel@tonic-gate 	mac_handle_t	lp_mh;
76*0Sstevel@tonic-gate 	const mac_info_t *lp_mip;
77*0Sstevel@tonic-gate 	mac_notify_handle_t lp_mnh;
78*0Sstevel@tonic-gate 	mac_rx_handle_t	lp_mrh;
79*0Sstevel@tonic-gate 	krwlock_t	lp_lock;
80*0Sstevel@tonic-gate 	uint_t		lp_tx_idx;		/* idx in group's tx array */
81*0Sstevel@tonic-gate 	uint64_t	lp_ifspeed;
82*0Sstevel@tonic-gate 	link_state_t	lp_link_state;
83*0Sstevel@tonic-gate 	link_duplex_t	lp_link_duplex;
84*0Sstevel@tonic-gate 	uint64_t	lp_stat[MAC_NSTAT];
85*0Sstevel@tonic-gate 	aggr_lacp_port_t lp_lacp;		/* LACP state */
86*0Sstevel@tonic-gate 	lacp_stats_t	lp_lacp_stats;
87*0Sstevel@tonic-gate 	mac_tx_t	lp_tx;
88*0Sstevel@tonic-gate 	void		*lp_tx_arg;
89*0Sstevel@tonic-gate } aggr_port_t;
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate /*
92*0Sstevel@tonic-gate  * A link aggregation group.
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  * The following per-group flags are defined:
95*0Sstevel@tonic-gate  *
96*0Sstevel@tonic-gate  * - lg_addr_fixed: set when the MAC address has been explicitely set
97*0Sstevel@tonic-gate  *   when the group was created, or by a m_unicst_set() request.
98*0Sstevel@tonic-gate  *   If this flag is not set, the MAC address of the group will be
99*0Sstevel@tonic-gate  *   set to the first port that is added to the group.
100*0Sstevel@tonic-gate  *
101*0Sstevel@tonic-gate  * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether
102*0Sstevel@tonic-gate  *   the MAC address was initialized according to the members of the group.
103*0Sstevel@tonic-gate  *   When set, the lg_port field points to the port from which the
104*0Sstevel@tonic-gate  *   MAC address was initialized.
105*0Sstevel@tonic-gate  *
106*0Sstevel@tonic-gate  */
107*0Sstevel@tonic-gate typedef struct aggr_grp_s {
108*0Sstevel@tonic-gate 	krwlock_t	lg_lock;
109*0Sstevel@tonic-gate 	uint16_t	lg_key;			/* key (group port number) */
110*0Sstevel@tonic-gate 	uint32_t	lg_refs;		/* refcount */
111*0Sstevel@tonic-gate 	uint16_t	lg_nports;		/* number of MAC ports */
112*0Sstevel@tonic-gate 	uint8_t		lg_addr[ETHERADDRL];	/* group MAC address */
113*0Sstevel@tonic-gate 	ghte_t		lg_hte;
114*0Sstevel@tonic-gate 	uint16_t
115*0Sstevel@tonic-gate 			lg_addr_fixed : 1,	/* fixed MAC address? */
116*0Sstevel@tonic-gate 			lg_started : 1,		/* group started? */
117*0Sstevel@tonic-gate 			lg_promisc : 1,		/* in promiscuous mode? */
118*0Sstevel@tonic-gate 			lg_closing : 1,
119*0Sstevel@tonic-gate 			lg_pad_bits : 12;
120*0Sstevel@tonic-gate 	aggr_port_t	*lg_ports;		/* list of configured ports */
121*0Sstevel@tonic-gate 	aggr_port_t	*lg_mac_addr_port;
122*0Sstevel@tonic-gate 	mac_t		lg_mac;
123*0Sstevel@tonic-gate 	uint_t		lg_rx_resources;
124*0Sstevel@tonic-gate 	uint_t		lg_nattached_ports;
125*0Sstevel@tonic-gate 	uint_t		lg_ntx_ports;
126*0Sstevel@tonic-gate 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
127*0Sstevel@tonic-gate 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
128*0Sstevel@tonic-gate 	uint32_t	lg_tx_policy;		/* outbound policy */
129*0Sstevel@tonic-gate 	uint64_t	lg_ifspeed;
130*0Sstevel@tonic-gate 	link_state_t	lg_link_state;
131*0Sstevel@tonic-gate 	link_duplex_t	lg_link_duplex;
132*0Sstevel@tonic-gate 	uint64_t	lg_stat[MAC_NSTAT];
133*0Sstevel@tonic-gate 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
134*0Sstevel@tonic-gate 	Agg_t		aggr;			/* 802.3ad data */
135*0Sstevel@tonic-gate } aggr_grp_t;
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate #define	AGGR_LACP_LOCK(grp)	mutex_enter(&(grp)->aggr.gl_lock);
138*0Sstevel@tonic-gate #define	AGGR_LACP_UNLOCK(grp)	mutex_exit(&(grp)->aggr.gl_lock);
139*0Sstevel@tonic-gate #define	AGGR_LACP_LOCK_HELD(grp) MUTEX_HELD(&(grp)->aggr.gl_lock)
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate #define	AGGR_GRP_REFHOLD(grp) {			\
142*0Sstevel@tonic-gate 	atomic_add_32(&(grp)->lg_refs, 1);	\
143*0Sstevel@tonic-gate 	ASSERT((grp)->lg_refs != 0);		\
144*0Sstevel@tonic-gate }
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate #define	AGGR_GRP_REFRELE(grp) {					\
147*0Sstevel@tonic-gate 	ASSERT((grp)->lg_refs != 0);				\
148*0Sstevel@tonic-gate 	membar_exit();						\
149*0Sstevel@tonic-gate 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
150*0Sstevel@tonic-gate 		aggr_grp_free(grp);				\
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate #define	AGGR_PORT_REFHOLD(port) {		\
154*0Sstevel@tonic-gate 	atomic_add_32(&(port)->lp_refs, 1);	\
155*0Sstevel@tonic-gate 	ASSERT((port)->lp_refs != 0);		\
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate #define	AGGR_PORT_REFRELE(port) {				\
159*0Sstevel@tonic-gate 	ASSERT((port)->lp_refs != 0);				\
160*0Sstevel@tonic-gate 	membar_exit();						\
161*0Sstevel@tonic-gate 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
162*0Sstevel@tonic-gate 		aggr_port_free(port);				\
163*0Sstevel@tonic-gate }
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate extern dev_info_t *aggr_dip;
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate extern int aggr_open(dev_t *, int, int, cred_t *);
168*0Sstevel@tonic-gate extern int aggr_close(dev_t, int, int, cred_t *);
169*0Sstevel@tonic-gate extern int aggr_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate typedef int (*aggr_grp_info_new_grp_fn_t)(void *, uint32_t, uchar_t *,
172*0Sstevel@tonic-gate     boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t, aggr_lacp_timer_t);
173*0Sstevel@tonic-gate typedef int (*aggr_grp_info_new_port_fn_t)(void *, char *, uint32_t,
174*0Sstevel@tonic-gate     uchar_t *, aggr_port_state_t, aggr_lacp_state_t *);
175*0Sstevel@tonic-gate typedef void (*aggr_grp_walker_fn_t)(aggr_grp_t *, void *);
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate extern void aggr_grp_init(void);
178*0Sstevel@tonic-gate extern int aggr_grp_fini(void);
179*0Sstevel@tonic-gate extern int aggr_grp_create(uint32_t, uint_t, laioc_port_t *, uint32_t,
180*0Sstevel@tonic-gate     boolean_t, uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
181*0Sstevel@tonic-gate extern int aggr_grp_delete(uint32_t);
182*0Sstevel@tonic-gate extern void aggr_grp_free(aggr_grp_t *);
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate extern int aggr_grp_info(uint_t *, uint32_t, void *,
185*0Sstevel@tonic-gate     aggr_grp_info_new_grp_fn_t, aggr_grp_info_new_port_fn_t);
186*0Sstevel@tonic-gate extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
187*0Sstevel@tonic-gate extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
188*0Sstevel@tonic-gate extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
189*0Sstevel@tonic-gate extern boolean_t aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *);
190*0Sstevel@tonic-gate extern int aggr_grp_add_ports(uint32_t, uint_t, laioc_port_t *);
191*0Sstevel@tonic-gate extern int aggr_grp_rem_ports(uint32_t, uint_t, laioc_port_t *);
192*0Sstevel@tonic-gate extern void aggr_grp_update_ports_mac(aggr_grp_t *);
193*0Sstevel@tonic-gate extern int aggr_grp_modify(uint32_t, aggr_grp_t *, uint8_t, uint32_t,
194*0Sstevel@tonic-gate     boolean_t, const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
195*0Sstevel@tonic-gate extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
196*0Sstevel@tonic-gate extern void aggr_grp_walk(aggr_grp_walker_fn_t, void *);
197*0Sstevel@tonic-gate 
198*0Sstevel@tonic-gate extern void aggr_port_init(void);
199*0Sstevel@tonic-gate extern int aggr_port_fini(void);
200*0Sstevel@tonic-gate extern int aggr_port_create(const char *, uint_t, aggr_port_t **);
201*0Sstevel@tonic-gate extern void aggr_port_delete(aggr_port_t *);
202*0Sstevel@tonic-gate extern void aggr_port_free(aggr_port_t *);
203*0Sstevel@tonic-gate extern int aggr_port_start(aggr_port_t *);
204*0Sstevel@tonic-gate extern void aggr_port_stop(aggr_port_t *);
205*0Sstevel@tonic-gate extern int aggr_port_promisc(aggr_port_t *, boolean_t);
206*0Sstevel@tonic-gate extern int aggr_port_unicst(aggr_port_t *, uint8_t *);
207*0Sstevel@tonic-gate extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
208*0Sstevel@tonic-gate extern uint64_t aggr_port_stat(aggr_port_t *, enum mac_stat);
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *);
211*0Sstevel@tonic-gate 
212*0Sstevel@tonic-gate extern mblk_t *aggr_m_tx(void *, mblk_t *);
213*0Sstevel@tonic-gate extern void aggr_send_port_enable(aggr_port_t *);
214*0Sstevel@tonic-gate extern void aggr_send_port_disable(aggr_port_t *);
215*0Sstevel@tonic-gate extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate extern void aggr_lacp_init_port(aggr_port_t *);
218*0Sstevel@tonic-gate extern void aggr_lacp_init_grp(aggr_grp_t *);
219*0Sstevel@tonic-gate extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
220*0Sstevel@tonic-gate     aggr_lacp_timer_t);
221*0Sstevel@tonic-gate extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
222*0Sstevel@tonic-gate extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
223*0Sstevel@tonic-gate extern void aggr_lacp_rx(aggr_port_t *, mblk_t *);
224*0Sstevel@tonic-gate extern void aggr_lacp_port_attached(aggr_port_t *);
225*0Sstevel@tonic-gate extern void aggr_lacp_port_detached(aggr_port_t *);
226*0Sstevel@tonic-gate extern void aggr_lacp_policy_changed(aggr_grp_t *);
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate #endif	/* _KERNEL */
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate #ifdef	__cplusplus
231*0Sstevel@tonic-gate }
232*0Sstevel@tonic-gate #endif
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate #endif	/* _SYS_AGGR_IMPL_H */
235