xref: /titanic_54/usr/src/uts/sun4v/sys/vnet.h (revision 844e62a3ec8c8ff5175bb35d1c38446e060730f6)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
23*844e62a3Sraghuram  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo #ifndef _VNET_H
281ae08745Sheppo #define	_VNET_H
291ae08745Sheppo 
301ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311ae08745Sheppo 
321ae08745Sheppo #ifdef __cplusplus
331ae08745Sheppo extern "C" {
341ae08745Sheppo #endif
351ae08745Sheppo 
361ae08745Sheppo #define	VNET_SUCCESS		(0)	/* successful return */
371ae08745Sheppo #define	VNET_FAILURE		(-1)	/* unsuccessful return */
381ae08745Sheppo 
391ae08745Sheppo #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
401ae08745Sheppo 
411ae08745Sheppo #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
421ae08745Sheppo #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
431ae08745Sheppo #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
44e1ebb9ecSlm66018 #define	VNET_LDC_MTU		64		/* ldc mtu */
451ae08745Sheppo 
461ae08745Sheppo /*
471ae08745Sheppo  * vnet proxy transport layer information. There is one instance of this for
481ae08745Sheppo  * every transport being used by a vnet device and a list of these transports
491ae08745Sheppo  * is maintained by vnet.
501ae08745Sheppo  */
511ae08745Sheppo typedef struct vp_tl {
521ae08745Sheppo 	struct vp_tl		*nextp;			/* next in list */
53ba2e4443Sseb 	mac_register_t		*macp;			/* transport ops */
541ae08745Sheppo 	char			name[LIFNAMSIZ];	/* device name */
551ae08745Sheppo 	major_t			major;			/* driver major # */
561ae08745Sheppo 	uint_t			instance;		/* dev instance */
571ae08745Sheppo } vp_tl_t;
581ae08745Sheppo 
591ae08745Sheppo /*
601ae08745Sheppo  * Forwarding database (FDB) entry, used by vnet to provide switching
611ae08745Sheppo  * functionality. Each fdb entry corresponds to a destination vnet device
621ae08745Sheppo  * within the ldoms which is directly reachable by invoking a transmit
631ae08745Sheppo  * function provided by a vnet proxy transport layer. Currently, the generic
641ae08745Sheppo  * transport layer adds/removes/modifies entries in fdb.
651ae08745Sheppo  */
661ae08745Sheppo typedef struct fdb {
671ae08745Sheppo 	struct fdb	*nextp;			/* next entry in the list */
681ae08745Sheppo 	uint8_t		macaddr[ETHERADDRL];	/* destination mac address */
691ae08745Sheppo 	mac_tx_t	m_tx;			/* transmit function */
701ae08745Sheppo 	void		*txarg;			/* arg to the transmit func */
711ae08745Sheppo } fdb_t;
721ae08745Sheppo 
731ae08745Sheppo /* FDB hash queue head */
741ae08745Sheppo typedef struct fdbf_s {
751ae08745Sheppo 	fdb_t		*headp;			/* head of fdb entries */
761ae08745Sheppo 	krwlock_t	rwlock;			/* protect the list */
771ae08745Sheppo } fdb_fanout_t;
781ae08745Sheppo 
79*844e62a3Sraghuram #define	VNET_NFDB_HASH		64	/* default no. of hash queues in fdb */
80*844e62a3Sraghuram #define	VNET_NFDB_HASH_MAX	128	/* max number of hash queues in fdb */
811ae08745Sheppo 
821ae08745Sheppo /* Hash calculation using the mac address */
831ae08745Sheppo #define	MACHASH(a, n)	((*(((uchar_t *)(a)) + 0) ^		\
841ae08745Sheppo 			*(((uchar_t *)(a)) + 1) ^		\
851ae08745Sheppo 			*(((uchar_t *)(a)) + 2) ^		\
861ae08745Sheppo 			*(((uchar_t *)(a)) + 3) ^		\
871ae08745Sheppo 			*(((uchar_t *)(a)) + 4) ^		\
881ae08745Sheppo 			*(((uchar_t *)(a)) + 5)) % (uint32_t)n)
891ae08745Sheppo 
901ae08745Sheppo /* rwlock macros */
911ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
921ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
931ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
941ae08745Sheppo 
951ae08745Sheppo /*
961ae08745Sheppo  * vnet instance state information
971ae08745Sheppo  */
981ae08745Sheppo typedef struct vnet {
991ae08745Sheppo 	int			instance;	/* instance # */
1001ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
1011ae08745Sheppo 	struct vnet		*nextp;		/* next in list */
102ba2e4443Sseb 	mac_handle_t 		mh;		/* handle to GLDv3 mac module */
1031ae08745Sheppo 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
1041ae08745Sheppo 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
1051ae08745Sheppo 	vp_tl_t			*tlp;		/* list of vp_tl */
1061ae08745Sheppo 	krwlock_t		trwlock;	/* lock for vp_tl list */
1071ae08745Sheppo 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
1081ae08745Sheppo 	fdb_fanout_t		*fdbhp;		/* fdb hash queues */
1091ae08745Sheppo 	int			nfdb_hash;	/* num fdb hash queues */
1101ae08745Sheppo } vnet_t;
1111ae08745Sheppo 
112*844e62a3Sraghuram 
113*844e62a3Sraghuram 
114*844e62a3Sraghuram #ifdef DEBUG
115*844e62a3Sraghuram /*
116*844e62a3Sraghuram  * debug levels:
117*844e62a3Sraghuram  * DBG_LEVEL1:	Function entry/exit tracing
118*844e62a3Sraghuram  * DBG_LEVEL2:	Info messages
119*844e62a3Sraghuram  * DBG_LEVEL3:	Warning messages
120*844e62a3Sraghuram  * DBG_LEVEL4:	Error messages
121*844e62a3Sraghuram  */
122*844e62a3Sraghuram 
123*844e62a3Sraghuram enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
124*844e62a3Sraghuram 	    DBG_ERR = 0x08 };
125*844e62a3Sraghuram 
126*844e62a3Sraghuram #define	DBG1(...)	do {						\
127*844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
128*844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
129*844e62a3Sraghuram 			    }						\
130*844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
131*844e62a3Sraghuram 
132*844e62a3Sraghuram #define	DBG2(...)	do {						\
133*844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
134*844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
135*844e62a3Sraghuram 			    }						\
136*844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
137*844e62a3Sraghuram 
138*844e62a3Sraghuram #define	DWARN(...)	do {						\
139*844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
140*844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
141*844e62a3Sraghuram 			    }						\
142*844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
143*844e62a3Sraghuram 
144*844e62a3Sraghuram #define	DERR(...)	do {						\
145*844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
146*844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
147*844e62a3Sraghuram 			    }						\
148*844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
149*844e62a3Sraghuram 
150*844e62a3Sraghuram #else
151*844e62a3Sraghuram 
152*844e62a3Sraghuram #define	DBG1(...)	if (0)	do { } while (0)
153*844e62a3Sraghuram #define	DBG2(...)	if (0)	do { } while (0)
154*844e62a3Sraghuram #define	DWARN(...)	if (0)	do { } while (0)
155*844e62a3Sraghuram #define	DERR(...)	if (0)	do { } while (0)
156*844e62a3Sraghuram 
157*844e62a3Sraghuram #endif
158*844e62a3Sraghuram 
1591ae08745Sheppo #ifdef __cplusplus
1601ae08745Sheppo }
1611ae08745Sheppo #endif
1621ae08745Sheppo 
1631ae08745Sheppo #endif	/* _VNET_H */
164