xref: /titanic_51/usr/src/uts/sun4v/sys/vnet.h (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1*1ae08745Sheppo /*
2*1ae08745Sheppo  * CDDL HEADER START
3*1ae08745Sheppo  *
4*1ae08745Sheppo  * The contents of this file are subject to the terms of the
5*1ae08745Sheppo  * Common Development and Distribution License (the "License").
6*1ae08745Sheppo  * You may not use this file except in compliance with the License.
7*1ae08745Sheppo  *
8*1ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*1ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
10*1ae08745Sheppo  * See the License for the specific language governing permissions
11*1ae08745Sheppo  * and limitations under the License.
12*1ae08745Sheppo  *
13*1ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
14*1ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*1ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
16*1ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
17*1ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
18*1ae08745Sheppo  *
19*1ae08745Sheppo  * CDDL HEADER END
20*1ae08745Sheppo  */
21*1ae08745Sheppo 
22*1ae08745Sheppo /*
23*1ae08745Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*1ae08745Sheppo  * Use is subject to license terms.
25*1ae08745Sheppo  */
26*1ae08745Sheppo 
27*1ae08745Sheppo #ifndef _VNET_H
28*1ae08745Sheppo #define	_VNET_H
29*1ae08745Sheppo 
30*1ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*1ae08745Sheppo 
32*1ae08745Sheppo #ifdef __cplusplus
33*1ae08745Sheppo extern "C" {
34*1ae08745Sheppo #endif
35*1ae08745Sheppo 
36*1ae08745Sheppo #define	VNET_SUCCESS		(0)	/* successful return */
37*1ae08745Sheppo #define	VNET_FAILURE		(-1)	/* unsuccessful return */
38*1ae08745Sheppo 
39*1ae08745Sheppo #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
40*1ae08745Sheppo 
41*1ae08745Sheppo #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
42*1ae08745Sheppo #define	VNET_RECLAIM_LOWAT	32		/* tx reclaim low watermark */
43*1ae08745Sheppo #define	VNET_RECLAIM_HIWAT	(512 - 32)	/* tx reclaim high watermark */
44*1ae08745Sheppo #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
45*1ae08745Sheppo #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
46*1ae08745Sheppo #define	VNET_LDC_QLEN		1024		/* ldc qlen */
47*1ae08745Sheppo 
48*1ae08745Sheppo /*
49*1ae08745Sheppo  * vnet proxy transport layer information. There is one instance of this for
50*1ae08745Sheppo  * every transport being used by a vnet device and a list of these transports
51*1ae08745Sheppo  * is maintained by vnet.
52*1ae08745Sheppo  */
53*1ae08745Sheppo typedef struct vp_tl {
54*1ae08745Sheppo 	struct vp_tl		*nextp;			/* next in list */
55*1ae08745Sheppo 	mac_t			*macp;			/* transport ops */
56*1ae08745Sheppo 	char			name[LIFNAMSIZ];	/* device name */
57*1ae08745Sheppo 	major_t			major;			/* driver major # */
58*1ae08745Sheppo 	uint_t			instance;		/* dev instance */
59*1ae08745Sheppo } vp_tl_t;
60*1ae08745Sheppo 
61*1ae08745Sheppo /*
62*1ae08745Sheppo  * Forwarding database (FDB) entry, used by vnet to provide switching
63*1ae08745Sheppo  * functionality. Each fdb entry corresponds to a destination vnet device
64*1ae08745Sheppo  * within the ldoms which is directly reachable by invoking a transmit
65*1ae08745Sheppo  * function provided by a vnet proxy transport layer. Currently, the generic
66*1ae08745Sheppo  * transport layer adds/removes/modifies entries in fdb.
67*1ae08745Sheppo  */
68*1ae08745Sheppo typedef struct fdb {
69*1ae08745Sheppo 	struct fdb	*nextp;			/* next entry in the list */
70*1ae08745Sheppo 	uint8_t		macaddr[ETHERADDRL];	/* destination mac address */
71*1ae08745Sheppo 	mac_tx_t	m_tx;			/* transmit function */
72*1ae08745Sheppo 	void		*txarg;			/* arg to the transmit func */
73*1ae08745Sheppo } fdb_t;
74*1ae08745Sheppo 
75*1ae08745Sheppo /* FDB hash queue head */
76*1ae08745Sheppo typedef struct fdbf_s {
77*1ae08745Sheppo 	fdb_t		*headp;			/* head of fdb entries */
78*1ae08745Sheppo 	krwlock_t	rwlock;			/* protect the list */
79*1ae08745Sheppo } fdb_fanout_t;
80*1ae08745Sheppo 
81*1ae08745Sheppo #define	VNET_NFDB_HASH	4	/* default number of hash queues in fdb */
82*1ae08745Sheppo #define	VNET_NFDB_HASH_MAX 32	/* max number of hash queues in fdb */
83*1ae08745Sheppo 
84*1ae08745Sheppo /* Hash calculation using the mac address */
85*1ae08745Sheppo #define	MACHASH(a, n)	((*(((uchar_t *)(a)) + 0) ^		\
86*1ae08745Sheppo 			*(((uchar_t *)(a)) + 1) ^		\
87*1ae08745Sheppo 			*(((uchar_t *)(a)) + 2) ^		\
88*1ae08745Sheppo 			*(((uchar_t *)(a)) + 3) ^		\
89*1ae08745Sheppo 			*(((uchar_t *)(a)) + 4) ^		\
90*1ae08745Sheppo 			*(((uchar_t *)(a)) + 5)) % (uint32_t)n)
91*1ae08745Sheppo 
92*1ae08745Sheppo /* rwlock macros */
93*1ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
94*1ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
95*1ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
96*1ae08745Sheppo 
97*1ae08745Sheppo /*
98*1ae08745Sheppo  * vnet instance state information
99*1ae08745Sheppo  */
100*1ae08745Sheppo typedef struct vnet {
101*1ae08745Sheppo 	int			instance;	/* instance # */
102*1ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
103*1ae08745Sheppo 	struct vnet		*nextp;		/* next in list */
104*1ae08745Sheppo 	mac_t 			*macp;		/* MAC - macinfo */
105*1ae08745Sheppo 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
106*1ae08745Sheppo 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
107*1ae08745Sheppo 	vp_tl_t			*tlp;		/* list of vp_tl */
108*1ae08745Sheppo 	krwlock_t		trwlock;	/* lock for vp_tl list */
109*1ae08745Sheppo 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
110*1ae08745Sheppo 	fdb_fanout_t		*fdbhp;		/* fdb hash queues */
111*1ae08745Sheppo 	int			nfdb_hash;	/* num fdb hash queues */
112*1ae08745Sheppo } vnet_t;
113*1ae08745Sheppo 
114*1ae08745Sheppo #ifdef __cplusplus
115*1ae08745Sheppo }
116*1ae08745Sheppo #endif
117*1ae08745Sheppo 
118*1ae08745Sheppo #endif	/* _VNET_H */
119