xref: /titanic_44/usr/src/uts/common/sys/aggr_impl.h (revision 743a77ed89085d3c232c4a2f65ab4e19576839e2)
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_pad_bits : 9;
151 	aggr_port_t	*lg_ports;		/* list of configured ports */
152 	aggr_port_t	*lg_mac_addr_port;
153 	mac_handle_t	lg_mh;
154 	uint_t		lg_nattached_ports;
155 	krwlock_t	lg_tx_lock;
156 	uint_t		lg_ntx_ports;
157 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
158 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
159 	uint32_t	lg_tx_policy;		/* outbound policy */
160 	uint8_t		lg_mac_tx_policy;
161 	uint64_t	lg_ifspeed;
162 	link_state_t	lg_link_state;
163 	link_duplex_t	lg_link_duplex;
164 	uint64_t	lg_stat[MAC_NSTAT];
165 	uint64_t	lg_ether_stat[ETHER_NSTAT];
166 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
167 	Agg_t		aggr;			/* 802.3ad data */
168 	uint32_t	lg_hcksum_txflags;
169 	uint_t		lg_max_sdu;
170 	uint32_t	lg_margin;
171 
172 	/*
173 	 * The following fields are used by the LACP packets processing.
174 	 * Specifically, as the LACP packets processing is not performance
175 	 * critical, all LACP packets will be handled by a dedicated thread
176 	 * instead of in the mac_rx() call. This is to avoid the dead lock
177 	 * with mac_unicast_remove(), which holding the mac perimeter of the
178 	 * aggr, and wait for the mr_refcnt of the RX ring to drop to zero.
179 	 */
180 	kmutex_t	lg_lacp_lock;
181 	kcondvar_t	lg_lacp_cv;
182 	mblk_t		*lg_lacp_head;
183 	mblk_t		*lg_lacp_tail;
184 	kthread_t	*lg_lacp_rx_thread;
185 	boolean_t	lg_lacp_done;
186 	aggr_pseudo_rx_group_t	lg_rx_group;
187 
188 	/*
189 	 * The following fields are used by aggr to wait for all the
190 	 * aggr_port_notify_cb() and aggr_port_timer_thread() to finish
191 	 * before it calls mac_unregister() when the aggr is deleted.
192 	 */
193 	kmutex_t	lg_port_lock;
194 	kcondvar_t	lg_port_cv;
195 	int		lg_port_ref;
196 } aggr_grp_t;
197 
198 #define	AGGR_GRP_REFHOLD(grp) {			\
199 	atomic_add_32(&(grp)->lg_refs, 1);	\
200 	ASSERT((grp)->lg_refs != 0);		\
201 }
202 
203 #define	AGGR_GRP_REFRELE(grp) {					\
204 	ASSERT((grp)->lg_refs != 0);				\
205 	membar_exit();						\
206 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
207 		aggr_grp_free(grp);				\
208 }
209 
210 #define	AGGR_PORT_REFHOLD(port) {		\
211 	atomic_add_32(&(port)->lp_refs, 1);	\
212 	ASSERT((port)->lp_refs != 0);		\
213 }
214 
215 #define	AGGR_PORT_REFRELE(port) {				\
216 	ASSERT((port)->lp_refs != 0);				\
217 	membar_exit();						\
218 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
219 		aggr_port_free(port);				\
220 }
221 
222 extern dev_info_t *aggr_dip;
223 extern int aggr_ioc_init(void);
224 extern void aggr_ioc_fini(void);
225 
226 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, datalink_id_t, uint32_t,
227     uchar_t *, boolean_t, boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t,
228     aggr_lacp_timer_t);
229 typedef int (*aggr_grp_info_new_port_fn_t)(void *, datalink_id_t, uchar_t *,
230     aggr_port_state_t, aggr_lacp_state_t *);
231 
232 extern void aggr_grp_init(void);
233 extern void aggr_grp_fini(void);
234 extern int aggr_grp_create(datalink_id_t, uint32_t, uint_t, laioc_port_t *,
235     uint32_t, boolean_t, boolean_t, uchar_t *, aggr_lacp_mode_t,
236     aggr_lacp_timer_t);
237 extern int aggr_grp_delete(datalink_id_t);
238 extern void aggr_grp_free(aggr_grp_t *);
239 
240 extern int aggr_grp_info(datalink_id_t, void *, aggr_grp_info_new_grp_fn_t,
241     aggr_grp_info_new_port_fn_t);
242 extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
243 extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
244 extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
245 extern void aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *,
246     boolean_t *, boolean_t *);
247 extern int aggr_grp_add_ports(datalink_id_t, uint_t, boolean_t,
248     laioc_port_t *);
249 extern int aggr_grp_rem_ports(datalink_id_t, uint_t, laioc_port_t *);
250 extern boolean_t aggr_grp_update_ports_mac(aggr_grp_t *);
251 extern int aggr_grp_modify(datalink_id_t, uint8_t, uint32_t, boolean_t,
252     const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
253 extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
254 extern uint_t aggr_grp_count(void);
255 
256 extern void aggr_port_init(void);
257 extern void aggr_port_fini(void);
258 extern int aggr_port_create(aggr_grp_t *, const datalink_id_t, boolean_t,
259     aggr_port_t **);
260 extern void aggr_port_delete(aggr_port_t *);
261 extern void aggr_port_free(aggr_port_t *);
262 extern int aggr_port_start(aggr_port_t *);
263 extern void aggr_port_stop(aggr_port_t *);
264 extern int aggr_port_promisc(aggr_port_t *, boolean_t);
265 extern int aggr_port_unicst(aggr_port_t *);
266 extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
267 extern uint64_t aggr_port_stat(aggr_port_t *, uint_t);
268 extern boolean_t aggr_port_notify_link(aggr_grp_t *, aggr_port_t *);
269 extern void aggr_port_init_callbacks(aggr_port_t *);
270 
271 extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *, boolean_t);
272 
273 extern mblk_t *aggr_m_tx(void *, mblk_t *);
274 extern void aggr_send_port_enable(aggr_port_t *);
275 extern void aggr_send_port_disable(aggr_port_t *);
276 extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
277 
278 extern void aggr_lacp_init(void);
279 extern void aggr_lacp_fini(void);
280 extern void aggr_lacp_init_port(aggr_port_t *);
281 extern void aggr_lacp_init_grp(aggr_grp_t *);
282 extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
283     aggr_lacp_timer_t);
284 extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
285 extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
286 extern void aggr_lacp_rx_enqueue(aggr_port_t *, mblk_t *);
287 extern void aggr_lacp_port_attached(aggr_port_t *);
288 extern void aggr_lacp_port_detached(aggr_port_t *);
289 extern void aggr_port_lacp_set_mode(aggr_grp_t *, aggr_port_t *);
290 
291 extern void aggr_lacp_rx_thread(void *);
292 extern void aggr_recv_lacp(aggr_port_t *, mac_resource_handle_t, mblk_t *);
293 
294 extern void aggr_grp_port_hold(aggr_port_t *);
295 extern void aggr_grp_port_rele(aggr_port_t *);
296 extern void aggr_grp_port_wait(aggr_grp_t *);
297 
298 extern int aggr_port_addmac(aggr_port_t *, const uint8_t *);
299 extern void aggr_port_remmac(aggr_port_t *, const uint8_t *);
300 
301 #endif	/* _KERNEL */
302 
303 #ifdef	__cplusplus
304 }
305 #endif
306 
307 #endif	/* _SYS_AGGR_IMPL_H */
308