xref: /titanic_50/usr/src/uts/common/sys/aggr_impl.h (revision 7e16fca05dfbcfd32c2ebc9e4d1abdac1cd8657c)
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 2009 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_ether.h>
31 #include <sys/mac_provider.h>
32 #include <sys/mac_client.h>
33 #include <sys/mac_client_priv.h>
34 #include <sys/aggr_lacp.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 #define	AGGR_MINOR_CTL	1		/* control interface minor */
43 
44 /* flags for aggr_grp_modify() */
45 #define	AGGR_MODIFY_POLICY		0x01
46 #define	AGGR_MODIFY_MAC			0x02
47 #define	AGGR_MODIFY_LACP_MODE		0x04
48 #define	AGGR_MODIFY_LACP_TIMER		0x08
49 
50 /*
51  * Possible value of aggr_rseudo_rx_ring_t.arr_flags. Set when the ring entry
52  * in the pseudo RX group is used.
53  */
54 #define	MAC_PSEUDO_RING_INUSE	0x01
55 
56 typedef struct aggr_unicst_addr_s {
57 	uint8_t				aua_addr[ETHERADDRL];
58 	struct aggr_unicst_addr_s	*aua_next;
59 } aggr_unicst_addr_t;
60 
61 typedef struct aggr_pseudo_rx_ring_s {
62 	mac_ring_handle_t	arr_rh;	/* filled in by aggr_fill_ring() */
63 	struct aggr_port_s	*arr_port;
64 	mac_ring_handle_t	arr_hw_rh;
65 	uint_t			arr_flags;
66 	uint64_t		arr_gen;
67 } aggr_pseudo_rx_ring_t;
68 
69 typedef struct aggr_pseudo_rx_group_s {
70 	struct aggr_grp_s	*arg_grp; /* filled in by aggr_fill_group() */
71 	mac_group_handle_t	arg_gh;   /* filled in by aggr_fill_group() */
72 	aggr_unicst_addr_t	*arg_macaddr;
73 	aggr_pseudo_rx_ring_t	arg_rings[MAX_RINGS_PER_GROUP];
74 	uint_t			arg_ring_cnt;
75 } aggr_pseudo_rx_group_t;
76 
77 /*
78  * A link aggregation MAC port.
79  * Note that lp_next is protected by the lg_lock of the group the
80  * port is part of.
81  */
82 typedef struct aggr_port_s {
83 	struct aggr_port_s *lp_next;
84 	struct aggr_grp_s *lp_grp;		/* back ptr to group */
85 	datalink_id_t	lp_linkid;
86 	uint16_t	lp_portid;
87 	uint8_t		lp_addr[ETHERADDRL];	/* port MAC address */
88 	uint32_t	lp_refs;		/* refcount */
89 	aggr_port_state_t lp_state;
90 	uint32_t	lp_started : 1,
91 			lp_tx_enabled : 1,
92 			lp_collector_enabled : 1,
93 			lp_promisc_on : 1,
94 			lp_no_link_update : 1,
95 			lp_grp_added : 1,
96 			lp_closing : 1,
97 			lp_pad_bits : 25;
98 	mac_handle_t	lp_mh;
99 	mac_client_handle_t lp_mch;
100 	const mac_info_t *lp_mip;
101 	mac_notify_handle_t lp_mnh;
102 	uint_t		lp_tx_idx;		/* idx in group's tx array */
103 	uint64_t	lp_ifspeed;
104 	link_state_t	lp_link_state;
105 	link_duplex_t	lp_link_duplex;
106 	uint64_t	lp_stat[MAC_NSTAT];
107 	uint64_t	lp_ether_stat[ETHER_NSTAT];
108 	aggr_lacp_port_t lp_lacp;		/* LACP state */
109 	lacp_stats_t	lp_lacp_stats;
110 	uint32_t	lp_margin;
111 	mac_promisc_handle_t lp_mphp;
112 	mac_unicast_handle_t lp_mah;
113 
114 	/* List of non-primary addresses that requires promiscous mode set */
115 	aggr_unicst_addr_t	*lp_prom_addr;
116 	/* handle of the underlying HW RX group */
117 	mac_group_handle_t	lp_hwgh;
118 } aggr_port_t;
119 
120 /*
121  * A link aggregation group.
122  *
123  * The following per-group flags are defined:
124  *
125  * - lg_addr_fixed: set when the MAC address has been explicitely set
126  *   when the group was created, or by a m_unicst_set() request.
127  *   If this flag is not set, the MAC address of the group will be
128  *   set to the first port that is added to the group.
129  *
130  * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether
131  *   the MAC address was initialized according to the members of the group.
132  *   When set, the lg_port field points to the port from which the
133  *   MAC address was initialized.
134  *
135  */
136 typedef struct aggr_grp_s {
137 	datalink_id_t	lg_linkid;
138 	uint16_t	lg_key;			/* key (group port number) */
139 	uint32_t	lg_refs;		/* refcount */
140 	uint16_t	lg_nports;		/* number of MAC ports */
141 	uint8_t		lg_addr[ETHERADDRL];	/* group MAC address */
142 	uint16_t
143 			lg_closing : 1,
144 			lg_addr_fixed : 1,	/* fixed MAC address? */
145 			lg_started : 1,		/* group started? */
146 			lg_promisc : 1,		/* in promiscuous mode? */
147 			lg_zcopy : 1,
148 			lg_vlan : 1,
149 			lg_force : 1,
150 			lg_lso : 1,
151 			lg_pad_bits : 8;
152 	aggr_port_t	*lg_ports;		/* list of configured ports */
153 	aggr_port_t	*lg_mac_addr_port;
154 	mac_handle_t	lg_mh;
155 	uint_t		lg_nattached_ports;
156 	krwlock_t	lg_tx_lock;
157 	uint_t		lg_ntx_ports;
158 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
159 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
160 	uint32_t	lg_tx_policy;		/* outbound policy */
161 	uint8_t		lg_mac_tx_policy;
162 	uint64_t	lg_ifspeed;
163 	link_state_t	lg_link_state;
164 	link_duplex_t	lg_link_duplex;
165 	uint64_t	lg_stat[MAC_NSTAT];
166 	uint64_t	lg_ether_stat[ETHER_NSTAT];
167 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
168 	Agg_t		aggr;			/* 802.3ad data */
169 	uint32_t	lg_hcksum_txflags;
170 	uint_t		lg_max_sdu;
171 	uint32_t	lg_margin;
172 	mac_capab_lso_t lg_cap_lso;
173 
174 	/*
175 	 * The following fields are used by the LACP packets processing.
176 	 * Specifically, as the LACP packets processing is not performance
177 	 * critical, all LACP packets will be handled by a dedicated thread
178 	 * instead of in the mac_rx() call. This is to avoid the dead lock
179 	 * with mac_unicast_remove(), which holding the mac perimeter of the
180 	 * aggr, and wait for the mr_refcnt of the RX ring to drop to zero.
181 	 */
182 	kmutex_t	lg_lacp_lock;
183 	kcondvar_t	lg_lacp_cv;
184 	mblk_t		*lg_lacp_head;
185 	mblk_t		*lg_lacp_tail;
186 	kthread_t	*lg_lacp_rx_thread;
187 	boolean_t	lg_lacp_done;
188 	aggr_pseudo_rx_group_t	lg_rx_group;
189 
190 	/*
191 	 * The following fields are used by aggr to wait for all the
192 	 * aggr_port_notify_cb() and aggr_port_timer_thread() to finish
193 	 * before it calls mac_unregister() when the aggr is deleted.
194 	 */
195 	kmutex_t	lg_port_lock;
196 	kcondvar_t	lg_port_cv;
197 	int		lg_port_ref;
198 } aggr_grp_t;
199 
200 #define	AGGR_GRP_REFHOLD(grp) {			\
201 	atomic_add_32(&(grp)->lg_refs, 1);	\
202 	ASSERT((grp)->lg_refs != 0);		\
203 }
204 
205 #define	AGGR_GRP_REFRELE(grp) {					\
206 	ASSERT((grp)->lg_refs != 0);				\
207 	membar_exit();						\
208 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
209 		aggr_grp_free(grp);				\
210 }
211 
212 #define	AGGR_PORT_REFHOLD(port) {		\
213 	atomic_add_32(&(port)->lp_refs, 1);	\
214 	ASSERT((port)->lp_refs != 0);		\
215 }
216 
217 #define	AGGR_PORT_REFRELE(port) {				\
218 	ASSERT((port)->lp_refs != 0);				\
219 	membar_exit();						\
220 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
221 		aggr_port_free(port);				\
222 }
223 
224 extern dev_info_t *aggr_dip;
225 extern int aggr_ioc_init(void);
226 extern void aggr_ioc_fini(void);
227 
228 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, datalink_id_t, uint32_t,
229     uchar_t *, boolean_t, boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t,
230     aggr_lacp_timer_t);
231 typedef int (*aggr_grp_info_new_port_fn_t)(void *, datalink_id_t, uchar_t *,
232     aggr_port_state_t, aggr_lacp_state_t *);
233 
234 extern void aggr_grp_init(void);
235 extern void aggr_grp_fini(void);
236 extern int aggr_grp_create(datalink_id_t, uint32_t, uint_t, laioc_port_t *,
237     uint32_t, boolean_t, boolean_t, uchar_t *, aggr_lacp_mode_t,
238     aggr_lacp_timer_t);
239 extern int aggr_grp_delete(datalink_id_t);
240 extern void aggr_grp_free(aggr_grp_t *);
241 
242 extern int aggr_grp_info(datalink_id_t, void *, aggr_grp_info_new_grp_fn_t,
243     aggr_grp_info_new_port_fn_t);
244 extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
245 extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
246 extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
247 extern void aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *,
248     boolean_t *, boolean_t *);
249 extern int aggr_grp_add_ports(datalink_id_t, uint_t, boolean_t,
250     laioc_port_t *);
251 extern int aggr_grp_rem_ports(datalink_id_t, uint_t, laioc_port_t *);
252 extern boolean_t aggr_grp_update_ports_mac(aggr_grp_t *);
253 extern int aggr_grp_modify(datalink_id_t, uint8_t, uint32_t, boolean_t,
254     const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
255 extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
256 extern uint_t aggr_grp_count(void);
257 
258 extern void aggr_port_init(void);
259 extern void aggr_port_fini(void);
260 extern int aggr_port_create(aggr_grp_t *, const datalink_id_t, boolean_t,
261     aggr_port_t **);
262 extern void aggr_port_delete(aggr_port_t *);
263 extern void aggr_port_free(aggr_port_t *);
264 extern int aggr_port_start(aggr_port_t *);
265 extern void aggr_port_stop(aggr_port_t *);
266 extern int aggr_port_promisc(aggr_port_t *, boolean_t);
267 extern int aggr_port_unicst(aggr_port_t *);
268 extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
269 extern uint64_t aggr_port_stat(aggr_port_t *, uint_t);
270 extern boolean_t aggr_port_notify_link(aggr_grp_t *, aggr_port_t *);
271 extern void aggr_port_init_callbacks(aggr_port_t *);
272 
273 extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *, boolean_t);
274 
275 extern mblk_t *aggr_m_tx(void *, mblk_t *);
276 extern void aggr_send_port_enable(aggr_port_t *);
277 extern void aggr_send_port_disable(aggr_port_t *);
278 extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
279 
280 extern void aggr_lacp_init(void);
281 extern void aggr_lacp_fini(void);
282 extern void aggr_lacp_init_port(aggr_port_t *);
283 extern void aggr_lacp_init_grp(aggr_grp_t *);
284 extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
285     aggr_lacp_timer_t);
286 extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
287 extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
288 extern void aggr_lacp_rx_enqueue(aggr_port_t *, mblk_t *);
289 extern void aggr_lacp_port_attached(aggr_port_t *);
290 extern void aggr_lacp_port_detached(aggr_port_t *);
291 extern void aggr_port_lacp_set_mode(aggr_grp_t *, aggr_port_t *);
292 
293 extern void aggr_lacp_rx_thread(void *);
294 extern void aggr_recv_lacp(aggr_port_t *, mac_resource_handle_t, mblk_t *);
295 
296 extern void aggr_grp_port_hold(aggr_port_t *);
297 extern void aggr_grp_port_rele(aggr_port_t *);
298 extern void aggr_grp_port_wait(aggr_grp_t *);
299 
300 extern int aggr_port_addmac(aggr_port_t *, const uint8_t *);
301 extern void aggr_port_remmac(aggr_port_t *, const uint8_t *);
302 
303 #endif	/* _KERNEL */
304 
305 #ifdef	__cplusplus
306 }
307 #endif
308 
309 #endif	/* _SYS_AGGR_IMPL_H */
310