xref: /titanic_54/usr/src/uts/sun4v/sys/vnet.h (revision ba2e4443695ee6a6f420a35cd4fc3d3346d22932)
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 /*
231ae08745Sheppo  * Copyright 2006 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_RECLAIM_LOWAT	32		/* tx reclaim low watermark */
431ae08745Sheppo #define	VNET_RECLAIM_HIWAT	(512 - 32)	/* tx reclaim high watermark */
441ae08745Sheppo #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
451ae08745Sheppo #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
461ae08745Sheppo #define	VNET_LDC_QLEN		1024		/* ldc qlen */
471ae08745Sheppo 
481ae08745Sheppo /*
491ae08745Sheppo  * vnet proxy transport layer information. There is one instance of this for
501ae08745Sheppo  * every transport being used by a vnet device and a list of these transports
511ae08745Sheppo  * is maintained by vnet.
521ae08745Sheppo  */
531ae08745Sheppo typedef struct vp_tl {
541ae08745Sheppo 	struct vp_tl		*nextp;			/* next in list */
55*ba2e4443Sseb 	mac_register_t		*macp;			/* transport ops */
561ae08745Sheppo 	char			name[LIFNAMSIZ];	/* device name */
571ae08745Sheppo 	major_t			major;			/* driver major # */
581ae08745Sheppo 	uint_t			instance;		/* dev instance */
591ae08745Sheppo } vp_tl_t;
601ae08745Sheppo 
611ae08745Sheppo /*
621ae08745Sheppo  * Forwarding database (FDB) entry, used by vnet to provide switching
631ae08745Sheppo  * functionality. Each fdb entry corresponds to a destination vnet device
641ae08745Sheppo  * within the ldoms which is directly reachable by invoking a transmit
651ae08745Sheppo  * function provided by a vnet proxy transport layer. Currently, the generic
661ae08745Sheppo  * transport layer adds/removes/modifies entries in fdb.
671ae08745Sheppo  */
681ae08745Sheppo typedef struct fdb {
691ae08745Sheppo 	struct fdb	*nextp;			/* next entry in the list */
701ae08745Sheppo 	uint8_t		macaddr[ETHERADDRL];	/* destination mac address */
711ae08745Sheppo 	mac_tx_t	m_tx;			/* transmit function */
721ae08745Sheppo 	void		*txarg;			/* arg to the transmit func */
731ae08745Sheppo } fdb_t;
741ae08745Sheppo 
751ae08745Sheppo /* FDB hash queue head */
761ae08745Sheppo typedef struct fdbf_s {
771ae08745Sheppo 	fdb_t		*headp;			/* head of fdb entries */
781ae08745Sheppo 	krwlock_t	rwlock;			/* protect the list */
791ae08745Sheppo } fdb_fanout_t;
801ae08745Sheppo 
811ae08745Sheppo #define	VNET_NFDB_HASH	4	/* default number of hash queues in fdb */
821ae08745Sheppo #define	VNET_NFDB_HASH_MAX 32	/* max number of hash queues in fdb */
831ae08745Sheppo 
841ae08745Sheppo /* Hash calculation using the mac address */
851ae08745Sheppo #define	MACHASH(a, n)	((*(((uchar_t *)(a)) + 0) ^		\
861ae08745Sheppo 			*(((uchar_t *)(a)) + 1) ^		\
871ae08745Sheppo 			*(((uchar_t *)(a)) + 2) ^		\
881ae08745Sheppo 			*(((uchar_t *)(a)) + 3) ^		\
891ae08745Sheppo 			*(((uchar_t *)(a)) + 4) ^		\
901ae08745Sheppo 			*(((uchar_t *)(a)) + 5)) % (uint32_t)n)
911ae08745Sheppo 
921ae08745Sheppo /* rwlock macros */
931ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
941ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
951ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
961ae08745Sheppo 
971ae08745Sheppo /*
981ae08745Sheppo  * vnet instance state information
991ae08745Sheppo  */
1001ae08745Sheppo typedef struct vnet {
1011ae08745Sheppo 	int			instance;	/* instance # */
1021ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
1031ae08745Sheppo 	struct vnet		*nextp;		/* next in list */
104*ba2e4443Sseb 	mac_handle_t 		mh;		/* handle to GLDv3 mac module */
1051ae08745Sheppo 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
1061ae08745Sheppo 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
1071ae08745Sheppo 	vp_tl_t			*tlp;		/* list of vp_tl */
1081ae08745Sheppo 	krwlock_t		trwlock;	/* lock for vp_tl list */
1091ae08745Sheppo 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
1101ae08745Sheppo 	fdb_fanout_t		*fdbhp;		/* fdb hash queues */
1111ae08745Sheppo 	int			nfdb_hash;	/* num fdb hash queues */
1121ae08745Sheppo } vnet_t;
1131ae08745Sheppo 
1141ae08745Sheppo #ifdef __cplusplus
1151ae08745Sheppo }
1161ae08745Sheppo #endif
1171ae08745Sheppo 
1181ae08745Sheppo #endif	/* _VNET_H */
119