xref: /onnv-gate/usr/src/uts/common/sys/aggr_impl.h (revision 7085:67db590f838c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51537Snd99603  * Common Development and Distribution License (the "License").
61537Snd99603  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
225895Syz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_AGGR_IMPL_H
270Sstevel@tonic-gate #define	_SYS_AGGR_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/mac.h>
332311Sseb #include <sys/mac_ether.h>
340Sstevel@tonic-gate #include <sys/aggr_lacp.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #ifdef	__cplusplus
370Sstevel@tonic-gate extern "C" {
380Sstevel@tonic-gate #endif
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef _KERNEL
410Sstevel@tonic-gate 
42269Sericheng #define	AGGR_MINOR_CTL	1		/* control interface minor */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /* flags for aggr_grp_modify() */
450Sstevel@tonic-gate #define	AGGR_MODIFY_POLICY		0x01
460Sstevel@tonic-gate #define	AGGR_MODIFY_MAC			0x02
470Sstevel@tonic-gate #define	AGGR_MODIFY_LACP_MODE		0x04
480Sstevel@tonic-gate #define	AGGR_MODIFY_LACP_TIMER		0x08
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * A link aggregation MAC port.
520Sstevel@tonic-gate  * Note that lp_next is protected by the lg_lock of the group the
530Sstevel@tonic-gate  * port is part of.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate typedef struct aggr_port_s {
560Sstevel@tonic-gate 	struct aggr_port_s *lp_next;
570Sstevel@tonic-gate 	struct aggr_grp_s *lp_grp;		/* back ptr to group */
585895Syz147064 	datalink_id_t	lp_linkid;
595102Syz147064 	uint16_t	lp_portid;
600Sstevel@tonic-gate 	uint8_t		lp_addr[ETHERADDRL];	/* port MAC address */
610Sstevel@tonic-gate 	uint32_t	lp_refs;		/* refcount */
620Sstevel@tonic-gate 	aggr_port_state_t lp_state;
630Sstevel@tonic-gate 	uint32_t	lp_started : 1,
640Sstevel@tonic-gate 			lp_tx_enabled : 1,
650Sstevel@tonic-gate 			lp_collector_enabled : 1,
660Sstevel@tonic-gate 			lp_promisc_on : 1,
675895Syz147064 			lp_no_link_update : 1,
685895Syz147064 			lp_pad_bits : 27;
691852Syz147064 	uint32_t	lp_closing;
700Sstevel@tonic-gate 	mac_handle_t	lp_mh;
710Sstevel@tonic-gate 	const mac_info_t *lp_mip;
720Sstevel@tonic-gate 	mac_notify_handle_t lp_mnh;
730Sstevel@tonic-gate 	mac_rx_handle_t	lp_mrh;
740Sstevel@tonic-gate 	krwlock_t	lp_lock;
750Sstevel@tonic-gate 	uint_t		lp_tx_idx;		/* idx in group's tx array */
760Sstevel@tonic-gate 	uint64_t	lp_ifspeed;
770Sstevel@tonic-gate 	link_state_t	lp_link_state;
780Sstevel@tonic-gate 	link_duplex_t	lp_link_duplex;
790Sstevel@tonic-gate 	uint64_t	lp_stat[MAC_NSTAT];
802311Sseb 	uint64_t	lp_ether_stat[ETHER_NSTAT];
810Sstevel@tonic-gate 	aggr_lacp_port_t lp_lacp;		/* LACP state */
820Sstevel@tonic-gate 	lacp_stats_t	lp_lacp_stats;
8356Smeem 	const mac_txinfo_t *lp_txinfo;
845895Syz147064 	uint32_t	lp_margin;
850Sstevel@tonic-gate } aggr_port_t;
860Sstevel@tonic-gate 
87*7085Sudpa typedef struct lg_mcst_addr_s	lg_mcst_addr_t;
88*7085Sudpa struct lg_mcst_addr_s {
89*7085Sudpa 	lg_mcst_addr_t	*lg_mcst_nextp;
90*7085Sudpa 	uint8_t		lg_mcst_addr[MAXMACADDRLEN];
91*7085Sudpa };
92*7085Sudpa 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * A link aggregation group.
950Sstevel@tonic-gate  *
960Sstevel@tonic-gate  * The following per-group flags are defined:
970Sstevel@tonic-gate  *
980Sstevel@tonic-gate  * - lg_addr_fixed: set when the MAC address has been explicitely set
990Sstevel@tonic-gate  *   when the group was created, or by a m_unicst_set() request.
1000Sstevel@tonic-gate  *   If this flag is not set, the MAC address of the group will be
1010Sstevel@tonic-gate  *   set to the first port that is added to the group.
1020Sstevel@tonic-gate  *
1030Sstevel@tonic-gate  * - lg_add_set: used only when lg_addr_fixed is not set. Captures whether
1040Sstevel@tonic-gate  *   the MAC address was initialized according to the members of the group.
1050Sstevel@tonic-gate  *   When set, the lg_port field points to the port from which the
1060Sstevel@tonic-gate  *   MAC address was initialized.
1070Sstevel@tonic-gate  *
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate typedef struct aggr_grp_s {
1100Sstevel@tonic-gate 	krwlock_t	lg_lock;
1115895Syz147064 	datalink_id_t	lg_linkid;
1120Sstevel@tonic-gate 	uint16_t	lg_key;			/* key (group port number) */
1130Sstevel@tonic-gate 	uint32_t	lg_refs;		/* refcount */
1140Sstevel@tonic-gate 	uint16_t	lg_nports;		/* number of MAC ports */
1150Sstevel@tonic-gate 	uint8_t		lg_addr[ETHERADDRL];	/* group MAC address */
1160Sstevel@tonic-gate 	uint16_t
1172047Syz147064 			lg_closing : 1,
1180Sstevel@tonic-gate 			lg_addr_fixed : 1,	/* fixed MAC address? */
1190Sstevel@tonic-gate 			lg_started : 1,		/* group started? */
1200Sstevel@tonic-gate 			lg_promisc : 1,		/* in promiscuous mode? */
1212311Sseb 			lg_gldv3_polling : 1,
1225895Syz147064 			lg_zcopy : 1,
1235895Syz147064 			lg_vlan : 1,
1245895Syz147064 			lg_force : 1,
1255895Syz147064 			lg_pad_bits : 8;
1260Sstevel@tonic-gate 	aggr_port_t	*lg_ports;		/* list of configured ports */
1270Sstevel@tonic-gate 	aggr_port_t	*lg_mac_addr_port;
1282311Sseb 	mac_handle_t	lg_mh;
1290Sstevel@tonic-gate 	uint_t		lg_rx_resources;
1300Sstevel@tonic-gate 	uint_t		lg_nattached_ports;
1310Sstevel@tonic-gate 	uint_t		lg_ntx_ports;
1320Sstevel@tonic-gate 	aggr_port_t	**lg_tx_ports;		/* array of tx ports */
1330Sstevel@tonic-gate 	uint_t		lg_tx_ports_size;	/* size of lg_tx_ports */
1340Sstevel@tonic-gate 	uint32_t	lg_tx_policy;		/* outbound policy */
1350Sstevel@tonic-gate 	uint64_t	lg_ifspeed;
1360Sstevel@tonic-gate 	link_state_t	lg_link_state;
1370Sstevel@tonic-gate 	link_duplex_t	lg_link_duplex;
1380Sstevel@tonic-gate 	uint64_t	lg_stat[MAC_NSTAT];
1392311Sseb 	uint64_t	lg_ether_stat[ETHER_NSTAT];
1400Sstevel@tonic-gate 	aggr_lacp_mode_t lg_lacp_mode;		/* off, active, or passive */
1410Sstevel@tonic-gate 	Agg_t		aggr;			/* 802.3ad data */
1422311Sseb 	uint32_t	lg_hcksum_txflags;
1432803Snd99603 	uint_t		lg_max_sdu;
1445895Syz147064 	uint32_t	lg_margin;
145*7085Sudpa 	lg_mcst_addr_t	*lg_mcst_list; /* A list of multicast addresses */
1460Sstevel@tonic-gate } aggr_grp_t;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #define	AGGR_LACP_LOCK(grp)	mutex_enter(&(grp)->aggr.gl_lock);
1490Sstevel@tonic-gate #define	AGGR_LACP_UNLOCK(grp)	mutex_exit(&(grp)->aggr.gl_lock);
1500Sstevel@tonic-gate #define	AGGR_LACP_LOCK_HELD(grp) MUTEX_HELD(&(grp)->aggr.gl_lock)
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	AGGR_GRP_REFHOLD(grp) {			\
1530Sstevel@tonic-gate 	atomic_add_32(&(grp)->lg_refs, 1);	\
1540Sstevel@tonic-gate 	ASSERT((grp)->lg_refs != 0);		\
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #define	AGGR_GRP_REFRELE(grp) {					\
1580Sstevel@tonic-gate 	ASSERT((grp)->lg_refs != 0);				\
1590Sstevel@tonic-gate 	membar_exit();						\
1600Sstevel@tonic-gate 	if (atomic_add_32_nv(&(grp)->lg_refs, -1) == 0)		\
1610Sstevel@tonic-gate 		aggr_grp_free(grp);				\
1620Sstevel@tonic-gate }
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate #define	AGGR_PORT_REFHOLD(port) {		\
1650Sstevel@tonic-gate 	atomic_add_32(&(port)->lp_refs, 1);	\
1660Sstevel@tonic-gate 	ASSERT((port)->lp_refs != 0);		\
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate #define	AGGR_PORT_REFRELE(port) {				\
1700Sstevel@tonic-gate 	ASSERT((port)->lp_refs != 0);				\
1710Sstevel@tonic-gate 	membar_exit();						\
1720Sstevel@tonic-gate 	if (atomic_add_32_nv(&(port)->lp_refs, -1) == 0)	\
1730Sstevel@tonic-gate 		aggr_port_free(port);				\
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate extern dev_info_t *aggr_dip;
177269Sericheng extern void aggr_ioctl(queue_t *, mblk_t *);
1780Sstevel@tonic-gate 
1795895Syz147064 typedef int (*aggr_grp_info_new_grp_fn_t)(void *, datalink_id_t, uint32_t,
1805895Syz147064     uchar_t *, boolean_t, boolean_t, uint32_t, uint32_t, aggr_lacp_mode_t,
1815895Syz147064     aggr_lacp_timer_t);
1825895Syz147064 typedef int (*aggr_grp_info_new_port_fn_t)(void *, datalink_id_t, uchar_t *,
1832311Sseb     aggr_port_state_t, aggr_lacp_state_t *);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate extern void aggr_grp_init(void);
1861804Sericheng extern void aggr_grp_fini(void);
1875895Syz147064 extern int aggr_grp_create(datalink_id_t, uint32_t, uint_t, laioc_port_t *,
1885895Syz147064     uint32_t, boolean_t, boolean_t, uchar_t *, aggr_lacp_mode_t,
1895895Syz147064     aggr_lacp_timer_t);
1905895Syz147064 extern int aggr_grp_delete(datalink_id_t);
1910Sstevel@tonic-gate extern void aggr_grp_free(aggr_grp_t *);
1920Sstevel@tonic-gate 
1935895Syz147064 extern int aggr_grp_info(datalink_id_t, void *, aggr_grp_info_new_grp_fn_t,
1945895Syz147064     aggr_grp_info_new_port_fn_t);
1950Sstevel@tonic-gate extern void aggr_grp_notify(aggr_grp_t *, uint32_t);
1960Sstevel@tonic-gate extern boolean_t aggr_grp_attach_port(aggr_grp_t *, aggr_port_t *);
1970Sstevel@tonic-gate extern boolean_t aggr_grp_detach_port(aggr_grp_t *, aggr_port_t *);
1982047Syz147064 extern void aggr_grp_port_mac_changed(aggr_grp_t *, aggr_port_t *,
1992047Syz147064     boolean_t *, boolean_t *);
2005895Syz147064 extern int aggr_grp_add_ports(datalink_id_t, uint_t, boolean_t,
2015895Syz147064     laioc_port_t *);
2025895Syz147064 extern int aggr_grp_rem_ports(datalink_id_t, uint_t, laioc_port_t *);
2032047Syz147064 extern boolean_t aggr_grp_update_ports_mac(aggr_grp_t *);
2045895Syz147064 extern int aggr_grp_modify(datalink_id_t, aggr_grp_t *, uint8_t, uint32_t,
2050Sstevel@tonic-gate     boolean_t, const uchar_t *, aggr_lacp_mode_t, aggr_lacp_timer_t);
2060Sstevel@tonic-gate extern void aggr_grp_multicst_port(aggr_port_t *, boolean_t);
207269Sericheng extern uint_t aggr_grp_count(void);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate extern void aggr_port_init(void);
2101804Sericheng extern void aggr_port_fini(void);
2115895Syz147064 extern int aggr_port_create(const datalink_id_t, boolean_t, aggr_port_t **);
2120Sstevel@tonic-gate extern void aggr_port_delete(aggr_port_t *);
2130Sstevel@tonic-gate extern void aggr_port_free(aggr_port_t *);
2140Sstevel@tonic-gate extern int aggr_port_start(aggr_port_t *);
2150Sstevel@tonic-gate extern void aggr_port_stop(aggr_port_t *);
2160Sstevel@tonic-gate extern int aggr_port_promisc(aggr_port_t *, boolean_t);
2170Sstevel@tonic-gate extern int aggr_port_unicst(aggr_port_t *, uint8_t *);
2180Sstevel@tonic-gate extern int aggr_port_multicst(void *, boolean_t, const uint8_t *);
2192311Sseb extern uint64_t aggr_port_stat(aggr_port_t *, uint_t);
2202163Syz147064 extern boolean_t aggr_port_notify_link(aggr_grp_t *, aggr_port_t *, boolean_t);
2212163Syz147064 extern void aggr_port_init_callbacks(aggr_port_t *);
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate extern void aggr_recv_cb(void *, mac_resource_handle_t, mblk_t *);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate extern mblk_t *aggr_m_tx(void *, mblk_t *);
2260Sstevel@tonic-gate extern void aggr_send_port_enable(aggr_port_t *);
2270Sstevel@tonic-gate extern void aggr_send_port_disable(aggr_port_t *);
2280Sstevel@tonic-gate extern void aggr_send_update_policy(aggr_grp_t *, uint32_t);
2290Sstevel@tonic-gate 
2301537Snd99603 extern void aggr_lacp_init(void);
2311537Snd99603 extern void aggr_lacp_fini(void);
2320Sstevel@tonic-gate extern void aggr_lacp_init_port(aggr_port_t *);
2330Sstevel@tonic-gate extern void aggr_lacp_init_grp(aggr_grp_t *);
2340Sstevel@tonic-gate extern void aggr_lacp_set_mode(aggr_grp_t *, aggr_lacp_mode_t,
2350Sstevel@tonic-gate     aggr_lacp_timer_t);
2360Sstevel@tonic-gate extern void aggr_lacp_update_mode(aggr_grp_t *, aggr_lacp_mode_t);
2370Sstevel@tonic-gate extern void aggr_lacp_update_timer(aggr_grp_t *, aggr_lacp_timer_t);
2380Sstevel@tonic-gate extern void aggr_lacp_rx(aggr_port_t *, mblk_t *);
2390Sstevel@tonic-gate extern void aggr_lacp_port_attached(aggr_port_t *);
2400Sstevel@tonic-gate extern void aggr_lacp_port_detached(aggr_port_t *);
2410Sstevel@tonic-gate extern void aggr_lacp_policy_changed(aggr_grp_t *);
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #endif	/* _KERNEL */
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate #ifdef	__cplusplus
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate #endif
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate #endif	/* _SYS_AGGR_IMPL_H */
250