xref: /titanic_44/usr/src/uts/sun4v/sys/vnet.h (revision 5dd2c7e9f9042148fc81d6aada5df28c2705977d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _VNET_H
28 #define	_VNET_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define	VNET_SUCCESS		(0)	/* successful return */
37 #define	VNET_FAILURE		(-1)	/* unsuccessful return */
38 
39 #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
40 
41 #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
42 #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
43 #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
44 #define	VNET_LDC_MTU		64		/* ldc mtu */
45 
46 /*
47  * vnet proxy transport layer information. There is one instance of this for
48  * every transport being used by a vnet device and a list of these transports
49  * is maintained by vnet.
50  */
51 typedef struct vp_tl {
52 	struct vp_tl		*nextp;			/* next in list */
53 	mac_register_t		*macp;			/* transport ops */
54 	char			name[LIFNAMSIZ];	/* device name */
55 	major_t			major;			/* driver major # */
56 	uint_t			instance;		/* dev instance */
57 } vp_tl_t;
58 
59 /*
60  * Forwarding database (FDB) entry, used by vnet to provide switching
61  * functionality. Each fdb entry corresponds to a destination vnet device
62  * within the ldoms which is directly reachable by invoking a transmit
63  * function provided by a vnet proxy transport layer. Currently, the generic
64  * transport layer adds/removes/modifies entries in fdb.
65  */
66 typedef struct fdb {
67 	struct fdb	*nextp;			/* next entry in the list */
68 	uint8_t		macaddr[ETHERADDRL];	/* destination mac address */
69 	mac_tx_t	m_tx;			/* transmit function */
70 	void		*txarg;			/* arg to the transmit func */
71 } fdb_t;
72 
73 /* FDB hash queue head */
74 typedef struct fdbf_s {
75 	fdb_t		*headp;			/* head of fdb entries */
76 	krwlock_t	rwlock;			/* protect the list */
77 } fdb_fanout_t;
78 
79 #define	VNET_NFDB_HASH		64	/* default no. of hash queues in fdb */
80 #define	VNET_NFDB_HASH_MAX	128	/* max number of hash queues in fdb */
81 
82 /* Hash calculation using the mac address */
83 #define	MACHASH(a, n)	((*(((uchar_t *)(a)) + 0) ^		\
84 			*(((uchar_t *)(a)) + 1) ^		\
85 			*(((uchar_t *)(a)) + 2) ^		\
86 			*(((uchar_t *)(a)) + 3) ^		\
87 			*(((uchar_t *)(a)) + 4) ^		\
88 			*(((uchar_t *)(a)) + 5)) % (uint32_t)n)
89 
90 /* rwlock macros */
91 #define	READ_ENTER(x)	rw_enter(x, RW_READER)
92 #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
93 #define	RW_EXIT(x)	rw_exit(x)
94 
95 /*
96  * vnet instance state information
97  */
98 typedef struct vnet {
99 	int			instance;	/* instance # */
100 	dev_info_t		*dip;		/* dev_info */
101 	struct vnet		*nextp;		/* next in list */
102 	mac_handle_t 		mh;		/* handle to GLDv3 mac module */
103 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
104 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
105 	vp_tl_t			*tlp;		/* list of vp_tl */
106 	krwlock_t		trwlock;	/* lock for vp_tl list */
107 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
108 	fdb_fanout_t		*fdbhp;		/* fdb hash queues */
109 	int			nfdb_hash;	/* num fdb hash queues */
110 } vnet_t;
111 
112 
113 
114 #ifdef DEBUG
115 /*
116  * debug levels:
117  * DBG_LEVEL1:	Function entry/exit tracing
118  * DBG_LEVEL2:	Info messages
119  * DBG_LEVEL3:	Warning messages
120  * DBG_LEVEL4:	Error messages
121  */
122 
123 enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
124 	    DBG_ERR = 0x08 };
125 
126 #define	DBG1(...)	do {						\
127 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
128 				debug_printf(__func__, __VA_ARGS__);	\
129 			    }						\
130 			_NOTE(CONSTCOND) } while (0)
131 
132 #define	DBG2(...)	do {						\
133 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
134 				debug_printf(__func__, __VA_ARGS__);	\
135 			    }						\
136 			_NOTE(CONSTCOND) } while (0)
137 
138 #define	DWARN(...)	do {						\
139 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
140 				debug_printf(__func__, __VA_ARGS__);	\
141 			    }						\
142 			_NOTE(CONSTCOND) } while (0)
143 
144 #define	DERR(...)	do {						\
145 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
146 				debug_printf(__func__, __VA_ARGS__);	\
147 			    }						\
148 			_NOTE(CONSTCOND) } while (0)
149 
150 #else
151 
152 #define	DBG1(...)	if (0)	do { } while (0)
153 #define	DBG2(...)	if (0)	do { } while (0)
154 #define	DWARN(...)	if (0)	do { } while (0)
155 #define	DERR(...)	if (0)	do { } while (0)
156 
157 #endif
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif	/* _VNET_H */
164