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