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