xref: /titanic_51/usr/src/uts/common/sys/aggr_impl.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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 	mac_tx_t	lp_tx;
88 	void		*lp_tx_arg;
89 } aggr_port_t;
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 	uint16_t	lg_key;			/* key (group port number) */
110 	uint32_t	lg_refs;		/* refcount */
111 	uint16_t	lg_nports;		/* number of MAC ports */
112 	uint8_t		lg_addr[ETHERADDRL];	/* group MAC address */
113 	ghte_t		lg_hte;
114 	uint16_t
115 			lg_addr_fixed : 1,	/* fixed MAC address? */
116 			lg_started : 1,		/* group started? */
117 			lg_promisc : 1,		/* in promiscuous mode? */
118 			lg_closing : 1,
119 			lg_pad_bits : 12;
120 	aggr_port_t	*lg_ports;		/* list of configured ports */
121 	aggr_port_t	*lg_mac_addr_port;
122 	mac_t		lg_mac;
123 	uint_t		lg_rx_resources;
124 	uint_t		lg_nattached_ports;
125 	uint_t		lg_ntx_ports;
126 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
127 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
128 	uint32_t	lg_tx_policy;		/* outbound policy */
129 	uint64_t	lg_ifspeed;
130 	link_state_t	lg_link_state;
131 	link_duplex_t	lg_link_duplex;
132 	uint64_t	lg_stat[MAC_NSTAT];
133 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
134 	Agg_t		aggr;			/* 802.3ad data */
135 } aggr_grp_t;
136 
137 #define	AGGR_LACP_LOCK(grp)	mutex_enter(&(grp)->aggr.gl_lock);
138 #define	AGGR_LACP_UNLOCK(grp)	mutex_exit(&(grp)->aggr.gl_lock);
139 #define	AGGR_LACP_LOCK_HELD(grp) MUTEX_HELD(&(grp)->aggr.gl_lock)
140 
141 #define	AGGR_GRP_REFHOLD(grp) {			\
142 	atomic_add_32(&(grp)->lg_refs, 1);	\
143 	ASSERT((grp)->lg_refs != 0);		\
144 }
145 
146 #define	AGGR_GRP_REFRELE(grp) {					\
147 	ASSERT((grp)->lg_refs != 0);				\
148 	membar_exit();						\
149 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
150 		aggr_grp_free(grp);				\
151 }
152 
153 #define	AGGR_PORT_REFHOLD(port) {		\
154 	atomic_add_32(&(port)->lp_refs, 1);	\
155 	ASSERT((port)->lp_refs != 0);		\
156 }
157 
158 #define	AGGR_PORT_REFRELE(port) {				\
159 	ASSERT((port)->lp_refs != 0);				\
160 	membar_exit();						\
161 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
162 		aggr_port_free(port);				\
163 }
164 
165 extern dev_info_t *aggr_dip;
166 
167 extern int aggr_open(dev_t *, int, int, cred_t *);
168 extern int aggr_close(dev_t, int, int, cred_t *);
169 extern int aggr_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
170 
171 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, uint32_t, uchar_t *,
172     boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t, aggr_lacp_timer_t);
173 typedef int (*aggr_grp_info_new_port_fn_t)(void *, char *, uint32_t,
174     uchar_t *, aggr_port_state_t, aggr_lacp_state_t *);
175 typedef void (*aggr_grp_walker_fn_t)(aggr_grp_t *, void *);
176 
177 extern void aggr_grp_init(void);
178 extern int aggr_grp_fini(void);
179 extern int aggr_grp_create(uint32_t, uint_t, laioc_port_t *, uint32_t,
180     boolean_t, uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
181 extern int aggr_grp_delete(uint32_t);
182 extern void aggr_grp_free(aggr_grp_t *);
183 
184 extern int aggr_grp_info(uint_t *, uint32_t, void *,
185     aggr_grp_info_new_grp_fn_t, aggr_grp_info_new_port_fn_t);
186 extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
187 extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
188 extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
189 extern boolean_t aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *);
190 extern int aggr_grp_add_ports(uint32_t, uint_t, laioc_port_t *);
191 extern int aggr_grp_rem_ports(uint32_t, uint_t, laioc_port_t *);
192 extern void aggr_grp_update_ports_mac(aggr_grp_t *);
193 extern int aggr_grp_modify(uint32_t, aggr_grp_t *, uint8_t, uint32_t,
194     boolean_t, const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
195 extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
196 extern void aggr_grp_walk(aggr_grp_walker_fn_t, void *);
197 
198 extern void aggr_port_init(void);
199 extern int aggr_port_fini(void);
200 extern int aggr_port_create(const char *, uint_t, aggr_port_t **);
201 extern void aggr_port_delete(aggr_port_t *);
202 extern void aggr_port_free(aggr_port_t *);
203 extern int aggr_port_start(aggr_port_t *);
204 extern void aggr_port_stop(aggr_port_t *);
205 extern int aggr_port_promisc(aggr_port_t *, boolean_t);
206 extern int aggr_port_unicst(aggr_port_t *, uint8_t *);
207 extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
208 extern uint64_t aggr_port_stat(aggr_port_t *, enum mac_stat);
209 
210 extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *);
211 
212 extern mblk_t *aggr_m_tx(void *, mblk_t *);
213 extern void aggr_send_port_enable(aggr_port_t *);
214 extern void aggr_send_port_disable(aggr_port_t *);
215 extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
216 
217 extern void aggr_lacp_init_port(aggr_port_t *);
218 extern void aggr_lacp_init_grp(aggr_grp_t *);
219 extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
220     aggr_lacp_timer_t);
221 extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
222 extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
223 extern void aggr_lacp_rx(aggr_port_t *, mblk_t *);
224 extern void aggr_lacp_port_attached(aggr_port_t *);
225 extern void aggr_lacp_port_detached(aggr_port_t *);
226 extern void aggr_lacp_policy_changed(aggr_grp_t *);
227 
228 #endif	/* _KERNEL */
229 
230 #ifdef	__cplusplus
231 }
232 #endif
233 
234 #endif	/* _SYS_AGGR_IMPL_H */
235