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