xref: /titanic_51/usr/src/uts/common/sys/aggr_impl.h (revision 544f04c0a127b3f42f33facf10edfc0e0d896bc3)
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/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  * A link aggregation MAC port.
52  * Note that lp_next is protected by the lg_lock of the group the
53  * port is part of.
54  */
55 typedef struct aggr_port_s {
56 	struct aggr_port_s *lp_next;
57 	struct aggr_grp_s *lp_grp;		/* back ptr to group */
58 	char		lp_devname[MAXNAMELEN + 1];
59 	uint8_t		lp_addr[ETHERADDRL];	/* port MAC address */
60 	uint32_t	lp_refs;		/* refcount */
61 	aggr_port_state_t lp_state;
62 	uint32_t	lp_started : 1,
63 			lp_tx_enabled : 1,
64 			lp_collector_enabled : 1,
65 			lp_promisc_on : 1,
66 			lp_closing : 1,
67 			/*
68 			 * Indicates whether it is in the process of setting
69 			 * MAC address to the aggregation group MAC
70 			 */
71 			lp_set_grpmac : 1,
72 			lp_pad_bits : 26;
73 	uint_t		lp_port;
74 	mac_handle_t	lp_mh;
75 	const mac_info_t *lp_mip;
76 	mac_notify_handle_t lp_mnh;
77 	mac_rx_handle_t	lp_mrh;
78 	krwlock_t	lp_lock;
79 	uint_t		lp_tx_idx;		/* idx in group's tx array */
80 	uint64_t	lp_ifspeed;
81 	link_state_t	lp_link_state;
82 	link_duplex_t	lp_link_duplex;
83 	uint64_t	lp_stat[MAC_NSTAT];
84 	aggr_lacp_port_t lp_lacp;		/* LACP state */
85 	lacp_stats_t	lp_lacp_stats;
86 	const mac_txinfo_t *lp_txinfo;
87 } aggr_port_t;
88 
89 /*
90  * A link aggregation group.
91  *
92  * The following per-group flags are defined:
93  *
94  * - lg_addr_fixed: set when the MAC address has been explicitely set
95  *   when the group was created, or by a m_unicst_set() request.
96  *   If this flag is not set, the MAC address of the group will be
97  *   set to the first port that is added to the group.
98  *
99  * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether
100  *   the MAC address was initialized according to the members of the group.
101  *   When set, the lg_port field points to the port from which the
102  *   MAC address was initialized.
103  *
104  */
105 typedef struct aggr_grp_s {
106 	krwlock_t	lg_lock;
107 	uint16_t	lg_key;			/* key (group port number) */
108 	uint32_t	lg_refs;		/* refcount */
109 	uint16_t	lg_nports;		/* number of MAC ports */
110 	uint8_t		lg_addr[ETHERADDRL];	/* group MAC address */
111 	uint16_t
112 			lg_addr_fixed : 1,	/* fixed MAC address? */
113 			lg_started : 1,		/* group started? */
114 			lg_promisc : 1,		/* in promiscuous mode? */
115 			lg_closing : 1,
116 			lg_pad_bits : 12;
117 	aggr_port_t	*lg_ports;		/* list of configured ports */
118 	aggr_port_t	*lg_mac_addr_port;
119 	mac_t		lg_mac;
120 	uint_t		lg_rx_resources;
121 	uint_t		lg_nattached_ports;
122 	uint_t		lg_ntx_ports;
123 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
124 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
125 	uint32_t	lg_tx_policy;		/* outbound policy */
126 	uint64_t	lg_ifspeed;
127 	link_state_t	lg_link_state;
128 	link_duplex_t	lg_link_duplex;
129 	uint64_t	lg_stat[MAC_NSTAT];
130 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
131 	Agg_t		aggr;			/* 802.3ad data */
132 } aggr_grp_t;
133 
134 #define	AGGR_LACP_LOCK(grp)	mutex_enter(&(grp)->aggr.gl_lock);
135 #define	AGGR_LACP_UNLOCK(grp)	mutex_exit(&(grp)->aggr.gl_lock);
136 #define	AGGR_LACP_LOCK_HELD(grp) MUTEX_HELD(&(grp)->aggr.gl_lock)
137 
138 #define	AGGR_GRP_REFHOLD(grp) {			\
139 	atomic_add_32(&(grp)->lg_refs, 1);	\
140 	ASSERT((grp)->lg_refs != 0);		\
141 }
142 
143 #define	AGGR_GRP_REFRELE(grp) {					\
144 	ASSERT((grp)->lg_refs != 0);				\
145 	membar_exit();						\
146 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
147 		aggr_grp_free(grp);				\
148 }
149 
150 #define	AGGR_PORT_REFHOLD(port) {		\
151 	atomic_add_32(&(port)->lp_refs, 1);	\
152 	ASSERT((port)->lp_refs != 0);		\
153 }
154 
155 #define	AGGR_PORT_REFRELE(port) {				\
156 	ASSERT((port)->lp_refs != 0);				\
157 	membar_exit();						\
158 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
159 		aggr_port_free(port);				\
160 }
161 
162 extern dev_info_t *aggr_dip;
163 extern void aggr_ioctl(queue_t *, mblk_t *);
164 
165 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, uint32_t, uchar_t *,
166     boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t, aggr_lacp_timer_t);
167 typedef int (*aggr_grp_info_new_port_fn_t)(void *, char *, uint32_t,
168     uchar_t *, aggr_port_state_t, aggr_lacp_state_t *);
169 typedef void (*aggr_grp_walker_fn_t)(aggr_grp_t *, void *);
170 
171 extern void aggr_grp_init(void);
172 extern int aggr_grp_fini(void);
173 extern int aggr_grp_create(uint32_t, uint_t, laioc_port_t *, uint32_t,
174     boolean_t, uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
175 extern int aggr_grp_delete(uint32_t);
176 extern void aggr_grp_free(aggr_grp_t *);
177 
178 extern int aggr_grp_info(uint_t *, uint32_t, void *,
179     aggr_grp_info_new_grp_fn_t, aggr_grp_info_new_port_fn_t);
180 extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
181 extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
182 extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
183 extern boolean_t aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *);
184 extern int aggr_grp_add_ports(uint32_t, uint_t, laioc_port_t *);
185 extern int aggr_grp_rem_ports(uint32_t, uint_t, laioc_port_t *);
186 extern void aggr_grp_update_ports_mac(aggr_grp_t *);
187 extern int aggr_grp_modify(uint32_t, aggr_grp_t *, uint8_t, uint32_t,
188     boolean_t, const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
189 extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
190 extern void aggr_grp_walk(aggr_grp_walker_fn_t, void *);
191 extern uint_t aggr_grp_count(void);
192 
193 extern void aggr_port_init(void);
194 extern int aggr_port_fini(void);
195 extern int aggr_port_create(const char *, uint_t, aggr_port_t **);
196 extern void aggr_port_delete(aggr_port_t *);
197 extern void aggr_port_free(aggr_port_t *);
198 extern int aggr_port_start(aggr_port_t *);
199 extern void aggr_port_stop(aggr_port_t *);
200 extern int aggr_port_promisc(aggr_port_t *, boolean_t);
201 extern int aggr_port_unicst(aggr_port_t *, uint8_t *);
202 extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
203 extern uint64_t aggr_port_stat(aggr_port_t *, enum mac_stat);
204 
205 extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *);
206 
207 extern mblk_t *aggr_m_tx(void *, mblk_t *);
208 extern void aggr_send_port_enable(aggr_port_t *);
209 extern void aggr_send_port_disable(aggr_port_t *);
210 extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
211 
212 extern void aggr_lacp_init_port(aggr_port_t *);
213 extern void aggr_lacp_init_grp(aggr_grp_t *);
214 extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
215     aggr_lacp_timer_t);
216 extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
217 extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
218 extern void aggr_lacp_rx(aggr_port_t *, mblk_t *);
219 extern void aggr_lacp_port_attached(aggr_port_t *);
220 extern void aggr_lacp_port_detached(aggr_port_t *);
221 extern void aggr_lacp_policy_changed(aggr_grp_t *);
222 
223 #endif	/* _KERNEL */
224 
225 #ifdef	__cplusplus
226 }
227 #endif
228 
229 #endif	/* _SYS_AGGR_IMPL_H */
230